# 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张量命名的更多相关文章

  1. AI - TensorFlow - 张量(Tensor)

    张量(Tensor) 在Tensorflow中,变量统一称作张量(Tensor). 张量(Tensor)是任意维度的数组. 0阶张量:纯量或标量 (scalar), 也就是一个数值,例如,\'Howd ...

  2. Tensorflow张量

    张量常规解释 张量(tensor)理论是数学的一个分支学科,在力学中有重要应用.张量这一术语起源于力学,它最初是用来表示弹性介质中各点应力状态的,后来张量理论发展成为力学和物理学的一个有力的数学工具. ...

  3. tensorflow 张量的阶、形状、数据类型及None在tensor中表示的意思。

    x = tf.placeholder(tf.float32, [None, 784]) x isn't a specific value. It's a placeholder, a value th ...

  4. cs224d 作业 problem set2 (二) TensorFlow 实现命名实体识别

    神经网络在命名实体识别中的应用 所有的这些包括之前的两篇都可以通过tensorflow 模型的托管部署到 google cloud 上面,发布成restful接口,从而与任何的ERP,CRM系统集成. ...

  5. tensorflow张量排序

    本篇记录一下TensorFlow中张量的排序方法 tf.sort和tf.argsort # 声明tensor a是由1到5打乱顺序组成的 a = tf.random.shuffle(tf.range( ...

  6. TensorFlow—张量运算仿真神经网络的运行

    import tensorflow as tf import numpy as np ts_norm=tf.random_normal([]) with tf.Session() as sess: n ...

  7. Tensorflow张量的形状表示方法

    对输入或输出而言: 一个张量的形状为a x b x c x d,实际写出这个张量时: 最外层括号[…]表示这个是一个张量,无别的意义! 次外层括号有a个,表示这个张量里有a个样本 再往内的括号有b个, ...

  8. tensorflow张量限幅

    本篇内容有clip_by_value.clip_by_norm.gradient clipping 1.tf.clip_by_value a = tf.range(10) print(a) # if ...

  9. tensorflow中张量(tensor)的属性——维数(阶)、形状和数据类型

    tensorflow的命名来源于本身的运行原理,tensor(张量)意味着N维数组,flow(流)意味着基于数据流图的计算,所以tensorflow字面理解为张量从流图的一端流动到另一端的计算过程. ...

随机推荐

  1. [Web 前端] 007 css 常见的七种选择器

    1. 标签选择器 影响范围大 建议尽量应用在层级选择器中 举例 <!-- body 体中的 div --> <div>box...</div> /* style 中 ...

  2. Java方法多态性——方法的重载Overload和重写Override

    方法的重写(Overriding)和重载(Overloading)是java多态性的不同表现,重写是父类与子类之间多态性的一种表现,重载可以理解成多态的具体表现形式. 重写(Override) 重写是 ...

  3. SUST_ACM_2019届暑期ACM集训热身赛题解

    问题A:Hello SUST! 知识点:基本输入输出 C/C++: #include <stdio.h> int main() { int n; scanf("%d", ...

  4. 小白学Python(13)——pyecharts 绘制 柱状图/条形图 Bar

    Bar-基本示例 from example.commons import Faker from pyecharts import options as opts from pyecharts.char ...

  5. Kotlin学习(2)函数

    函数声明: fun plus(a:Int,b:String):Boolean{ //fun 函数名(参数名:参数类型,参数名:参数类型):返回值类型 println(a) return true // ...

  6. PhotonServer新增应用的配置

    一,如下代码配置 <MyGameInstance MaxMessageSize=" MaxQueuedDataPerPeer=" PerPeerMaxReliableData ...

  7. 25.conda 下载安装与运用

    转载:https://www.cnblogs.com/gandoufu/p/9748841.html https://blog.csdn.net/tuzixini/article/details/81 ...

  8. Linux awk抓取IP的两种方式

    ip addr show ens33 | awk -F "[ /]+" '/inet /{print $3}' 或 ifconfig ens33 | awk -F "[ ...

  9. .NET Core _linux sdk安装

    根据官方介绍页面的步骤: 步骤1. sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/do ...

  10. highcharts控制X刻度值整数调整

    function chartData() { var app_id = $('.app_id').attr('app_id'); var gener_id = $('.gener_id').attr( ...