Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'CyclicLR' object has no attribute 'on_train_batch_begin' #17

Open
Serge3006 opened this issue May 31, 2019 · 1 comment

Comments

@Serge3006
Copy link

Serge3006 commented May 31, 2019

Hi, I've tried to use your class within my training code, but I got the following error: AttributeError: 'CyclicLR' object has no attribute 'on_train_batch_begin'.

My code is the following:

from tensorflow.keras.applications.resnet50 import ResNet50

base_model = ResNet50(weights='imagenet', include_top=False)
base_model.trainable = False

model = tf.keras.Sequential([
base_model,
tf.keras.layers.GlobalAveragePooling2D(),
tf.keras.layers.Dense(units=200, activation='relu'),
tf.keras.layers.Dense(units=5, activation="softmax")
])

model.compile(optimizer=tf.keras.optimizers.Adam(0.001), metrics=["accuracy"],
loss=tf.keras.losses.sparse_categorical_crossentropy)
clr = CyclicLR(base_lr=0.001, max_lr=0.006, step_size=240)
model.fit(train_dataset, epochs=30, steps_per_epoch=60, validation_data=val_dataset,
validation_steps=1, callbacks=[clr])

By the way train_dataset and val_dataset are tf.data.Datasets.

Versions: Python3 and TF 1.10.

Any idea why the issue?

@Rendiere
Copy link

Hey, I've had a similar issue and I think it's because the tensorflow port of Keras has a slightly different callback API than the original Keras.

To fix this, just replace everywhere you use tf.keras with keras and be sure to import keras (not tensorflow.keras!) in your script.

Let me know if this worked :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants