Reputation: 1306
I am pretty new to TensorFlow and keras and I have searched a lot but I could not find answer. I want to train a neural network. In import statements, when I use keras everything works. However, when I change them to tensorflow.keras, then I get an error. For some reasons, I have to upgrade my codes to use tf.keras instead of keras
Here is how I give numpy array as input to train:
model.fit(X2_upsampled_train, Y2_upsampled_train, batch_size=batch_size, epochs=nb_epoch,verbose=0, validation_data=(X2[test], Y2_test),callbacks=[monitor])
Here is the error which I get with tf.keras
RuntimeError Traceback (most recent call last)
<ipython-input-11-2ea1c5ab4362> in <module>()
145 monitor = EarlyStopping(monitor='val_loss', min_delta=1e-5, patience=5, verbose=1, mode='auto', restore_best_weights=True)
146
--> 147 model.fit(X2_upsampled_train, Y2_upsampled_train, batch_size=batch_size, epochs=nb_epoch,verbose=0, validation_data=(X2[test], Y2_test),callbacks=[monitor])
149
16 frames
/tensorflow-1.15.0/python3.6/tensorflow_core/python/ops/resource_variable_ops.py in __imul__(self, unused_other)
1227
1228 def __imul__(self, unused_other):
-> 1229 raise RuntimeError("Variable *= value not supported. Use "
1230 "`var.assign(var * value)` to modify the variable or "
1231 "`var = var * value` to get a new Tensor object.")
RuntimeError: Variable *= value not supported. Use `var.assign(var * value)` to modify the variable or `var = var * value` to get a new Tensor object.
Anyone knows what is going on in tf.keras vs keras? How can I change my codes so that I can use tf.keras?
Upvotes: 0
Views: 713
Reputation: 357
Ensure that you are using tf.keras and not keras.
In the error-message, it looks like you are using tensorflow-1.15.0. Use tensorflow 2+ and it should work.
Upvotes: 1