Mar*_*oma 6 python numpy tensorflow
我希望我训练的CNN可重现的结果.因此我在我的脚本中设置了种子:
import tensorflow as tf
tf.set_random_seed(0) # make sure results are reproducible
import numpy as np
np.random.seed(0) # make sure results are reproducible
Run Code Online (Sandbox Code Playgroud)
文件set_random_seed和np.random.seed不报告种子的任何特殊行为0.
当我在几分钟内在同一台机器上运行相同的脚本两次并且没有进行更新时,我希望得到相同的结果.然而,这种情况并非如此:
运行1:
0;0.001733;0.001313
500;0.390164;0.388188
Run Code Online (Sandbox Code Playgroud)
运行2:
0;0.006986;0.007000
500;0.375288;0.374250
Run Code Online (Sandbox Code Playgroud)
如何使网络产生可重复的结果?
$ python -c "import tensorflow;print(tensorflow.__version__)"
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
1.0.0
$ python -c "import numpy;print(numpy.__version__)"
1.12.0
Run Code Online (Sandbox Code Playgroud)
尽管我没有解决问题,但可能有以下原因导致结果并不总是相同(从最可能/最容易修复到最不可能/最难修复的顺序排序)。问题发生后,我也尝试给出解决方案。
2017-12-31-23-54-experiment-result.log为您运行的每个实验创建一个。不是手动进行的,而是由实验创建的。是的,名称中的时间戳记便于再次查找。对于每个单个实验,所有以下内容均应记录到该文件中。无论如何,多次运行“相同”的东西可能有助于使人对不同的事物有一种直觉。
如果您写论文,我认为以下将是重现性的最佳实践:
requirements.txt则必须提供确切的软件版本,而不是类似tensorflow>=1.0.0但tensorflow==1.2.3要记录版本,您可能需要使用以下内容:
#!/usr/bin/env python
# core modules
import subprocess
def get_logstring():
"""
Get important environment information that might influence experiments.
Returns
-------
logstring : str
"""
logstring = []
with open('/proc/cpuinfo') as f:
cpuinfo = f.readlines()
for line in cpuinfo:
if "model name" in line:
logstring.append("CPU: {}".format(line.strip()))
break
with open('/proc/driver/nvidia/version') as f:
version = f.read().strip()
logstring.append("GPU driver: {}".format(version))
logstring.append("VGA: {}".format(find_vga()))
return "\n".join(logstring)
def find_vga():
vga = subprocess.check_output("lspci | grep -i 'vga\|3d\|2d'",
shell=True,
executable='/bin/bash')
return vga
print(get_logstring())
Run Code Online (Sandbox Code Playgroud)
这给像
CPU: model name : Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
GPU driver: NVRM version: NVIDIA UNIX x86_64 Kernel Module 384.90 Tue Sep 19 19:17:35 PDT 2017
GCC version: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)
VGA: 00:02.0 VGA compatible controller: Intel Corporation Skylake Integrated Graphics (rev 06)
02:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 940MX] (rev a2)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
875 次 |
| 最近记录: |