0
votes

I am trying to train a convolutional neural network using Keras and Tensorflow on a Nvidia GPU. I have tried using code and data that implement very simple models models with no lock. Every network I try to define gives me the same error:

File "", line 2, in model.add(Dense(12, input_dim=5, kernel_initializer='normal', activation='relu'))>

File "build/bdist.linux-x86_64/egg/keras/models.py", line 463, in add name=layer.name + '_input')

File "build/bdist.linux-x86_64/egg/keras/engine/topology.py", line 1457, in Input input_tensor=tensor)

File "build/bdist.linux-x86_64/egg/keras/legacy/interfaces.py", line 91, in wrapper return func(*args, **kwargs)

File "build/bdist.linux-x86_64/egg/keras/engine/topology.py", line 1366, in init name=self.name)

File "build/bdist.linux-x86_64/egg/keras/backend/tensorflow_backend.py", line 507, in placeholder x = tf.placeholder(dtype, shape=shape, name=name)

File "/home/smalldave/.local/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1734, in placeholder return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)

File "/home/smalldave/.local/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 4929, in placeholder "Placeholder", _inputs_flat, _attrs, _result, name)

File "/home/smalldave/.local/lib/python2.7/site-packages/tensorflow/python/eager/backprop.py", line 162, in _record_gradient return pywrap_tensorflow.TFE_Py_RecordGradient(op_name, inputs, attrs,

AttributeError: 'NoneType' object has no attribute 'TFE_Py_RecordGradient'

Does anyone know the source of this error?

Here is an example of a network I tried to define:

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()

Thank you so much.

1

1 Answers

0
votes

From the stacktrace, I gather you're using keras and not tf.keras, which is packaged with the TensorFlow installation.

tf.keras implements the API spec defined in keras.io but adds additional TensorFlow-specific functionality, such as support for eager execution.

So, I suspect all you need to do is change from something like:

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

to:

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

Hope that helps.