tensorflow-计算图(3)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 23 11:26:04 2018

@author: myhaspl
"""
import tensorflow as tf
#创建图
c=tf.constant(0.0)
g=tf.Graph()
with g.as_default():
c1=tf.constant(0.1)
g2=tf.get_default_graph()
print(g2)
tf.reset_default_graph()
g3=tf.get_default_graph()
print(g3)
print(c1.name)
t=g.get_tensor_by_name(name="Const:0")
print(t)
a=tf.constant([[1.0,2.0]])
b=tf.constant([[1.0],[3.0]])
tensor1=tf.matmul(a,b,name="exampleop")
print(tensor1.name,tensor1)
test=g3.get_tensor_by_name("exampleop:0")
print(test)

print(tensor1.op.name)
testop=g3.get_operation_by_name("exampleop")
print(testop)

with tf.Session() as sess:
test=sess.run(test)
print(test)
test=tf.get_default_graph().get_tensor_by_name("exampleop:0")
print(test)
tt2=g.get_operations()
print(tt2)

tt3=g.as_graph_element(c1)
print(tt3)

<tensorflow.python.framework.ops.Graph object at 0x7f8aaa8e5160>
<tensorflow.python.framework.ops.Graph object at 0x7f8a90a9a710>
Const:0
Tensor("Const:0", shape=(), dtype=float32)
exampleop:0 Tensor("exampleop:0", shape=(1, 1), dtype=float32)
Tensor("exampleop:0", shape=(1, 1), dtype=float32)
exampleop
name: "exampleop"
op: "MatMul"
input: "Const"
input: "Const_1"
attr {
key: "T"
value {
type: DT_FLOAT
}
}
attr {
key: "transpose_a"
value {
b: false
}
}
attr {
key: "transpose_b"
value {
b: false
}
}

2018-12-25 17:26:56.179157: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
[[7.]]
Tensor("exampleop:0", shape=(1, 1), dtype=float32)
[<tf.Operation ‘Const‘ type=Const>]
Tensor("Const:0", shape=(), dtype=float32)
[

原文地址:http://blog.51cto.com/13959448/2335174

时间: 2024-07-30 14:04:09

tensorflow-计算图(3)的相关文章

tensorflow计算图

tensorflow计算图 计算图是对有向图的表示,主要包含点和边:tensorflow使用计算图计算,计算图的点对应于ops,variables,constant,placeholder等,边对应于Tensors.因此tensorflow主要包含两个部分:构建计算图和runtime运行计算图. 为什么要用计算图? 并行化,因为计算图是对计算的一种抽象,点之间的关系取决其依赖关系.因此,互相不依赖的计算可以并行计算,在多集群环境下可以进行分布式计算. 可移植性性,因为图是一种语言无关的表示方式,

Tensorflow命名空间与计算图可视化

Tensorflow命名空间与计算图可视化 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 参考文献Tensorflow实战Google深度学习框架 实验平台: Tensorflow1.4.0 python3.5.0 Tensorflow可视化得到的图并不仅是将Tensorflow计算图中的节点和边直接可视化,它会根据每个Tensorflow计算节点的命名空间来整理可视化得到效果图,使得神经网络的整体结构不会被过多的细节所淹没.除了显示Tensorflow计算图的结构,Tens

TensorFlow分布式计算机制解读:以数据并行为重

Tensorflow 是一个为数值计算(最常见的是训练神经网络)设计的流行开源库.在这个框架中,计算流程通过数据流程图(data flow graph)设计,这为更改操作结构与安置提供了很大灵活性.TensorFlow 允许多个 worker 并行计算,这对必须通过处理的大量训练数据训练的神经网络是有益的.此外,如果模型足够大,这种并行化有时可能是必须的.在本文中,我们将探讨 TensorFlow 的分布式计算机制. TensorFlow 计算图示例 数据并行 VS. 模型并行 当在多个计算节点

TensorFlow学习笔记(8)--网络模型的保存和读取【转】

转自:http://blog.csdn.net/lwplwf/article/details/62419087 之前的笔记里实现了softmax回归分类.简单的含有一个隐层的神经网络.卷积神经网络等等,但是这些代码在训练完成之后就直接退出了,并没有将训练得到的模型保存下来方便下次直接使用.为了让训练结果可以复用,需要将训练好的神经网络模型持久化,这就是这篇笔记里要写的东西. TensorFlow提供了一个非常简单的API,即tf.train.Saver类来保存和还原一个神经网络模型. 下面代码给

TensorFlow深入MNIST笔记[三]

TensorFlow深入MNIST笔记[三] TensorFlow是进行大规模数值计算的强大库.其优点之一是实施和训练深层神经网络. 加载MNIST数据 from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets('MNIST_data', one_hot=True) 这mnist是一个轻量级的类,它将训练,验证和测试集存储为NumPy数组.它还提供了一个迭代数据服务的功

统计学习方法:罗杰斯特回归及Tensorflow入门

作者:桂. 时间:2017-04-21  21:11:23 链接:http://www.cnblogs.com/xingshansi/p/6743780.html 前言 看到最近大家都在用Tensorflow,一查才发现火的不行.想着入门看一看,Tensorflow使用手册第一篇是基于MNIST的手写数字识别的,用到softmax regression,而这个恰好与我正在看的<统计信号处理>相关.本文借此梳理一下: 1)罗杰斯特回归 2)Softmax Regression 3)基于Tenso

TensorFlow教程05:MNIST深度学习初探

TensorFlow是一个非常强大的用来做大规模数值计算的库.其所擅长的任务之一就是实现以及训练深度神经网络. 在本教程中,我们将学到构建一个TensorFlow模型的基本步骤,并将通过这些步骤为MNIST构建一个深度卷积神经网络. 这个教程假设你已经熟悉神经网络和MNIST数据集.如果你尚未了解,请查看新手指南. 安装 在创建模型之前,我们会先加载MNIST数据集,然后启动一个TensorFlow的session. 加载MNIST数据 为了方便起见,我们已经准备了一个脚本来自动下载和导入MNI

学习笔记TF061:分布式TensorFlow,分布式原理、最佳实践

分布式TensorFlow由高性能gRPC库底层技术支持.Martin Abadi.Ashish Agarwal.Paul Barham论文<TensorFlow:Large-Scale Machine Learning on Heterogeneous Distributed Systems>. 分布式原理.分布式集群 由多个服务器进程.客户端进程组成.部署方式,单机多卡.分布式(多机多卡).多机多卡TensorFlow分布式. 单机多卡,单台服务器多块GPU.训练过程:在单机单GPU训练,

学习笔记TF062:TensorFlow线性代数编译框架XLA

XLA(Accelerated Linear Algebra),线性代数领域专用编译器(demain-specific compiler),优化TensorFlow计算.即时(just-in-time,JIT)编译或提前(ahead-of-time,AOT)编译实现XLA,有助于硬件加速.XLA还在试验阶段.https://www.tensorflow.org/versions/master/experimental/xla/ . XLA优势.线性代数领域专用编译器,优化TensorFlow计算

TensorFlow模型保存和提取方法

TensorFlow模型保存和提取方法 原创 2017年06月01日 11:25:25 标签: TensorFlow / 模型保存 / 模型提取 / tf.train.Saver 7004 一.TensorFlow模型保存和提取方法 1. TensorFlow通过tf.train.Saver类实现神经网络模型的保存和提取.tf.train.Saver对象saver的save方法将TensorFlow模型保存到指定路径中,saver.save(sess,"Model/model.ckpt"