121、TensorFlow张量命名
# tf.Graph对象定义了一个命名空间对于它自身包含的tf.Operation对象
# TensorFlow自动选择一个独一无二的名字,对于数据流图中的每一个操作
# 但是给操作添加一个描述性的名字可以使你的程序更容易来阅读和调试
# TensorFlow api提供两种方式来重写一个操作的名字
# 1、每一个api函数创建了一个新的tf.Operation或者返回一个新的tf.Tensor接收一个可选的name参数
# 列如tf.constant(42.0,name="answer")创建了一个新的tf.Operation叫做answer
# 并且返回以叫做"answer:0"的tf.Tensor .如果默认的数据流图已经包含了叫做"answer"的操作
# TensorFlow会在后面append,"_1","_2"来使它变得唯一
# 2、tf.name_scope函数使得在名字后面添加一个后缀变得可能
import tensorflow as tf
c_0 = tf.constant(0, name="c") # operation named "c"
# already-used names will be "uniquified"
c_1 = tf.constant(2, name="c") # => operation named "c_1"
# Name scopes add a prefix to all operations created in the same context
with tf.name_scope("outer"):
c_2 = tf.constant(2, name="c") # =>operation nemed "outer/c" # 在层次化文件系统中,名称范围嵌套类似的路径
with tf.name_scope("inner"):
c_3 = tf.constant(3, name="c") # 已经存在的变量名字会返回到前一个变量名加上一个后缀
c_4 = tf.constant(4, name="c") # =>operation named "outer/c_1" # 已经使用的命名空间会被 "uniquified"
with tf.name_scope("inner"):
c_5 = tf.constant(5, name="c") # =>operation named "outer/inner_1/c" init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(c_0)
print(c_1)
print(c_2)
print(c_3)
print(c_4)
print(c_5)
下面是上面代码的输出结果:
2018-02-17 11:01:55.084300: I C:\tf_jenkins\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
Tensor("c:0", shape=(), dtype=int32)
Tensor("c_1:0", shape=(), dtype=int32)
Tensor("outer/c:0", shape=(), dtype=int32)
Tensor("outer/inner/c:0", shape=(), dtype=int32)
Tensor("outer/c_1:0", shape=(), dtype=int32)
Tensor("outer/inner_1/c:0", shape=(), dtype=int32)
121、TensorFlow张量命名的更多相关文章
- AI - TensorFlow - 张量(Tensor)
张量(Tensor) 在Tensorflow中,变量统一称作张量(Tensor). 张量(Tensor)是任意维度的数组. 0阶张量:纯量或标量 (scalar), 也就是一个数值,例如,\'Howd ...
- Tensorflow张量
张量常规解释 张量(tensor)理论是数学的一个分支学科,在力学中有重要应用.张量这一术语起源于力学,它最初是用来表示弹性介质中各点应力状态的,后来张量理论发展成为力学和物理学的一个有力的数学工具. ...
- tensorflow 张量的阶、形状、数据类型及None在tensor中表示的意思。
x = tf.placeholder(tf.float32, [None, 784]) x isn't a specific value. It's a placeholder, a value th ...
- cs224d 作业 problem set2 (二) TensorFlow 实现命名实体识别
神经网络在命名实体识别中的应用 所有的这些包括之前的两篇都可以通过tensorflow 模型的托管部署到 google cloud 上面,发布成restful接口,从而与任何的ERP,CRM系统集成. ...
- tensorflow张量排序
本篇记录一下TensorFlow中张量的排序方法 tf.sort和tf.argsort # 声明tensor a是由1到5打乱顺序组成的 a = tf.random.shuffle(tf.range( ...
- TensorFlow—张量运算仿真神经网络的运行
import tensorflow as tf import numpy as np ts_norm=tf.random_normal([]) with tf.Session() as sess: n ...
- Tensorflow张量的形状表示方法
对输入或输出而言: 一个张量的形状为a x b x c x d,实际写出这个张量时: 最外层括号[…]表示这个是一个张量,无别的意义! 次外层括号有a个,表示这个张量里有a个样本 再往内的括号有b个, ...
- tensorflow张量限幅
本篇内容有clip_by_value.clip_by_norm.gradient clipping 1.tf.clip_by_value a = tf.range(10) print(a) # if ...
- tensorflow中张量(tensor)的属性——维数(阶)、形状和数据类型
tensorflow的命名来源于本身的运行原理,tensor(张量)意味着N维数组,flow(流)意味着基于数据流图的计算,所以tensorflow字面理解为张量从流图的一端流动到另一端的计算过程. ...
随机推荐
- Java{0}占位符替换字符串
Java{0}占位符替换字符串 public class Test { public static void main(String[] args) { System.out.println(Stri ...
- .net日志的用法
public class Logs { private static Logger logger = LogManager.GetCurrentClassLogger(); //初始化日志类 /// ...
- web 前端2 html css一些小问题技巧
html css一些小问题技巧 1 对于儿子块float后,父亲块如果没内容就不见了,如何让父亲块依然跟随飘起了的儿子块撑起来呢?? 用到的属性after方法 公共方法作为继承即可. 1.1 方法 ...
- iBatis框架之配置文件之注意点之总结
1.配置文件sqlMap.xml中需要注意的点 比如: <?xml version="1.0" encoding="UTF-8" ?> <!D ...
- 华为交换机SOCK CPU占用率高处理方法
问题截图: 解决方法: cpu-defend policy cpu auto-defend enable auto-defend attack-packet sample 5 auto-defend ...
- java基础常问面试题
1.面向对象和面向过程的区别 面向过程 :面向过程性能比面向对象高. 因为类调用时需要实例化,开销比较大,比较消耗资源,所以当性能是最重要的考量因素的时候,比如单片机.嵌入式开发.Linux/Unix ...
- vue实现搜索功能
vue实现搜索功能 template 部分 <!-- 搜索页面 --> <template> <div> <div class="goback&qu ...
- Linq 高级应用实例
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- 吉首大学2019年程序设计竞赛(重现赛)I 滑稽树上滑稽果 (莫队+逆元打表)
链接:https://ac.nowcoder.com/acm/contest/992/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K ...
- bzoj3991 [SDOI2015]寻宝游戏 树链的并
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3991 题解 貌似这个东西叫做树链的并,以前貌似写过一个类似的用来动态维护虚树. 大概就是最终的 ...