【问题标题】:TFE_Py_RecordGradient error using Keras with Tensorflow back end使用带有 Tensorflow 后端的 Keras 的 TFE_Py_RecordGradient 错误
【发布时间】:2018-08-19 03:50:24
【问题描述】:

我正在尝试在 Nvidia GPU 上使用 Keras 和 Tensorflow 训练卷积神经网络。我尝试过使用代码和数据来实现非常简单的无锁模型模型。我尝试定义的每个网络都会给我同样的错误:

文件“”,第 2 行,在 model.add(Dense(12, input_dim=5, kernel_initializer='normal', activation='relu'))>

文件“build/bdist.linux-x86_64/egg/keras/models.py”,第 463 行,添加 name=layer.name + '_input')

文件“build/bdist.linux-x86_64/egg/keras/engine/topology.py”,第 1457 行,输入 input_tensor=张量)

文件“build/bdist.linux-x86_64/egg/keras/legacy/interfaces.py”,第 91 行,在包装器中 返回函数(*args, **kwargs)

文件“build/bdist.linux-x86_64/egg/keras/engine/topology.py”,第 1366 行,在 init 中 name=self.name)

文件“build/bdist.linux-x86_64/egg/keras/backend/tensorflow_backend.py”,第 507 行,占位符 x = tf.placeholder(dtype, shape=shape, name=name)

文件“/home/smalldave/.local/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py”,第 1734 行,占位符 return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)

文件“/home/smalldave/.local/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py”,第 4929 行,在占位符中 “占位符”、_inputs_flat、_attrs、_result、名称)

文件“/home/smalldave/.local/lib/python2.7/site-packages/tensorflow/python/eager/backprop.py”,第 162 行,在 _record_gradient return pywrap_tensorflow.TFE_Py_RecordGradient(op_name, inputs, attrs,

AttributeError: 'NoneType' 对象没有属性 'TFE_Py_RecordGradient'

有人知道这个错误的来源吗?

这是我尝试定义的网络示例:

model = Sequential()
model.add(Dense(12, input_dim=5, kernel_initializer='normal', activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='linear'))
model.summary()

非常感谢。

【问题讨论】:

    标签: python tensorflow keras gpu


    【解决方案1】:

    从堆栈跟踪中,我推测您使用的是 keras,而不是 tf.keras,它与 TensorFlow 安装一起打包。

    tf.keras 实现了 keras.io 中定义的 API 规范,但添加了额外的 TensorFlow 特定功能,例如支持急切执行。

    所以,我怀疑您需要做的只是改变以下内容:

    from keras.models import Sequential
    from keras.layers import Dense
    

    到:

    from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import Dense
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-11-17
      • 2018-02-15
      • 1970-01-01
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      • 2020-05-07
      • 2016-12-19
      • 2016-08-01
      相关资源
      最近更新 更多