我正在使用keras拟合模型,并将回调列表传递给模型fit_generator,但遇到以下错误。请帮忙。
AttributeError:“函数”对象没有属性“ 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)
答案 0 :(得分:0)
问题是您要传递python函数(lr_schedule
)作为回调而不是Keras回调对象。您应该改为使用Keras LearningRateScheduler
回调,如下所示:
lr = LearningRateScheduler(lr_schedule)
callbacks_list=[lr, model_ckpt]