我有一个模型,它需要很长时间才能完成历元(设置为129(。比方说,我想参加训练,但不想失去模特。
model.compile(loss ='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
history = model.fit(X_modified, ys, epochs = 127, verbose=1, callbacks=[callbacks] ) # verbose 1 means progress bar
from keras.models import load_model
file_Name = "shahnameh_embdding64_bidirectional_LSTM400_softmax.h5"
model.save(file_Name)
我使用了回调:
class myCallback(tf.keras.callbacks.Callback):
def on_train_begin(self, logs={}):
self.models = []
def on_epoch_end(self, epoch, logs={}):
try:
target_acc = .2
if logs.get('acc') > target_acc:
print('nReached '+target_acc+'% accuracy, so cancelling the accuracy')
self.model.stop_training = True
models.append(model)
except KeyboardInterrupt:
model = self.models[-1]
callbacks = myCallback()
当我运行这个时,我得到错误:
名称错误:名称"models"未定义
有什么想法吗?如有任何帮助,我们将不胜感激。
CS-
它不是在那行之间中断,而是在拟合期间的其他地方。呢
callbacks = myCallback()
try:
history = model.fit(X_modified, ys, epochs = 127, verbose=1, callbacks=[callbacks] )
except:
model.save(file_Name)
我总是用这样的东西通过