如何在中调试Tensorflow分段错误模型.拟合()?

2024-04-27 19:46:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用带有geforce2080的tensorflow gpu运行Keras MINST example。我的环境是Linux系统上的Anaconda。在

我从命令行python会话运行未修改的示例。我得到以下输出:

Using TensorFlow backend.
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce RTX 2080, pci bus id: 0000:01:00.0, compute capability: 7.5
x_train shape: (60000, 28, 28, 1)
60000 train samples
10000 test samples
Train on 60000 samples, validate on 10000 samples
Epoch 1/12
conv2d_1/random_uniform/RandomUniform: (RandomUniform): 
/job:localhost/replica:0/task:0/device:GPU:0
conv2d_1/random_uniform/sub: (Sub): 
/job:localhost/replica:0/task:0/device:GPU:0
conv2d_1/random_uniform/mul: (Mul): 
/job:localhost/replica:0/task:0/device:GPU:0
conv2d_1/random_uniform: (Add): 
/job:localhost/replica:0/task:0/device:GPU:0
[...]

我收到的最后几行是:

^{pr2}$

通过阅读,我认为这可能是内存问题,并添加了以下行以防止GPU内存不足:

config = tf.ConfigProto(log_device_placement=True)
config.gpu_options.per_process_gpu_memory_fraction=0.3
K.tensorflow_backend.set_session(tf.Session(config=config))

使用nvidia-smi工具检查GPU是否实际使用(watch -n1 nvidia-smi),我可以从以下输出中确认(在本次运行中,per_process_gpu_memory_fraction被设置为1):

enter image description here

我怀疑CUDA、Keras和Tensorflow之间的某个版本不兼容是问题所在,但我不知道如何调试。在

有什么样的调试措施可以弄清这一点?还有什么问题可能是造成这一故障的原因?在

编辑:我做了进一步的实验,用下面的代码替换模型效果很好:

model = keras.Sequential([
    keras.layers.Flatten(input_shape=input_shape),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(10, activation=tf.nn.softmax)
])

不过,一旦我引入了这样的卷积层

model = keras.Sequential([
    keras.layers.Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape),
#    keras.layers.Flatten(input_shape=input_shape),
    keras.layers.Flatten(),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(10, activation=tf.nn.softmax)

]))

然后我又得到了前面提到的segfault。在

所有的包都是通过水蟒安装的。我已经安装了

  • 条件4.5.11
  • python 3.6.6
  • keras gpu 2.2.4
  • tensorflow 1.12.0版
  • tensorflow gpu 1.12.0
  • 铜管7.2.1
  • cudatoolkit 9.2版

编辑:我在一个非水蟒的环境中尝试了同样的代码,它工作得非常完美。我更喜欢使用Python虽然,以避免系统更新破坏东西。在


Tags: localhosttaskinputgpudevicelayerstftensorflow
3条回答

我在一个与Francois非常相似的系统上遇到了完全相同的问题,但是我使用了一个RTX2070,当使用GPU上执行的conv2d函数时,我可以可靠地重现分段错误。我的设置:

  • Ubuntu:18.04
  • GPU:RTX 2070
  • 库达:10
  • 卡德恩:7
  • 使用python 3.6的conda

我最终通过将tensorflow从源构建到一个新的conda环境中来解决这个问题。有关精彩的指南,请参见以下链接: https://gist.github.com/Brainiarc7/6d6c3f23ea057775b72c52817759b25c

这基本上与源代码指南中的任何其他构建tensorflow一样,包括以下步骤:

  1. 集市
  2. 从git克隆tensorflow并运行./configure
  3. 运行适当的bazel build命令(有关详细信息,请参阅链接)

在构建过程中出现了一些小问题,其中一个问题通过手动安装3个软件包解决,使用:

pip install keras_applications==1.0.4  no-deps
pip install keras_preprocessing==1.0.2  no-deps
pip install h5py==2.8.0

我用这个答案发现: Error Compiling Tensorflow From Source - No module named 'keras_applications'

conv2d现在在使用gpu时就像一个符咒!在

但是,由于所有这些花费了相当长的时间(从源代码构建需要一个多小时,不包括在互联网上搜索解决方案),我建议在系统正常工作后备份它,例如使用timeshift或任何其他您喜欢的程序。在

我有同样的Conv2D问题:

  • Ubuntu 18.04版
  • 显卡:GeForce RTX 2080
  • 库达:库达10.0.130欧410
  • CUDNN:CUDNN-10.0-linux-x64-v7.4.2
  • 使用Python 3.6的conda

最好的建议来自这个链接:https://github.com/tensorflow/tensorflow/issues/24383

因此,一个修复程序应该带有Tensorflow 1.13。 同时,使用Tensorflow 1.13 nightly build(2018年12月26日)+使用tensorflow.keras公司而不是keras解决了这个问题。在

从源代码构建tensorflow(r1.13)。Conv2D分段错误已修复。在

跟随Build from Source

我的GPU:RTX 2070 Ubuntu 16.04 Python 3.5.2版 Nvidia驱动程序410.78 CUDA-10.0.130 cuDNN-10.0-7.4.2.24 张力索-5.0.0 计算能力:7.5

内部版本:tensorflow-1.13.0rc0-cp35-cp35m-linux_x86_64

https://github.com/tensorflow/tensorflow/issues/22706下载预构建

相关问题 更多 >