import tensorflow as tf
import numpy as np

##save to file
#rember to define the same dtype and shape when restore
# W = tf.Variable([[1,2,3],[3,4,5]],dtype=tf.float32,name='Weights')
# b = tf.Variable([[1,2,3]],dtype=tf.float32,name='biases')

# init = tf.global_variables_initializer()

# saver = tf.train.Saver()

# with tf.Session() as sess:
# sess.run(init)
# save_path = saver.save(sess,"my_net/save_net.ckpt")
# print("save to path",save_path)

#resotre variables
#redefine the same shape and same type for your variables
W = tf.Variable(np.arange(6).reshape((2,3)),dtype=tf.float32,name='Weights')
b = tf.Variable(np.arange(3).reshape((1,3)),dtype=tf.float32,name='biases')

#not need init step
saver = tf.train.Saver()
with tf.Session() as sess:
saver.restore(sess,"my_net/save_net.ckpt")
print("Weights",sess.run(W))
print("biases",sess.run(b))

莫烦tensorflow(9)-Save&Restore的更多相关文章

  1. 莫烦tensorflow(8)-CNN

    import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data#number 1 to 10 dat ...

  2. 莫烦tensorflow(7)-mnist

    import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_data#number 1 to 10 dat ...

  3. 莫烦tensorflow(6)-tensorboard

    import tensorflow as tfimport numpy as np def add_layer(inputs,in_size,out_size,n_layer,activation_f ...

  4. 莫烦tensorflow(5)-训练二次函数模型并用matplotlib可视化

    import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt def add_layer(inputs,in_siz ...

  5. 莫烦tensorflow(4)-placeholder

    import tensorflow as tf input1 = tf.placeholder(tf.float32)input2 = tf.placeholder(tf.float32) outpu ...

  6. 莫烦tensorflow(3)-Variable

    import tensorflow as tf state = tf.Variable(0,name='counter') one = tf.constant(1) new_value = tf.ad ...

  7. 莫烦tensorflow(2)-Session

    import os os.environ['TF_CPP_MIN_LOG_LEVEL']='2' import tensorflow as tfmatrix1 = tf.constant([[3,3] ...

  8. 莫烦tensorflow(1)-训练线性函数模型

    import tensorflow as tfimport numpy as np #create datax_data = np.random.rand(100).astype(np.float32 ...

  9. tensorflow学习笔记-bili莫烦

    bilibili莫烦tensorflow视频教程学习笔记 1.初次使用Tensorflow实现一元线性回归 # 屏蔽警告 import os os.environ[' import numpy as ...

随机推荐

  1. Oracle 12c 的RMAN备份

    备份 rman只备份cdb 只备份CDB数据库需要具有SYSDBA或SYSBACKUP权限用户连接到CDB的root环境下,执行backupdatabase root命令即可完成对CDB的备份,方法如 ...

  2. Python3 tkinter基础 OptionMenu 将list导入下拉列表中

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. 论文笔记:Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks

    Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks ICML 2017 Paper:https://arxiv.org/ ...

  4. 用bytomswap进行“跨链”资产转换

    bytom是专注资产领域的公有区块链平台,最近开发者社区基于比原做了一款资产转换平台.我们可以在上面通过自己现有的资产在比原上发行资产.然后达到资产转换的目的. 一. 以太币资产转换成比原上的资产 首 ...

  5. eclipse中如何在当前工程中查找一个字符串

    ctrl + h 后弹出 tab选项,你选择 file search 然后在下面输入要查找的字符串workset 那里选择你要查找的项目默认是全部项目进行查找

  6. _quest_mod

    该功能实现对任务的优化,设定接受任务的条件,比如VIP等级几或者军衔多少持有何种物品才可以接受任务,同时可以配置任务的随机奖励及几率,以上修改都会在任务文本中体现.还支持任务传送功能,接完任务后,可和 ...

  7. 整合SpringData JPA

    ORM(Object Relational Mapping): 1).编写一个实体类(bean)和数据表进行映射,并且配置好映射关系: //使用JPA注解配置映射关系 @Entity //告诉JPA这 ...

  8. 整合Druid数据源

    pom依赖: <!--引入druid数据源--> <!-- https://mvnrepository.com/artifact/com.alibaba/druid --> & ...

  9. flink入门

    wordCount POM文件需要导入的依赖: <dependency> <groupId>org.apache.flink</groupId> <artif ...

  10. 一段曾经处理datetime的代码

    前记:主要是数据库存储记录时一个属性是以"2019-01"这样的年月进行存储的,当需要根据A年月到B年月取出相关记录时,filter()直接range()是不行的,不是数值区间或者 ...