开始使用编码器和解码器训练简单的NMT(神经机器翻译器),培训在Colab上进行,
encoder = Encoder(vocab_inp_size, embedding_dim, units, BATCH_SIZE)
decoder = Decoder(vocab_tar_size, embedding_dim, units, BATCH_SIZE)
然后使用检查点保存模型,
# On loacl machine dir changed to 'training_checkpoints/' to fit the loaction
checkpoint_dir = './training_checkpoints'
checkpoint_prefix = os.path.join(checkpoint_dir, "ckpt")
checkpoint = tf.train.Checkpoint(optimizer=optimizer,
encoder=encoder,
decoder=decoder)
并在训练期间使用
保存checkpoint.save(file_prefix = checkpoint_prefix)
经过训练后,还原检查点可以在Colab上正常工作,甚至将整个检查点文件夹保存在Google驱动器上并再次还原时也是如此,但是当尝试在我的本地计算机上还原它们时,返回的结果却不尽相同, 在使用进行训练之前先启动检查点
checkpoint.restore(tf.train.latest_checkpoint(checkpoint_dir))
Colab笔记本输出:
Input: <start> يلعبون الكرة <end>
Predicted translation: he played soccer . <end>
本地计算机输出:
Input: <start> يلعبون الكرة <end>
Predicted translation: take either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either either
Colab张量流版本:1.13.0-rc1
本地机器张量流版本:1.12.0
知道这个问题是由于tensorflow的不同版本而导致的,如何在不面临这个问题的情况下保存模型?
NMT笔记本的附加链接 Neural Machine Translation with Attention
答案 0 :(得分:0)
TF仅提供前向兼容性保证:https://www.tensorflow.org/guide/version_compat#compatibility_of_graphs_and_checkpoints 1.13保存1.12无法还原的文件也就不足为奇了。 升级本地机器的张量流?