class LossHistory(keras.callbacks.Callback): def on_train_begin(self, logs={}): self.losses = [] def on_batch_end(self, batch, logs={}): pass # self.losses.append(logs.get('loss')) # print('callback调用!!!!!!!!!') def on_epoch_end(self, epoch, logs=None): # self.losses.append(logs.get('loss')) print_loss = logs.get('loss') val_loss = logs.get('val_loss') print(' callback调用!!!!!!!!! loss:{}'.format(print_loss)) print_loss = str(print_loss) val_loss =str(val_loss) with open(log_path,'a+') as f: f.write(print_loss+' '+val_loss) f.write(' ') history2 = LossHistory() history=my_model.fit(train_high0_img,train_rain,validation_data=(test_high0_img,test_rain),epochs=epochs, validation_freq=1,batch_size=bat,callbacks=[history2])