Tensorflow学习教程------创建图启动图

Posted 行走的祭祀

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tensorflow学习教程------创建图启动图相关的知识,希望对你有一定的参考价值。

  Tensorflow作为目前最热门的机器学习框架之一,受到了工业界和学界的热门追捧。以下几章教程将记录本人学习tensorflow的一些过程。

  在tensorflow这个框架里,可以讲是弱数据类型,也就是说不严格声明数据是什么类型,因为在整个过程中玩的都是向量,或者说矩阵和数组,所有的数据都被看做是一个tensor, 一个或者几个tensor经过一个op(operation)之后,产生新的tensor。首先将所有tensor和op都定义好,然后把这套tensor和op的组合放到默认的图里,用会话启动图,最后我们就看到结果了。以下是创建图和启动图的代码以及结果。

#coding:utf-8
import tensorflow as tf
m1 = tf.constant([[3,3]])
m2 = tf.constant([[2],[3]])
product = tf.matmul(m1,m2)
print (product)
#定义一个会话 启动默认图
sess = tf.Session()
#调用sess的run方法来执行矩阵乘法
result = sess.run(product)
print (result)
sess.close()

  结果如下

I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
Tensor("MatMul:0", shape=(1, 1), dtype=int32)
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasnt compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasnt compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasnt compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasnt compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasnt compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasnt compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: 
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.582
pciBusID 0000:03:00.0
Total memory: 10.91GiB
Free memory: 10.24GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:03:00.0)
[[15]]

 

以上是关于Tensorflow学习教程------创建图启动图的主要内容,如果未能解决你的问题,请参考以下文章

人工智能深度学习入门练习之(21)TensorFlow – 创建计算图

自学tensorflow——1.框架初步了解以及构建简单的计算图计算

基于TensorFlow的深度学习系列教程 2——常量Constant

运行TensorFlow

tensorflow

Tensorflow入门