当前位置:网站首页>[tensorflow] sharing mechanism
[tensorflow] sharing mechanism
2022-04-23 13:18:00 【^_^ Min Fei】
List of articles
Because I need to write some TF Code for , Forget about sharing mechanism implementation , Reviewed and wrote .
1. Sharing mechanism
TF Mainly provide Variable Scope This unique mechanism to share variables
> # Create or return a variable with a given name
> tf.get_variable(<name>, <shape>, <initializer>)
>
> # Transfer management to get_variable() The scope of the variable name
> tf.variable_scope(<scope_name>)
2. example
Step 1: Create variables
def conv_relu(input, kernel_shape, bias_shape):
# Create variable named "weights".
weights = tf.get_variable("weights", kernel_shape,
initializer=tf.random_normal_initializer())
# Create variable named "biases".
biases = tf.get_variable("biases", bias_shape,
initializer=tf.constant_initializer(0.0))
conv = tf.nn.conv2d(input, weights,
strides=[1, 1, 1, 1], padding='SAME')
return tf.nn.relu(conv + biases)
Step 2: Define scope : This part is a reusable module , It can be convolution and other operations .
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])
Step3: Reuse
Pay attention here , When reusing a convolution block, be sure to use :scope.reuse_variables()
with tf.variable_scope("image_filters") as scope:
result1 = my_image_filter(image1)
scope.reuse_variables() # The most important sentence
result2 = my_image_filter(image2) # In this case image2 And image1 You can use the same module
3. Reference resources :
- Official website guidelines :variable_scope
- https://www.jianshu.com/p/ab0d38725f88
版权声明
本文为[^_^ Min Fei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230611136673.html
边栏推荐
- 你和42W奖金池,就差一次“长沙银行杯”腾讯云启创新大赛!
- 榜样专访 | 孙光浩:高校俱乐部伴我成长并创业
- According to the salary statistics of programmers in June 2021, the average salary is 15052 yuan. Are you holding back?
- You and the 42W bonus pool are one short of the "Changsha bank Cup" Tencent yunqi innovation competition!
- Filter and listener of three web components
- Brief introduction of asynchronous encapsulation interface request based on uniapp
- FFmpeg常用命令
- Async void caused the program to crash
- SSM整合之pom.xml
- @Excellent you! CSDN College Club President Recruitment!
猜你喜欢

ESP32 VHCI架构传统蓝牙设置scan mode,让设备能被搜索到

Kernel error: no rule to make target 'Debian / canonical certs pem‘, needed by ‘certs/x509_ certificate_ list‘

Use Proteus to simulate STM32 ultrasonic srf04 ranging! Code+Proteus
![[51 single chip microcomputer traffic light simulation]](/img/70/0d78e38c49ce048b179a85312d063f.png)
[51 single chip microcomputer traffic light simulation]

EMMC / SD learning notes

100000 college students have become ape powder. What are you waiting for?

SHA512 / 384 principle and C language implementation (with source code)

@优秀的你!CSDN高校俱乐部主席招募!

LeetCode_ DFS_ Medium_ 695. Maximum area of the island

AUTOSAR from introduction to mastery 100 lectures (52) - diagnosis and communication management function unit
随机推荐
MySQL 8.0.11 download, install and connect tutorials using visualization tools
Super 40W bonus pool waiting for you to fight! The second "Changsha bank Cup" Tencent yunqi innovation competition is hot!
Riscv MMU overview
[dynamic programming] 221 Largest Square
解决虚拟机中Oracle每次要设置ip的问题
Nodejs + Mysql realize simple registration function (small demo)
[untitled] PID control TT encoder motor
缘结西安 | CSDN与西安思源学院签约,全面开启IT人才培养新篇章
Wu Enda's programming assignment - logistic regression with a neural network mindset
Uniapp image import local image not displayed
Vscode tips
LeetCode_DFS_中等_695.岛屿的最大面积
AUTOSAR from introduction to mastery 100 lectures (86) - 2F of UDS service foundation
decast id.var measure. Var data splitting and merging
[official announcement] Changsha software talent training base was established!
[51 single chip microcomputer traffic light simulation]
The use of dcast and melt in R language is simple and easy to understand
SPI NAND flash summary
uniapp image 引入本地图片不显示
[Technical Specification]: how to write technical documents?