【问题标题】:AttributeError: 'list' object has no attribute 'set_model'AttributeError:“列表”对象没有属性“set_model”
【发布时间】:2018-10-30 11:29:46
【问题描述】:

我正在尝试使用提前停止和模型检查点来保存最佳模型,同时训练深度卷积神经网络。但是,我收到以下错误:

 callback.set_model(model)
 AttributeError: 'list' object has no attribute 'set_model'

到目前为止我的代码是:

model = Sequential()

###First block
model.add(Conv2D(100,kernel_size = (3,3),activation = 'relu',padding = 'same',input_shape=(12,11,1)))
model.add(Conv2D(100,kernel_size = (3,3),activation = 'relu',padding = 'same'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Dropout(0.20))


###Second block

model.add(Conv2D(128,kernel_size = (3,3),activation = 'relu',padding = 'same'))
model.add(Conv2D(128,kernel_size = (3,3),activation = 'relu',padding = 'same'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Dropout(0.10))


model.add(Flatten())

#model.add(Dense(100,activation = 'relu',kernel_regularizer=regularizers.l2(0.01)))
model.add(Dense(1000,activation = 'relu',kernel_regularizer=regularizers.l2(0.01)))
model.add(Dropout(0.30))
model.add(Dense(500,activation = 'relu',kernel_regularizer=regularizers.l2(0.01)))
model.add(Dropout(0.10))
#model.add(Dense(500,activation = 'relu',kernel_regularizer=regularizers.l2(0.01)))
#model.add(Dropout(0.15))

model.add(Dense(5,activation = 'softmax')) 

model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])


earlystop = [EarlyStopping(monitor='val_acc', min_delta=0.001, patience=5,
                          verbose=1, mode='auto')]


outputModel = 'outputModel'

model_json = model.to_json()
with open(outputModel+".json", "w") as json_file:
    json_file.write(model_json)
modWeightsFilepath=outputModel+"_weights.hdf5"
checkpoint = ModelCheckpoint(modWeightsFilepath, monitor='val_acc', verbose=1, save_best_only=True, save_weights_only=True, mode='auto')

callbacks_list = [earlystop,checkpoint]


history = model.fit(x_train, Y,
      batch_size=100, ##number of observations per batch
      epochs=100, ##Number of epochs
      callbacks = callbacks_list,
      verbose=1,
      shuffle = True,
      validation_split=0.2) ###Data for evaluation

我不知道我做错了什么。我读到 ModelCheckPoint 和 earlystopping 应该作为一个列表给出,这就是为什么我明确地将其设为:

  callbacks_list = [earlystop,checkpoint]

我们将不胜感激。

【问题讨论】:

    标签: python keras conv-neural-network


    【解决方案1】:

    您对回调是正确的,但earlystop 已经是这里的列表。删除[EarlyStopping(..)] 周围的括号以解决问题。

    【讨论】:

      猜你喜欢
      • 2021-07-05
      • 2018-01-16
      • 2016-05-14
      • 2016-12-21
      • 2022-01-23
      • 2022-01-23
      • 2019-11-01
      • 2021-08-23
      • 2016-04-22
      相关资源
      最近更新 更多