问题描述
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 (将#修改为@)