Any idea why the following issue occured?
https://github.com/keras-team/keras/issues/17255
This happen when I try to recompile the model using callback. It should work, right?
Any idea why the following issue occured?
https://github.com/keras-team/keras/issues/17255
This happen when I try to recompile the model using callback. It should work, right?
Is it not valid approach (if I wanna do so)?
class CustomLearningRateScheduler(keras.callbacks.Callback):
def on_epoch_begin(self, epoch, logs=None):
self.model.compile(
optimizer=keras.optimizers.RMSprop(learning_rate=0.1),
loss="mean_squared_error",
metrics=["mean_absolute_error"],
)
Are you trying to change the learning rate of the optimizer?
maybe this could help you: Optimizers
Sorry for the confusion. I didn’t worry about optimizer. The above code was taken from official keras io page.
I want to recompile the keras model using callback. But I’m facing the above mentioned TypeErrror. Here is the simplified code. Please suggest.
import tensorflow as tf
from tensorflow import keras
# Define the Keras model to add callbacks to
def get_model():
model = keras.Sequential()
model.add(keras.layers.Dense(1, input_dim=784))
model.compile(
optimizer=keras.optimizers.RMSprop(learning_rate=0.1),
loss="mean_squared_error",
metrics=["mean_absolute_error"],
)
return model
# Load example MNIST data and pre-process it
(x_train, y_train), (_, _) = tf.keras.datasets.mnist.load_data()
x_train = x_train.reshape(-1, 784).astype("float32") / 255.0
class RecompileInCallback(keras.callbacks.Callback):
def on_epoch_begin(self, epoch, logs=None):
self.model.compile(
optimizer=keras.optimizers.RMSprop(learning_rate=0.1),
loss="mean_squared_error",
metrics=["mean_absolute_error"],
)
model = get_model()
model.fit(
x_train,
y_train,
batch_size=64,
epochs=2,
callbacks=[
RecompileInCallback(),
],
)
1182 _r=1):
1183 callbacks.on_train_batch_begin(step)
-> 1184 tmp_logs = self.train_function(iterator)
1185 if data_handler.should_sync:
1186 context.async_wait()
TypeError: 'NoneType' object is not callable