Tensorflow

安装

使用清华大学的镜像安装,地址在这里。可以自己选择计算单元、操作系统、版本等。

使用生成的pip命令进行安装,需要加上sudo

MNIST机器学习

文档在这里:MNIST机器学习入门
跟着一步步走就行了。

数据集

文档里提供了数据集下载和安装的python代码,但使用代码下载速度太慢,建议使用下载软件下载,然后不解压直接复制到MNIST_data目录下即可。

关于initialize_all_variables的WARNING

运行程序之后,会出现一个WARNING,意思是原文档中使用的initialize_all_variables已经过时了,改为global_variables_initializer即可。

1
2
3
WARNING:tensorflow:From mnist.py:13: 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.

CPU加速提示

使用的是pip安装,所以会出以下的提示:

1
2
3
: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't 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 wasn't 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 wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.

这里是表示如果使用源码编译性能会有所提升,不想看到这些提示的话有两种办法:一是卸载后直接改为源码编译;二是添加以下代码:

1
2
3
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf

TF_CPP_MIN_LOG_LEVEL这个环境变量与TensorFlow的log有关,1代表INFO,2为Warning,3为Error。