118、TensorFlow变量共享(二)
import tensorflow as tf
# 在不同的变量域中调用conv_relu,并且声明我们想创建新的变量
def my_image_filter(input_images):
with tf.variable_scope("conv1"):
# Variables created here will be named "conv1/weights" ,"conv1/biases"
relu1 = conv_relu(input_images, [5, 5, 32, 32], [32])
with tf.variable_scope("conv2"):
# Variables created here will be named "conv2/weights" , "conv2/biases"
return conv_relu(relu1, [5, 5, 32, 32], [32]) # 如果你想分享变量,你有两个选择,第一你可以创建一个有相同名字的变量域,使用reuse=True
with tf.variable_scope("model"):
output1 = my_image_filter(input1)
with tf.variable_scope("model", reuse=True): output2 = my_image_filter(input2) # 你也可以调用scope.reuse_variables()来触发一个重用:
with tf.variable_scope("model") as scope:
output1 = my_image_filter(input1)
scope.reuse_variables()
output2 = my_image_filter(input2) # 因为解析一个变量域的名字是有危险的
# 通过一个变量来初始化另一个变量也是可行的
with tf.variable_scope("model") as scope:
output1 = my_image_filter(input1)
with tf.variable_scope(scope, reuse=True):
output2 = my_image_filter(input2)
118、TensorFlow变量共享(二)的更多相关文章
- TF Boys (TensorFlow Boys ) 养成记(三): TensorFlow 变量共享
上次说到了 TensorFlow 从文件读取数据,这次我们来谈一谈变量共享的问题. 为什么要共享变量?我举个简单的例子:例如,当我们研究生成对抗网络GAN的时候,判别器的任务是,如果接收到的是生成器生 ...
- 117、TensorFlow变量共享
# sharing variables # Tensorflow supports two ways of sharing variables # 1.Explicitly passing tf.Va ...
- Tensorflow 变量的共享
https://github.com/chenghuige/tensorflow-exp/blob/master/examples/sparse-tensor-classification/ tens ...
- TensorFlow学习笔记3——变量共享
因为最近在研究生成对抗网络GAN,在读别人的代码时发现了 with tf.variable_scope(self.name_scope_conv, reuse = reuse): 这样一条语句,查阅官 ...
- 4、TensorFlow基础(二)常用API与变量作用域
1.图.操作和张量 TensorFlow 的计算表现为数据流图,所以 tf.Graph 类中包含一系列表示计算的操作对象(tf.Operation),以及在操作之间流动的数据 — 张量对象(tf.Te ...
- TensorFlow学习笔记4——变量共享
因为最近在研究生成对抗网络GAN,在读别人的代码时发现了 with tf.variable_scope(self.name_scope_conv, reuse = reuse): 这样一条语句,查阅官 ...
- tensorflow笔记(二)之构造一个简单的神经网络
tensorflow笔记(二)之构造一个简单的神经网络 版权声明:本文为博主原创文章,转载请指明转载地址 http://www.cnblogs.com/fydeblog/p/7425200.html ...
- tensorflow常用函数(二)
一.变量相关的函数 1)tf.train.list_variables(ckpt_dir_or_file) Returns list of all variables in the checkp ...
- tensorflow学习笔记二:入门基础 好教程 可用
http://www.cnblogs.com/denny402/p/5852083.html tensorflow学习笔记二:入门基础 TensorFlow用张量这种数据结构来表示所有的数据.用一 ...
随机推荐
- 洛谷P2786 英语1(eng1)- 英语作文——map
给一手链接 https://www.luogu.com.cn/problem/P2786 拿这道题当map模板练练手qwq #include<cstdio> #include<cst ...
- js 解决函数加载的问题
var queue = function(funcs, scope) { (function next() { if(funcs.length > 0 ...
- CompletionService的好处与使用场景
转自:https://blog.csdn.net/jdsjlzx/article/details/52912701 FutureTask既是Future.Runnable,又是包装了Callable( ...
- git_clone资源获取失败解决
github上克隆一个仓库到本地,一直失败.还以为是git安装问题,卸载重装无效:又换了个大容量的磁盘目录位置:最后ECS系统也重装还是无效.. remote: Counting objects: 5 ...
- linux处理器子系统调优
- 几种激活Profile的方式
方法一: 选择spring.profiles.active spring.profiles.active=prodspring.profiles.active=dev 方法二: 选择spring.pr ...
- Linux就该这么学08学习笔记
参考链接:https://www.linuxprobe.com/chapter-08.html 防火墙管理工具 众所周知,相较于企业内网,外部的公网环境更加恶劣,罪恶丛生.在公网与企业内网之间充当保护 ...
- This program cannot be run in DOS mode.
问题:通过ftp上传的exe执行时提示“This program cannot be run in DOS mode.” 解决方法:检查ftp传输模式,设置成binary模式上传即可 参考:https ...
- MySQL--07 explain用法
目录 MySQL explain用法 一.explain命令应用 二. Extra(扩展) 三.建立索引的原则(规范) 总结: MySQL explain用法 一.explain命令应用 查询数据的方 ...
- MySQL04-- 版本区别及管理
目录 MySQL版本区别及管理 一.MySQL5.6与MySQL5.7安装的区别 二.MySQL用户权限管理 三.MySQL连接管理 四.MySQL启动关闭流程 五.MySQL实例初始化配置 六.My ...