TensorFlow MNIST 問題解決
一、數據集下載錯誤
錯誤:IOError: [Errno socket error] [Errno 101] Network is unreachable
A: 手動下載:
http://yann.lecun.com/exdb/mnist/
下面的四個包
train-images-idx3-ubyte.gz: training set images (9912422 bytes)
train-labels-idx1-ubyte.gz: training set labels (28881 bytes)
t10k-images-idx3-ubyte.gz: test set images (1648877 bytes)
t10k-labels-idx1-ubyte.gz: test set labels (4542 bytes)
B: 將下載到的包拷貝到如下目錄(注意新版本已經不是之前的MNIST_data 目錄了)
cp *.gz /tmp/tensorflow/mnist/input_data/
二、不能運行
錯誤: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX0.9166
A: 零時解決辦法
mnist_softmax.py 中加入如下代碼:
在 import sys 后加入如下代碼
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
import tensorflow as tf
如果出現如下警告: 'TF_CPP_MIN_LOG_LEVEL' represents the Tensorflow environment variable responsible for logging.
則 在ubuntu 上執行如下:
export TF_CPP_MIN_LOG_LEVEL=2
B: 徹底解決此問題
(1)卸載已安裝的tensorflow
sudo pip uninstall tensorflow
(2) 用下面的命令重新編譯 tensorflow
GPU & CPU
bazel build -c opt --copt=-march=native --copt=-mfpmath=both --config=cuda -k //tensorflow/tools/pip_package:build_pip_package
僅CPU
bazel build -c opt --copt=-march=native --copt=-mfpmath=both -k //tensorflow/tools/pip_package:build_pip_package
(3)生成安裝包
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
(4) 安裝
sudo -H pip install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp27-cp27mu-linux_x86_64.whl
參考:
https://stackoverflow.com/questions/42463594/cpu-instructions-not-compiled-with-tensorflow
三、 安裝TensorFlow時出現警告
安裝命令:
sudo pip install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp27-cp27mu-linux_x86_64.whl
警告:
The directory '/home/dyufei/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
解決辦法:
用sudo -H 命令安裝:
sudo -H pip install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp27-cp27mu-linux_x86_64.whl
參考:https://stackoverflow.com/questions/33437798/osx-10-11-1-cant-install-gevent
