我正在开发一个相当大的模型,我需要使用tf.RunOptions或其他调试器来精简我的代码,因为我遇到了非常小的批量大小的 OOM 错误。但是我在使用tf.RunOptions.
我不认为这是模型问题,因为以下代码也会出现问题(而没有 的相同代码runopt正在工作):
import tensorflow as tf
import tensorflow.keras.models as mm
import tensorflow.keras.layers as ll
import numpy as np
model = mm.Sequential([
ll.Dense(27,input_shape=(1,)),
ll.Activation('relu'),
ll.Dense(27),
ll.Activation('softmax')
])
runopt = tf.RunOptions(report_tensor_allocations_upon_oom = True)
model.compile(optimizer='sgd',
loss='mean_squared_error',
metrics=['accuracy'],
options=runopt)
a = np.zeros(27)*10
model.fit(a,a,epochs=10)
在 Linux 18.04 上遇到同样的错误(tensorflow-gpu 安装了 pip, tf version 1.13.1, python version 3.6.7, CUDA 9.1.85, GeForce GTX 980 4GB)and on macOS 10.12.6(tensorflow-cpu installed with pip, tf version 1.13.1, python version 3.7.2)