在Colab中在中断时保存Tensorflow编译模型

我有一个模型,它需要很长时间才能完成纪元(设置为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()

运行此命令时,出现错误:

  

NameError:未定义名称“模型”

有什么想法吗? 任何帮助将不胜感激。

CS

lwb896148823 回答:在Colab中在中断时保存Tensorflow编译模型

在该行之间不是中断,而是在拟合过程中的其他地方。那

keras

我总是使用类似的东西

本文链接:https://www.f2er.com/3132552.html

大家都在问