(1)查看history字典包含哪些值

# 报错语句:accuracy = history_record.history["acc"]
# -------------------------------------------dyc-------------------------------------
history_dict = history_record.history
print("---------------------history_dict.keys()------------------:", history_dict.keys())
# -------------------------------------------dyc-------------------------------------
# 输出:
---------------------history_dict.keys()------------------: dict_keys(['val_loss', 'loss','accuracy'])

(2)示例:如上history字典中包含'accuracy',则若报KeyError: 'acc',就将报错语句中'acc'替换为'accuracy'即可。

(3)history字典输出为:

---------------------history_dict.keys()------------------: dict_keys(['val_loss', 'loss'])

此时需要直接注释掉报错语句,因为会出现:报KeyError: 'acc',然后你将'acc'替换为'accuracy',就会报KeyError: 'accuracy',以此类推。