gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 03:01:51 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com