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)变量初始化 ...
随机推荐
- Python分布式爬虫必学框架Scrapy打造搜索引擎 学习教程
Python分布式爬虫打造搜索引擎Scrapy精讲—用Django实现搜索的自动补全功能 elasticsearch(搜索引擎)提供了自动补全接口 1.创建搜索自动补全字段suggest自动补全需要用 ...
- TCGA癌症缩写、癌症中英文对照
Cohort 英文名称 中文名称 ACC Adrenocortical carcinoma 肾上腺皮质癌 BLCA Bladder Urothelial Carcinoma 膀胱尿路上皮癌 BRCA ...
- 前端最常用的跨域方式--jsonp
jsonp通过动态创建script标签的方式来实现跨域通信.原理是浏览器允许html标签在不同的域名下加载资源. <script> var script = document.create ...
- 这样设计 Java 异常更优雅,赶紧学!
来源:lrwinx.github.io/2016/04/28/如何优雅的设计java异常/ 导语 异常处理是程序开发中必不可少操作之一,但如何正确优雅的对异常进行处理确是一门学问,笔者根据自己的开发经 ...
- Cannot modify header information - headers already sent by出错的原因
<?php ob_start(); setcookie("username","送家",time()+3600); echo "the user ...
- 2019 Multi-University Training Contest 1 - 1009 - String - 贪心
不知道错在哪里. 是要把atop改成stop!两个弄混了.感谢自造样例. #include<bits/stdc++.h> using namespace std; typedef long ...
- linux php 中session 多站点共享session问题
linux php 中session默认file 假如修改为redis php.ini session.save_handler = "files"; session.save_p ...
- RDD缓存
RDD的缓存 Spark速度非常快的原因之一,就是在不同操作中可以在内存中持久化或缓存数据集.当持久化某个RDD后,每一个节点都将把计算的分片结果保存在内存中,并在对此RDD或衍生出的RDD进行的其他 ...
- LeetCode Array Easy 448. Find All Numbers Disappeared in an Array
Description Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear ...
- [置顶]unity常用开发套件
维京人骨骼动画制作(Unity 2D Animation资源包使用指南) 维京人骨骼动画制作2(Unity 2D IK资源包使用指南) -------------------------------- ...