keras - 属性错误 : 'function' object has no attribute 'set_model'

标签 keras

我正在使用 keras 拟合模型并将回调列表传递给模型 fit_generator 但遇到以下错误。请帮忙。

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

代码片段:

    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)

最佳答案

问题是您传递的是 python 函数 (lr_schedule) 作为回调而不是 Keras 回调对象。您应该改为使用 Keras LearningRateScheduler 回调,如下所示:

lr = LearningRateScheduler(lr_schedule)
callbacks_list=[lr, model_ckpt]

关于keras - 属性错误 : 'function' object has no attribute 'set_model' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55438400/

相关文章:

tensorflow - Keras 自定义合并两个张量

Tensorflow/Keras - 如何公开类别之间的关系?

keras - 数据增强: What exactly does steps_per_epoch mean?

tensorflow - 虽然pc识别gpu,但它使用的是tensorflow-gpu中的CPU

python - Keras Functional API 多输入层

python - Keras > 在具有不同 python 版本的不同机器上使用经过训练的模型

keras - 将 deeplearning4j 模型导出到 Keras

python - 如何可视化keras中卷积神经网络中间层的输出?

deep-learning - 为什么在可视化深度网络中的特征时用线性激活替换 softmax 激活

tensorflow - 我无法从 keras.applications 模块导入 resnet