当前位置: 首页 > news >正文

北京正规网站建设调整网站收录入口申请查询

北京正规网站建设调整,网站收录入口申请查询,个人网店店铺名字,怎么在wordpress建英文网站前言 探索一下variable_scope和name_scope相关的作用域#xff0c;为下一章节tensorboard的学习做准备 其实关于variable_scope与get_variable实现变量共享#xff0c;在最开始的博客有介绍过#xff1a; 【TensorFlow-windows】学习笔记二——低级API 当然还是国际惯例…前言 探索一下variable_scope和name_scope相关的作用域为下一章节tensorboard的学习做准备 其实关于variable_scope与get_variable实现变量共享在最开始的博客有介绍过 【TensorFlow-windows】学习笔记二——低级API 当然还是国际惯例参考博客 tensorflow: name_scope 和 variable_scope区别及理解 tensorflow学习笔记(十七):namevariable scope tensorflow官方文档name_scope tensorflow官方文档get_varialbe tensorflow官方文档variable_scope variable_scope相关 先引入对应包 import tensorflow as tf import numpy as npVariable定义的变量是否共享 a1 tf.Variable(1,nameaaa) a2 tf.Variable(2,nameaaa) inittf.initialize_all_variables() with tf.Session() as sess:sess.run(init)print(a1.eval())#1print(a2.eval())#2 print(a1) #tf.Variable aaa:0 shape() dtypeint32_ref print(a2) #tf.Variable aaa_1:0 shape() dtypeint32_ref结论Variable定义的权重不共享会自动给变量按照定义顺序加后缀_索引比如第2此定义的aaa得到的名字是aaa_1所以他们是完全不同的两个变量名称也不同。 Variable定义与get_variable定义有什么区别 #variable创建方式 tf.Variable(initial-value, nameoptional-name) #get_variable创建方式 tf.get_variable(name,shapeNone,dtypeNone,initializerNone,regularizerNone,trainableTrue,collectionsNone,caching_deviceNone,partitionerNone,validate_shapeTrue,use_resourceNone,custom_getterNone,constraintNone )结论Variable定义不实现共享所以只需要初始值就行了名字无所谓。get_variable要通过名字实现共享所以必须给变量一个名字其余无所谓。 直接定义两个同名的get_variable变量 b1 tf.get_variable(nameb,initializer10) init tf.initialize_all_variables() with tf.Session() as sess:sess.run(init)print(b1.eval())#10 b2 tf.get_variable(nameb,initializer20)Variable b already exists, disallowed. Did you mean to set reuseTrue or reusetf.AUTO_REUSE in VarScope? Originally defined at:结论不能直接定义两个同名get_variable变量必须通过特定方法实现共享 第一种共享方法 在variable_scope内部使用reuse_variables函数 with tf.variable_scope(dd) as scope:d1tf.get_variable(named,initializer10.0,dtypetf.float32)scope.reuse_variables()d2tf.get_variable(named,initializer20.0,dtypetf.float32)上述在同一个变量空间中定义两个同名变量通过reuse_variable实现共享输出结果如下 print(d1,d2) inittf.initialize_all_variables() with tf.Session() as sess:sess.run(init)print(d1.eval(),d2.eval())tf.Variable dd/d:0 shape() dtypefloat32_ref tf.Variable dd/d:0 shape() dtypefloat32_ref 10.0 10.0结论可以通过reuse_variable实现共享但是第二次初始化的值是无法覆盖第一次初始化的值的 第二种共享方法 在使用variable_scope建立变量空间的时候如果是复用一个已定义的变量空间中的变量直接将reuse设置为True with tf.variable_scope(ff) as scope:f1tf.get_variable(namef,initializer10.0,dtypetf.float32) with tf.variable_scope(ff,reuseTrue) as scope:f2tf.get_variable(namef,initializer20.0,dtypetf.float32) with tf.variable_scope(gg) as scope:gtf.get_variable(namef,initializer20.0,dtypetf.float32)输出看看 print(f1,f2,g) inittf.initialize_all_variables() with tf.Session() as sess:sess.run(init)print(f1.eval(),f2.eval(),g.eval())tf.Variable ff/f:0 shape() dtypefloat32_ref tf.Variable ff/f:0 shape() dtypefloat32_ref tf.Variable gg/f:0 shape() dtypefloat32_ref 10.0 10.0 20.0结论可以通过函数参数reuse实现变量共享 不同变量空间中的相同名称变量是否共享 结论无法共享比如上例中f1和g无法共享虽然名称都是f但是所在变量空间不同。 第三种共享方法 调用函数的时候自动检测是否需要reuse with tf.variable_scope(ee,reusetf.AUTO_REUSE) as scope:e2tf.get_variable(namee,initializer10.0,dtypetf.float32)e3tf.get_variable(namee,initializer20.0,dtypetf.float32) with tf.variable_scope(ee,reusetf.AUTO_REUSE) as scope:e4tf.get_variable(namee,initializer30.0,dtypetf.float32) init tf.initialize_all_variables() with tf.Session() as sess:sess.run(init)print(e2,e3,e4)print(e2.eval(),e3.eval(),e4.eval())tf.Variable ee/e:0 shape() dtypefloat32_ref tf.Variable ee/e:0 shape() dtypefloat32_ref tf.Variable ee/e:0 shape() dtypefloat32_ref 10.0 10.0 10.0如果之前没创建过共享变量不适用自动检测而直接reuse会报错 with tf.variable_scope(ee,reuseTrue) as scope:e2tf.get_variable(namee,initializer10.0,dtypetf.float32) Variable ee/e does not exist, or was not created with tf.get_variable(). Did you mean to set reusetf.AUTO_REUSE in VarScope?结论如果不确定之前是否创建过共享变量最好是使用AUTO_REUSE自动检测 name_scope相关 直接用namescope是否能隔绝共享变量 with tf.name_scope(f) as nscope:f1 tf.get_variable(f,initializer10.0,dtypetf.float32) with tf.name_scope(g) as nscope:g tf.get_variable(f,initializer20.0,dtypetf.float32)Variable f already exists, disallowed. Did you mean to set reuseTrue or reusetf.AUTO_REUSE in VarScope? Originally defined at:结论无法直接用name_scope隔绝共享变量 在不同namesope中是否可以共享变量 创建两个命名空间但是两个命名空间包含相同的变量空间设置共享变量h with tf.name_scope(test1) as scope:with tf.variable_scope(h,reusetf.AUTO_REUSE):h1 tf.get_variable(hh,initializer10.0,dtypetf.float32) with tf.name_scope(test2) as scope:with tf.variable_scope(h,reusetf.AUTO_REUSE):h2 tf.get_variable(hh,initializer10.0,dtypetf.float32)测试是否能实现变量共享 init tf.initialize_all_variables() with tf.Session() as sess:sess.run(init)print(h1,h2)print(h1.eval(),h2.eval())optf.assign(h1,30.0)sess.run(op)print(h1.eval(),h2.eval())tf.Variable h/hh:0 shape() dtypefloat32_ref tf.Variable h/hh:0 shape() dtypefloat32_ref 10.0 10.0 30.0 30.0结论命名空间不能控制是否共享但是变量空间可以控制变量共享。 总结 get_variable与variable_scope配合可以实现变量共享。 name_scope无法实现变量共享但是如果看过之前的博客可以发现它的一个作用是将一系列操作封装在一起这样画图的时候网络结构比较清晰。 其它作用以后遇到再补充主要是为了下一章节学习tensorboard做准备。
http://www.huolong8.cn/news/121899/

相关文章:

  • 网站地图有哪些网址道路运输电子证照
  • perl 网站开发网站收录变少
  • 招聘网站模板页深圳网络营销外包好吗
  • 坪地网站建设信息社交新零售
  • 广州手机网站设计电商网站备案
  • 一开始用php做网站建筑行业信息查询平台
  • 河南省建协网官方网站网站开发任务需求书
  • 搜狗提交网站收录入口重庆商城网站制作报价
  • 做网站全过程广告推广语
  • 南京高端网站建设哪家好上海建设学校网站
  • 学院网站建设与管理办法怎么建设一个优秀的网站
  • 色彩 导航网站crm管理系统功能
  • 网站建设 不需要见面网站建设要注意些什么
  • nas可以做视频网站吗wordpress 仿微信主题
  • 网站所有权问题湛江网络
  • 微信网站后台功能芙蓉建设官方网站
  • 上饶网站设计公司施工企业法定条件
  • 注册网站会员会泄露信息吗商业网站平台
  • 文件外链网站html标签
  • 微网站免费软件建设部标准规范网站
  • 网站ui设计用什么软件做微信公众号和网站建设
  • 网站模板 扁平化一个网站推广
  • 潍坊定制网站搭建湖南汽车软件网站建设
  • 用html5制作个人网站莱芜百姓网
  • 东莞建设网站制作电商平台推广方式有哪些
  • 网站建设一般多少钱比较合适微信小商城怎么开通
  • 高校网站建设需求分析报告325建筑人才网招聘
  • wordpress 手机自适应百度seo收录软件
  • 淄博网站建设公司有多少家平顺网站建设
  • 佛山做网站制作建设电子商务网站策划书