码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-07 14:32:22      阅读:418      评论:0      收藏:0      [点我收藏+]

标签:一个   sha   dev   1.5   组合   color   load   atm   logs   

  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学习教程------创建图启动图

标签:一个   sha   dev   1.5   组合   color   load   atm   logs   

原文地址:http://www.cnblogs.com/cnugis/p/7634257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!