Keras: Dropout error with Functional API ((Cast uint8 to bool is not supported)

Created on 9 May 2016  路  3Comments  路  Source: keras-team/keras

I can't implement Dropout with the Funcional API on Keras (1.0.2) with Tensorflow 0.8 backend.
This minimal code works without x = Dropout(.3)(x)

inputs = Input(shape=(2,))
x = Dense(64, activation='relu')(inputs)
x = Dropout(.3)(x)
x = Dense(64, activation='relu')(x)
predictions = Dense(2, activation='softmax')(x)
model = Model(input=inputs, output=predictions)
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(data, labels,nb_epoch=10)

But with x = Dropout(.3)(x) it gives following error:

tensorflow.python.framework.errors.UnimplementedError:

Cast uint8 to bool is not supported [[Node: Cast = Cast[DstT=DT_BOOL, SrcT=DT_UINT8, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_keras_learning_phase_0)]]

What is the correct way to add dropout in the functional API?

Most helpful comment

My bad.... I have 2 versions of TensorFlow and was using the wrong version (0.5) !
Now it works.
Thanks for your help @joelthchao !

All 3 comments

With same version of Keras and TensorFlow, these code is able to run for me.

data = np.random.rand(100, 2)
labels = np.random.rand(100, 2)

inputs = Input(shape=(2,))
x = Dense(64, activation='relu')(inputs)
x = Dropout(.3)(x)
x = Dense(64, activation='relu')(x)
predictions = Dense(2, activation='softmax')(x)
model = Model(input=inputs, output=predictions)
model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(data, labels, nb_epoch=10)

Can you provide more error message?

My bad.... I have 2 versions of TensorFlow and was using the wrong version (0.5) !
Now it works.
Thanks for your help @joelthchao !

@MarkVdBergh please close this issue if it is solved. Thanks!

Was this page helpful?
0 / 5 - 0 ratings