如何修复:模块 'keras.utils.generic_utils' 没有属性 'populate_dict_with_module_objects'

How to fix : module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'

我正在尝试使用 keras.callbacks 来监控我的神经网络,但出现此错误。

AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'

参考代码:

from keras.callbacks import EarlyStopping
es = EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=50)

如果你的 TF 版本是 2.5 使用

from tensorflow.python.keras.callbacks import EarlyStopping 

或者您可以将 TF 版本降级到 2.1。

pip install tensorflow==2.1.0