import tensorflow as tf

def model_1():
with tf.variable_scope("var_a"):
a = tf.Variable(initial_value=[1, 2, 3], name="a") vars = [var for var in tf.trainable_variables() if var.name.startswith("var_a")]
print(len(vars))
return vars def model_2(): vars1 = model_1() with tf.variable_scope("var_b"):
a = tf.Variable(initial_value=[1, 2, 3], name="a") vars2 = [var for var in tf.trainable_variables() if var.name.startswith("var")]
print(len(vars2))
return vars1 def pretrain_model1():
print("-------- model 1 ------")
vars = model_1() with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver()
saver.save(sess, "./model.ckpt") def train_model2():
print("-------- model 2 ------") model1_vars = model_2() with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver(var_list=model1_vars)
saver.restore(sess, "./model.ckpt")
vars = sess.run([model1_vars])
for var in vars:
print(var) step = 2
if step == 1:
pretrain_model1()
else:
train_model2()

tensorflow 只恢复部分模型参数的更多相关文章

  1. TensorFlow 训练好模型参数的保存和恢复代码

    TensorFlow 训练好模型参数的保存和恢复代码,之前就在想模型不应该每次要个结果都要重新训练一遍吧,应该训练一次就可以一直使用吧. TensorFlow 提供了 Saver 类,可以进行保存和恢 ...

  2. 模型文件(checkpoint)对模型参数的储存与恢复

    1.  模型参数的保存: import tensorflow as tfw=tf.Variable(0.0,name='graph_w')ww=tf.Variable(tf.random_normal ...

  3. TensorFlow Object Detection API中的Faster R-CNN /SSD模型参数调整

    关于TensorFlow Object Detection API配置,可以参考之前的文章https://becominghuman.ai/tensorflow-object-detection-ap ...

  4. Tensorflow学习教程------模型参数和网络结构保存且载入,输入一张手写数字图片判断是几

    首先是模型参数和网络结构的保存 #coding:utf-8 import tensorflow as tf from tensorflow.examples.tutorials.mnist impor ...

  5. TensorFlow保存、加载模型参数 | 原理描述及踩坑经验总结

    写在前面 我之前使用的LSTM计算单元是根据其前向传播的计算公式手动实现的,这两天想要和TensorFlow自带的tf.nn.rnn_cell.BasicLSTMCell()比较一下,看看哪个训练速度 ...

  6. 【4】TensorFlow光速入门-保存模型及加载模型并使用

    本文地址:https://www.cnblogs.com/tujia/p/13862360.html 系列文章: [0]TensorFlow光速入门-序 [1]TensorFlow光速入门-tenso ...

  7. fluent批量处理——模型参数的设置

    对于常见的工程应用来说,计算的工况很多,尤其优化工作,少则几百,多则上千,面对如此之多的case文件要写,假如按照一个一个的读写的话,相信你一定会为这么机械的工作烦躁,甚至影响今后好几天的心情,那么有 ...

  8. MySQL只恢复某个库或某张表

    在Mysqldump官方工具中,如何只恢复某个库呢? 全库备份 [root@HE1 ~]#mysqldump -uroot -p --single-transaction -A --master-da ...

  9. TensorFlow保存和载入模型

    首先定义一个tf.train.Saver类: saver = tf.train.Saver(max_to_keep=1) 其中,max_to_keep参数设定只保存最后一个参数,默认值是5,即保存最后 ...

随机推荐

  1. range 小数据池介绍

    1.range 2.小数据池 1. range 范围 [起始位置:终止位置:步长]range(起始位置,终止位置,步长) #顾头不顾尾 3.小数据池 小数据池,也称为小整数缓存机制,或者称为驻留机制等 ...

  2. caffe特征层可视化

    #参考1:https://blog.csdn.net/sushiqian/article/details/78614133#参考2:https://blog.csdn.net/thy_2014/art ...

  3. flutter插件汇总

    audio_recorder: any #录音.播放 flutter_sound: ^#录音 dropdown_menu: ^#下拉菜单 simple_permissions:#权限获取 easy_a ...

  4. springboot(一)

    @Configuration:声明当前类是一个配置类==等同于 spring的xml文件,如果使用了改注解意味着该类里可能有0个或者多个@bean注解,此处没有使用包扫描,是因为所有的@bean 都在 ...

  5. 区间DP 基本题集

    51 Nod 1021 石子归并 模板题,敲就完事了,注意一下这种状态转移方程有个四边形的优化(时间) #include <cstdio> #include <iostream> ...

  6. springboot缓存注解——@CacheEvict

    @CacheEvict:缓存清除 可以通过key指定清除的数据 如果不写默认参数的值 allEntries = true (是否删除该缓存名中所有数据,默认为false) beforeInvocati ...

  7. maven install报错 Failed to execute goal on project my-manager-mapper: Could not resolve dependencies for project com.my:my-manager-mapper:jar:0.0.1-SNAPSHOT:

    报错信息为: [ERROR] Failed to execute goal on project my-manager-mapper: Could not resolve dependencies f ...

  8. python运用PIL制作GIF

    与一.安装Pillow 安装地址:https://pypi.org/project/Pillow/#files 二.准备好图片,并从0开始命名,如下图: (ps:记得存图位置与新建的py文件在同一存放 ...

  9. 学习node.js的一些笔记

    最近看了几眼node.js,以前曾听说它用途很大. 在菜鸟教程上,已看了过半的内容:http://www.runoob.com/nodejs/nodejs-web-module.html,如今看到了这 ...

  10. Web程序报错:Error instantiating servlet

    ---恢复内容开始--- web程序的前期准备工作都做好了,也就是web程序的目录都建好了,在WEB-INF文件夹下建立了classes文件夹,用于存放编好的.class文件.我想这两个类应该都在相应 ...