美文网首页我爱编程
初入Tensorflow一览(1)

初入Tensorflow一览(1)

作者: wlhwai | 来源:发表于2017-09-10 17:12 被阅读0次

1. 安装Tensorflow

环境: macOS Sierra 10.12.6


2. 安装方式

在tensorflow的官方指导下,利用virtualenv安装。


3. 安装步骤

3.1 安装virtualenv工具。

$sudo pip install --upgrade virtualenv


3.2 为tensorflow创建环境目录

$ virtualenv --system-site-packages ~/tensorflow$cd~/tensorflow

注释:上面的命令行都是根据tensorflow的官网教程安装的,忘记记录了,下面开始本人的记实操作步骤。


3.3 进入virtualenv环境并安装tensorflow(本人是在VPN环境下安装的,不知道非VPN环境是否被墙)

[wai@waideMacBook ~/tensorflow]$cd bin/

[wai@waideMacBook ~/tensorflow/bin]$source activate

(tensorflow)[wai@waideMacBook ~/tensorflow/bin]$pip install --upgrade tensorflow

Collecting tensorflow

Downloading tensorflow-1.3.0-cp27-cp27m-macosx_10_11_x86_64.whl (39.4MB)

100% |████████████████████████████████| 39.4MB 20kB/s

Collecting six>=1.10.0 (from tensorflow)

Using cached six-1.10.0-py2.py3-none-any.whl

中间省去各种 Collecting...

Building wheels for collected packages: html5lib, markdown

Running setup.py bdist_wheel for html5lib ... done

Stored in directory: /Users/wai/Library/Caches/pip/wheels/6f/85/6c/56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962

Running setup.py bdist_wheel for markdown ... done

Stored in directory: /Users/wai/Library/Caches/pip/wheels/bf/46/10/c93e17ae86ae3b3a919c7b39dad3b5ccf09aeb066419e5c1e5

Successfully built html5lib markdown

Installing collected packages: six, protobuf, backports.weakref, numpy, werkzeug, html5lib, markdown, bleach, tensorflow-tensorboard, funcsigs, pbr, mock, tensorflow

Found existing installation: six 1.4.1

Not uninstalling six at /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python, outside environment /Users/wai/tensorflow

Found existing installation: numpy 1.8.0rc1

Not uninstalling numpy at /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python, outside environment /Users/wai/tensorflow

Successfully installed backports.weakref-1.0rc1 bleach-1.5.0 funcsigs-1.0.2 html5lib-0.9999999 markdown-2.6.9 mock-2.0.0 numpy-1.13.1 pbr-3.1.1 protobuf-3.4.0 six-1.10.0 tensorflow-1.3.0 tensorflow-tensorboard-0.1.6 werkzeug-0.12.2


4. 初用tensorflow,hello tensorflow!

[wai@waideMacBook ~/tensorflow/bin]$source activate

(tensorflow)[wai@waideMacBook ~/tensorflow/bin]$python

Python 2.7.10 (default, Feb  7 2017, 00:08:15)

[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf

>>>

注:因为在virtualenv下安装,所以只能在该环境的python中import tensorflow。

>>> hello = tf.constant('Hello, TensorFlow!')

>>> sess = tf.Session()

2017-09-07 22:42:56.980323: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.

2017-09-07 22:42:56.980373: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

2017-09-07 22:42:56.980392: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.

2017-09-07 22:42:56.980410: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

>>> print(sess.run(hello))

Hello, TensorFlow!

果不其然,虽然都是按照官方指导来操作的,但是还是多多少少遇到一些WARN信息。上面总的意思就是说刚才安装的tensorflow没有采用这四个计算效率更高的库(SSE4.2/AVX/AVX2/FMA)来进行编译,原因为我仅仅是通过pip install来直接安装的。pip install这种安装方式其实就是把人家预编译的tensorflow下载下来然后放置到我电脑的python PATH中,而别人预编译的环境没有采用这四个库来进行编译。如果我想在使用tensorflow的过程中获得更快的计算效率,就得下载tensorflow的源码,通过build的方式来安装。这一步以后再做吧,先熟悉环境。暂且记录下来。之后搞定了再更新。

当然毕竟只是WARN,hello tensorflow是可以正常print的。如果要临时消除这些烦人的WARN,可以通过修改环境变量来屏蔽。

TF(tensorflow)有一个环境变量TF_CPP_MIN_LOG_LEVEL,默认为0:显示所有lOG,往上分别可以设置为:

1:屏蔽INFO级别LOG

2:屏蔽WARN级别LOG

3:屏蔽ERROR级别LOG

>>> import os

>>> os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

>>> sess = tf.Session()

>>> print(sess.run(hello))

Hello, TensorFlow!

WARN被屏蔽啦。

相关文章

  • 初入Tensorflow一览(1)

    1. 安装Tensorflow 环境: macOS Sierra 10.12.6 2. 安装方式 在tensorf...

  • minst识别结果入门(tensorFlow)

    对于初入tensorflow的同学来说(尤其是初入python的同学),minst一般都是第一个教程。它原理简单清...

  • Win10+TensorFlow+Anaconda+CUDA+c

    初入坑,一步掉一个坑,爬出来,埋上,再掉,无穷尽也。 一、准备工作 1. TensorFlow TensorFl...

  • 初入篇1

    “天气越来越凉了呢……” “不,这里马上就有入春了” 此刻站在整个伯洛萨国的最高点--一座满是翠碧色树木围成的山峰...

  • 初入职场(1)

    2015.07.12 新进tx,有些事真的是要经历过才知道适不适合。 来SZ之前,心中还是有万分的不舍。...

  • 初入大学(1)

    现在的我已经大二了,想起大一刚入学所遇到的困难,还是历历在目。 怀着对大学生活的向往,开心的搬入宿舍,谁知寝室竟然...

  • 初入职场1

    LGXX工厂工作日记1 不知道是工作以来三百多少天了,感觉过了很久,但还未满一年。我是2018年7月10号入社...

  • 初入职场1

    工作半年多了,从刚开始的充满激情,到现在的疲惫懒惰,中间似乎也没有发生什么惊天动地的大事,整个人身上的“火”却一点...

  • 初入菜园(1)

    美好的五一假期来临了。外公外婆也从老家来到了屯溪,与我和妈妈共度这个假期。 我和妈妈都非常清楚,外公外婆一...

  • TensorFlow准备

    1、关于TensorFlow 相关网站:TensorFlow、TensorFlow中文社区 TensorFlow™...

网友评论

    本文标题:初入Tensorflow一览(1)

    本文链接:https://www.haomeiwen.com/subject/urktsxtx.html