Tensorflow,tf.train.Saver 保存了什么? [英] Tensorflow, what is saved with tf.train.Saver?

查看:33
本文介绍了Tensorflow,tf.train.Saver 保存了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在每个训练时期后使用 tf.train.Saver() 保存我的模型时究竟保存了什么.与我习惯使用 Keras 模型的文件相比,该文件似乎有点大.现在我的 RNN 每次保存占用 900 MB.有什么方法可以告诉保护程序只保存可训练的参数吗?我还想要一种仅保存部分模型的方法.我知道我可以获取我定义的变量并使用 numpy 格式保存它们但是当我使用 RNN 类时我不能直接访问它们的权重我查看了代码并且没有像 get_weights 这样的东西我可以看到.

I am wondering what exactly is saved when I use a tf.train.Saver() to save my model after every training epoch. The file seems kind of large compared to what I am used to with Keras models. Right now my RNN takes up 900 MB at each save. Is there any way to tell the saver to only save the trainable parameters? I would also like a way to save only part of the model. I know I can just get the variables I define and save them using the numpy format but when I use the RNN classes I don't directly have access to their weights and I looked through the code and there is nothing like get_weights that I can see.

推荐答案

您可以在 Saver 构造函数中提供要保存的变量列表,即 saver=tf.train.Saver(var_list=tf.trainable_variables())

You can provide a list of variables to save in the Saver constructor, ie saver=tf.train.Saver(var_list=tf.trainable_variables())

这篇关于Tensorflow,tf.train.Saver 保存了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆