Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'function' object has no attribute 'set_model'

Tags:

keras

I am fitting a model using keras and passed the callbacks list to the model fit_generator but encounterd the following error.Please help.

AttributeError: 'function' object has no attribute 'set_model'

Code snippet :

    from keras.callbacks import LearningRateScheduler
    import numpy as np
    from keras import optimizers
    from keras.callbacks import *

    def lr_schedule(epoch):
        lrate = 0.1
        if epoch > 50:
            lrate = 0.01
        elif epoch > 75:
            lrate = 0.001       
        return lrate


    filepath="latest_weight_ckpt_{epoch:02d}_{val_acc:.2f}.hdf5"
    model_ckpt = ModelCheckpoint(filepath, monitor='val_acc', verbose=1, 
    save_best_only=True, mode='max')
    #lists = [model_ckpt]


    #model_checkpoint= ModelCheckpoint("weights/DenseNet-BC-100-12- 
    CIFAR100.h5", monitor="val_acc", 
    save_best_only=True,save_weights_only=True)

    callbacks_list=[lr_schedule, model_ckpt]

    model.fit_generator(train_generator, epochs=25, 
    steps_per_epoch=200,verbose=1, validation_steps=200, 
    validation_data=validation_generator,callbacks=callbacks_list)
like image 721
abhishek Kumar Avatar asked Oct 27 '25 08:10

abhishek Kumar


1 Answers

The problem is that you are passing a python function (lr_schedule) as a callback instead of a Keras callback object. You should instead use the Keras LearningRateScheduler callback as follows:

lr = LearningRateScheduler(lr_schedule)
callbacks_list=[lr, model_ckpt]
like image 143
Anna Krogager Avatar answered Oct 29 '25 06:10

Anna Krogager



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!