tensorflow data's save and load

Posted tangpg

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tensorflow data's save and load相关的知识,希望对你有一定的参考价值。

note:

if you‘ll load data,the data shape should be similar with saved data‘s shape.    -- 中式英语,天下无敌

 

import tensorflow as tf
import numpy as np

# save variable data
W = tf.Variable([[2, 3], [3, 4]], dtype=tf.float32)
b = tf.Variable([[3, 4]], dtype=tf.float32)

init = tf.global_variables_initializer()
saver = tf.train.Saver()
with tf.Session() as sess:
    sess.run(init)
    saver_path = saver.save(sess, templates/save_net.ckpt)
    print("save path in --", saver_path)


# load saved Variable‘s data
W = tf.Variable(np.arange(2).reshape((1, 2)), dtype=tf.float32)  # 2, 2)  二行两列
b = tf.Variable(np.arange(2).reshape((2, 2)), dtype=tf.float32)  # (1, 2)  一行两列

saver = tf.train.Saver()

with tf.Session() as sess:
    saver.restore(sess, templates/save_net.ckpt)
    print("W: ", sess.run(W))
    print("b: ", sess.run(b))

 

以上是关于tensorflow data's save and load的主要内容,如果未能解决你的问题,请参考以下文章

为啥 TensorFlow 的 `tf.data` 包会减慢我的代码速度?

TensorFlow 多对一 RNN 时间序列

Tensorflow中的tensor Dimension问题

Tensorflow2数据增强(data_augmentation)代码

[翻译] TensorFlow Programmer's Guide之Frequently Asked Questions(问得频率最多的几个问题)

hugeng007_tensorflow_mnist.ipynb