201803221142
=====================================
1 Tensorflow简介与入门指导 [1]
Tensorflow是一个编程系统。
Tensorflow官方网站 [3]
Tensorflow中文社区 [4]
=====================================
2 初步使用与安装[2]
配置:MacOS + virtualenv
实现过程如下
$virtualenv --system-site-packages ~/tensorflow
#创建虚拟空间路径
如果没有安装,则要安装,其中tensorflow分为CPU和GPU两种版本(python需要第一个用pip3)
$pip install --upgrade pip#先更新pip版本
$pip install tensorflow #第一种
$pip install $TF_BINARY_URL #第二种
$pip install 你下载的tensorflow安装包路径 #第三种
$cd ~/targetDirectory. #python3
$cd ~/tensorflow #python2
$cd ~/tensorflow2 #python2
$ source bin/activate # 如果使用 bash
#从源代码树的根路径执行
(tensorflow)$ cd tensorflow/models/image/mnist
(tensorflow)$pythonx
(tensorflow)$ deactivate # 停用 virtualenv
201712030519问题:命令
解决:
管理员sudo –s
查询python python --version
使用 tensorflow 时激活虚拟环境
$ source ~/tensorflow/bin/activate # bash, sh, ksh, or zsh
$ source ~/tensorflow/bin/activate.csh # csh or tcsh
=====================================
3 入手Tensorflow
问题1:网站上的下载代码链接失效
解决:[9]
问题2:TypeError: only integer scalar arrays can be converted to a scalar index
解决:Numpy版本的问题 [9]
1 return numpy.frombuffer(bytestream.read(4), dtype=dt) 2 #改为 3 return numpy.frombuffer(bytestream.read(4), dtype=dt)[0]
问题3:EOFError: Compressed file ended before the end-of-stream marker was reached
解决:[10]
删除下载下来的文件夹,本篇里的文件夹名是data,删除之后重新运行
问题4:WARNING:tensorflow:From /Users/jiaxiaobin/targetDirectory/lib/python3.6/site-packages/tensorflow/python/util/tf_should_use.py:118: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.Instructions for updating:Use `tf.global_variables_initializer` instead.
1 WARNING:tensorflow:From /Users/jiaxiaobin/targetDirectory/lib/python3.6/site-packages/tensorflow/python/util/tf_should_use.py:118: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02. 2 Instructions for updating: 3 Use `tf.global_variables_initializer` instead.
解决:[11]
Solution is to use the updated method global_variables_initializer() instead of initialize_all_variables
1 >>>init = tf.global_variables_initializer()
问题5:2018-04-05 21:06:08.618154: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
1 2018-04-05 21:06:08.618154: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
解决:判断你的CPU可以开启AVX2 FMA来进行高性能运算[12]. 处理方法就是
使用GPU的话:
# Just disables the warning, doesn't enable AVX/FMA
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
使用CPU开启AVX2的话(为了提高运算,但是没有GPU)。 [13] [14] [15] [16],需要下载Bazel,然后执行bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --config=cuda -k //tensorflow/tools/pip_package:build_pip_package
=====================================
参考文献
[1] 知乎. TensorFlow 如何入门?. https://www.zhihu.com/question/49909565. /201803221142
[2] 返回主页 1024’ Blog. TensorFlow安装与测试. [EB/OL]. https://www.cnblogs.com/mydebug/p/4972276.html. 2015-11-17 17:08/201804041112
[3] Tensoflow官网. https://www.tensorflow.org/. /201804051008
[4] Tensorflow中文社区. [WEB]. http://www.tensorfly.cn/index.html. /201804031010
[5] Udacity. https://classroom.udacity.com/courses/ud730
[6] 极客学院团队出品. TensorFlow 官方文档中文版. http://wiki.jikexueyuan.com/project/tensorflow-zh/. 更新于 2018-04-05 10:00:47/201804051002
[7] Googl制作. 机器学习速成课程 使用 TensorFlow API. https://developers.google.com/machine-learning/crash-course/. /201804051004
[8] minixuezhen的博客. 已安装python3,安装pip3 ,再安装tensorflow(for Mac). [EB/OL]. https://blog.csdn.net/minixuezhen/article/details/72887712.
2017年06月06日 21:32:13/201804051440
[9] taomiaotaomiao. 获取mnist训练数据集input_data.py. https://blog.csdn.net/taomiaotaomiao/article/details/78566775. 2017年11月18日 09:33:21/201804051710
[10] Payas Pandey. https://stackoverflow.com/questions/40877781/eoferror-compressed-file-ended-before-the-end-of-stream-marker-was-reached-mn. answered Sep 22 '17 at 20:25/201804051740
[11] gmsi. https://stackoverflow.com/questions/41962131/warningtensorflow-initialize-all-variables-from-tensorflow-python-ops-variab. answered Jan 31 '17 at 16:07/201804052102
[12] CliuGeek的博客. Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2. [EB/OL]. https://blog.csdn.net/CliuGeek/article/details/78836598. 2017年12月18日 20:09:35/201804052130
[13] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2. [EB/OL]. https://stackoverflow.com/questions/47068709/your-cpu-supports-instructions-that-this-tensorflow-binary-was-not-compiled-to-u. /201804052150
[14] How to compile Tensorflow with SSE4.2 and AVX instructions?. [EB/OL]. https://stackoverflow.com/questions/41293077/how-to-compile-tensorflow-with-sse4-2-and-avx-instructions. /201804052154
[15] Tensorflow官网. https://www.tensorflow.org/install/install_sources. /201804052209
[16] Bazel官网. https://docs.bazel.build/versions/master/install.html#mac-os-x. /201804052209