简体   繁体   English

KeyError: 'val_acc'

[英]KeyError: 'val_acc'

Below are some parameters for the model.fit_generator() function. Theses objects are saved in a list labeled callbacks.以下是 model.fit_generator() function 的一些参数。这些对象保存在标记为回调的列表中。

checkpoint = ModelCheckpoint(
        model_file, 
        monitor= 'val_acc', 
        save_best_only=True)

early_stopping = EarlyStopping(
    monitor='val_loss',
    patience=5,
    verbose=1,
    restore_best_weights=True)


tensorboard = TensorBoard(
    log_dir=log_dir,
    batch_size=batch_size,
    update_freq = 'batch')


reduce_lr = ReduceLROnPlateau(
    monitor='val_loss',
    patience=5,
    cooldown=2,
    min_lr=0.0000000001,
    verbose=1)


#-----------------------------------------------------------------------------------------------------------------#
callbacks = [checkpoint, reduce_lr, early_stopping, tensorboard]

After creating the callback objects and parameters for the objects, I implement the layers and compile(which is not shown because it is irrelevant to the problem I am having).在为对象创建回调对象和参数后,我实现了层并编译(未显示,因为它与我遇到的问题无关)。 Then I run the model.fit_generator function (which uses the callback arguments above):然后我运行 model.fit_generator function(使用上面的回调 arguments):

history = model.fit_generator(
    train_generator,
    steps_per_epoch = steps_per_epoch,
    epochs=epochs,
    verbose=2,
    callbacks=callbacks,
    validation_data=validation_generator,
    validation_steps=validation_steps,
    class_weight=class_weight)

The error that I am getting is:我得到的错误是:

KeyError: 'val_acc'

From my understanding this means that val_acc is not in the list.据我了解,这意味着 val_acc 不在列表中。 But it is.. so need help to understanding why I am getting this error.但它是..所以需要帮助来理解为什么我会收到这个错误。

Edit:编辑:

Picture of the result before the error shows..[ https://i.stack.imgur.com/5lheg.png]错误前的结果图片显示..[ https://i.stack.imgur.com/5lheg.png]

You need to change monitor= 'val_acc' to monitor='val_loss'您需要将monitor= 'val_acc'更改为monitor='val_loss'

checkpoint = ModelCheckpoint(
        model_file, 
        monitor='val_loss', 
        save_best_only=True)

Make sure you have used model.compile(metrics=['accuracy']) , not Accuracy or acc .确保您使用model.compile(metrics=['accuracy']) ,而不是Accuracyacc Also in filepath use val_accuracy .同样在文件路径中使用val_accuracy I have recently faced this problem.我最近遇到了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM