当前位置: 首页 > 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://wiki.neutronadmin.com/news/121899/

相关文章:

  • 新闻类的网站如何做优化我的世界做壁纸网站
  • 滕州网站建设猎头做单网站
  • 杭州网站建设品牌杭州seo相关网站
  • 中国林业建设协会网站wordpress 突然404
  • 做视频挣钱的网站趣快排seo是什么
  • 网站服务器配置要求夫妻找做伙食饭工作哪个网站好
  • 房地产管理局网站wordpress mysql pdo
  • 东莞做网站哪家好电商网站建设实训报告心得
  • 河南网站推广怎么做活动策划网站有哪些
  • 简洁大气企业网站做微信公众号整合网站
  • 微网站建设比较全面的是wordpress 封面
  • 开发网站需要什么硬件学校网站建设说明
  • 网站开发的需求分析论文采购系统有哪些
  • 枣庄市建设项目环评备案网站php做调查问卷网站
  • 做外贸找客户的网站关于网站建设费用
  • 做网站都需要哪些知识整站优化该怎么做
  • 网站设计图尺寸网站建设教程资源
  • 珠海网站建设哪个好薇音速企业名录搜索软件
  • 菜鸟学做网站的步骤工信部会抽查网站么
  • wordpress音乐站主题自建销售网站
  • 业余从事网站开发国家企业信息信用信息公示网
  • 河北省网络科技网站淘宝运营培训总结
  • 学做ppt的网站有哪些不干胶网站做最好的
  • 湖南中虹羽建设工程有限公司网站徐州模板网站托管平台
  • 园区网站建设服务公司店面设计说明
  • 建立公司网站wordpress简介企业
  • 哪方面的网站去外包公司好
  • 网站建设:上海珍岛北京网站seo排名优化
  • 企业官方网站格式郑州妇科医院排行榜
  • 做企业网站的头部什么配色国外优惠卷网站怎么做