简体   繁体   English

样式转移:在 tensorflow 1.15.0 中保存和恢复检查点/模型

[英]Style Transfer : Save&Restore checkpoint/model in tensorflow 1.15.0

i am a bit frustrated about saving and restoring models in tensorflow 1.15.0.我对在 tensorflow 1.15.0 中保存和恢复模型感到有些沮丧。 I want to achieve it in a jupyter notebook / google colab notebook environment.我想在 jupyter notebook / google colab notebook 环境中实现它。 The application is style-transfer of images.该应用程序是图像的风格转移。

I simply want to save the model and restore it in order to apply the style transfer for a larger number of images.我只是想保存模型并恢复它,以便为大量图像应用样式转换。

The tensorflow documentation is a bit confusing, (i did not find examples for this), so i never really know what the right syntax looks like. tensorflow 文档有点混乱,(我没有找到这方面的例子),所以我从来不知道正确的语法是什么样的。

I am at a point now where i want to achieve 1 thing:我现在想实现一件事:

  1. Restore the model correctly.正确恢复模型。

I will write the relevant lines now:我现在将写下相关的行:

model = get_model()  
opt = tf.train.AdamOptimizer(learning_rate=2.5,beta1=0.99, epsilon=1e-1)
saver = tf.train.Checkpoint(model=model, optimizer=opt)
saver.save('/content/sample_data/test/_____NEU____')

When i want to restore the model, i use the command:当我想恢复模型时,我使用以下命令:

saver.restore('/content/sample_data/test/_____NEU____')

How can i fix this issue, and load my checkpoint files correctly?我该如何解决这个问题,并正确加载我的检查点文件? Thank you谢谢


The google colab project is here: google colab 项目在这里:

https://colab.research.google.com/drive/12hTitoQ2-tH8pYEsfMDR5jtsg8a96PgC https://colab.research.google.com/drive/12hTitoQ2-tH8pYEsfMDR5jtsg8a96PgC


I also tried saving the model via the keras - syntax.我还尝试通过 keras - 语法保存模型。

model.load_weights('/content/sample_data/saved_model/my_model6.h5')

and

model.save_weights('/content/sample_data/saved_model/my_model6.h5', save_format='h5')

There was no error message, but the model did not load in the previously trained weights.没有错误消息,但模型没有加载之前训练的权重。 I asked someone in a mirc-channel yesterday and he said it could be a bug in tf.keras for tensorflow 1.15.0 , but i tried it with tensorflow 1.14.0 and 1.13.1 yesterday without success.我昨天在 mirc-channel 中问过某人,他说这可能是 tensorflow 1.15.0 的 tf.keras 中的一个错误,但我昨天在 tensorflow 1.14.0 和 1.13.1 上尝试了它,但没有成功。

This technique is one where the model doesn't change, but you update the input image to produce the desired output.这种技术是模型不会改变的一种技术,但您更新输入图像以产生所需的输出。 .. so there was nothing wrong with the saving, but the model just did not change. ..所以保存没有任何问题,但模型没有改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM