104、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)
104、Tensorflow 的变量重用的更多相关文章
- TF:Tensorflow定义变量+常量,实现输出计数功能—Jason niu
#TF:Tensorflow定义变量+常量,实现输出计数功能 import tensorflow as tf state = tf.Variable(0, name='Parameter_name_c ...
- TensorFlow 使用变量共享
参考: https://www.tensorflow.org/programmers_guide/variable_scope 举例说明 TensorFlow中的变量一般就是模型的参数.当模型复杂的时 ...
- tensorflow 保存变量,
代码: #!usr/bin/env python# coding:utf-8"""这个代码的作用是 通过 tensorflow 来计算 y = 0.3x + 0.1 的线 ...
- 05 Tensorflow中变量的初始化
打开Python Shell,输入import tensorflow as tf,然后可以执行以下代码. 1.创建一个2*3的矩阵,并让所有元素的值为0.(类型为tf.float) a = tf.ze ...
- tensorflow冻结变量方法(tensorflow freeze variable)
最近由于项目需要,要对tensorflow构造的模型中部分变量冻结,然后继续训练,因此研究了一下tf中冻结变量的方法,目前找到三种,各有优缺点,记录如下: 1.名词解释 冻结变量,指的是在训练模型时, ...
- 深度学习原理与框架-Tensorflow基本操作-变量常用操作 1.tf.random_normal(生成正态分布随机数) 2.tf.random_shuffle(进行洗牌操作) 3. tf.assign(赋值操作) 4.tf.convert_to_tensor(转换为tensor类型) 5.tf.add(相加操作) tf.divide(相乘操作) 6.tf.placeholder(输入数据占位
1. 使用tf.random_normal([2, 3], mean=-1, stddev=4) 创建一个正态分布的随机数 参数说明:[2, 3]表示随机数的维度,mean表示平均值,stddev表示 ...
- Tensorflow模型变量保存
Tensorflow:模型变量保存 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献Tensorflow实战Google深度学习框架 实验平台: Tensorflow1.4.0 pyt ...
- TensorFlow笔记-变量,图,会话
变量 存储一些临时值的作用或者长久存储.在Tensorflow中当训练模型时,用变量来存储和更新参数.变量包含张量(Tensor)存放于内存的缓存区.建模时它们需要被明确地初始化,模型训练后它们必须被 ...
- Tensorflow之变量赋值输出1+2+3+4+5+6+7+8+...
一.导入tensorflow import tensorflow as tf 二.定义计算图 (1)常量初始化 constant_name = tf.constant(value) (2)变量初始化 ...
随机推荐
- Git010--解决冲突
Git--解决冲突 本文来自于:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ ...
- Mac009--Axure RP安装
Mac--Axure RP安装 一.下载Axure RP8.0 下载网址:https://www.axure.com/download (下载mac版本) Axure RP说明: Axure RP是 ...
- 19.ThreadLocal方法解决代码不友好的问题
#ThreadLocal import threading #创建全局ThreadLocal loacl_school = threading.local() class Student(): def ...
- 【Python—参数】*arg与**kwargs参数的用法
在python中,这两个是python中的可变参数,*arg表示任意多个无名参数,类型为tuple;**kwargs表示关键字参数,为dict. # *允许你传入0个或任意个参数,这些可变参数在函数调 ...
- bfs(火星撞地球)
Meteor Shower 链接:https://ac.nowcoder.com/acm/contest/997/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 327 ...
- Blocks题解(区间dp)
Blocks题解 区间dp 阅读体验...https://zybuluo.com/Junlier/note/1289712 很好的一道区间dp的题目(别问我怎么想到的) dp状态 其实这个题最难的地方 ...
- vue.js(6)--v-model
v-model实现数据的双向绑定(简易计算器实例) 简易计算器实例 <!DOCTYPE html> <html lang="en"> <head> ...
- GC(垃圾回收器)中的算法
GC的两种判定方法 (1) 引用计数法 给对象添加一个引用计数器,每当引用一次+1,每次失效时-1,当计数器为0时,表示对象就是不可能再被使用的. (2) 可达性分析算法 将“GC Roots”对象作 ...
- canvas 图片反色
代码实例: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <tit ...
- Es学习第八课, Filter、bool和范围查询
Filter过滤查询 filter是不计算相关性的,同时可以缓存.因此filter速度快于query. 我们先在kibana上先添加数据来做准备 POST /lib4/items/_bulk { &q ...