如何解决'CustomModelCheckpoint' 中的 AttributeError:对象没有属性 'epoch'
File "C:\ConnectomeNet\model_utils.py",line 180,in on_train_end
self.epoch,self.acc,self.loss,self.val_acc)
AttributeError: 'CustomModelCheckpoint' object has no attribute 'epoch'
这是我在 CustomModelCheckpoint 中的代码部分:
class CustomModelCheckpoint(tf.keras.callbacks.Callback):
def __init__(self,date_path,name_model):
self.date_path = date_path
self.name_model = name_model
def on_epoch_end(self,epoch,logs=None):
if 'Autoencoder' in self.name_model:
self.acc = round(logs.get("output_acc"),2)
self.loss = str([round(logs.get("output_loss"),2),round(logs.get("autoencoder_loss"),2)])
self.val_acc = round(logs.get("val_output_acc"),2)
else:
self.acc = round(logs.get("accuracy"),2)
self.loss = round(logs.get("loss"),2)
self.val_acc = round(logs.get("val_accuracy"),2)
self.epoch = epoch
def on_train_end(self,logs=None):
name_model = '/{}_{:02d}-{}-{}-{}.h5'.format(self.name_model,self.epoch,self.val_acc)
weights_path = self.date_path + name_model
if not os.path.exists(self.date_path + "/"):
os.makedirs(self.date_path + "/")
# self.model.save_weights(self.date_path + "/",save_format='tf')
tf.keras.models.save_model(self.model,weights_path)
# self.model.save(weights_path)
非常感谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。