Closed momir81 closed 8 years ago
Hello,
I am trying to run code below using tensorflow backend but I get error dtype argument unexpected:
# Create first MLP in Keras
from keras.models import Sequential
from keras.layers import Dense
import numpy
# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)
# load pima indians dataset
dataset = numpy.loadtxt("pima-indians-diabetes.csv", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:,0:8]
Y = dataset[:,8]
# create model
model = Sequential()
model.add(Dense(12, input_dim=8, init='uniform', activation='relu'))
model.add(Dense(8, init='uniform', activation='relu'))
model.add(Dense(1, init='uniform', activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Fit the model
model.fit(X, Y, nb_epoch=150, batch_size=10)
# evaluate the model
scores = model.evaluate(X, Y)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
Log error is:
Traceback (most recent call last):
File "/Users/quuppa/Documents/deep_learning_with_python/deep_learning_with_python_code/chapt er_07/first_mlp.py", line 15, in <module>
model.add(Dense(12, input_dim=8, init='uniform', activation='relu'))
File "/usr/local/lib/python2.7/site-packages/keras/models.py", line 114, in add
layer.create_input_layer(batch_input_shape, input_dtype)
File "/usr/local/lib/python2.7/site-packages/keras/engine/topology.py", line 341, in create_input_layer
self(x)
File "/usr/local/lib/python2.7/site-packages/keras/engine/topology.py", line 458, in __call__
self.build(input_shapes[0])
File "/usr/local/lib/python2.7/site-packages/keras/layers/core.py", line 604, in build
name='{}_W'.format(self.name))
File "/usr/local/lib/python2.7/site-packages/keras/initializations.py", line 32, in uniform
return K.random_uniform_variable(shape, -scale, scale, name=name)
File "/usr/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 244, in random_uniform_variable
return variable(value, dtype=dtype, name=name)
File "/usr/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 123, in variable
v = tf.Variable(value, dtype=_convert_string_dtype(dtype), name=name)
TypeError: __init__() got an unexpected keyword argument 'dtype'
I have updated from git keras.
For keras.json configuration I use:
{
"image_dim_ordering": "tf",
"epsilon": 1e-07,
"floatx": "float32",
"backend": "tensorflow"
}
Could you please send some ideas how to solve this?
Thanks!
I believe your Tensorflow is out of date. I had faced a similar issue with Tensorflow v0.7. Please try with the v0.9. I believe that has updated the function signature to include dtype.
Thanks a lot ameya005, now it works.
Please make sure that the boxes below are checked before you submit your issue. Thank you!