TensorFlowをインストールし、MNIST for Beginnersを試す

f:id:daisuke-jp:20160819003912j:plain
CentOSの環境で、TensorFlowの動作を確認出来る所までを記載します。

前提

  • CentOS7
  • Anaconda

手順

Anaconda環境準備

CentOSにAnacondaをインストールしてデータサイエンスに踏み込んでみる

TensorFlow用仮想環境準備

conda create -n tensorflow python=3.5
source activate tensorflow

TensorFlowインストール

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0rc0-cp35-cp35m-linux_x86_64.whl

なお、使っている環境によってtensorflowの種類は書き換えましょう。TensorFlow参照

easy_install --upgrade six
pip install --upgrade $TF_BINARY_URL

TensorFlowにはPython3.5の場合はpip3を使うようになっていますが、今回のインストール方法ではpipで良いです。

Successfullyが出た事を確認しましょう

テストドライブ

$ python
...
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>>

テストドライブ参考

GitHubからClone

cd /usr/local/src/
mkdir ./tensorflow
git clone --recurse-submodules https://github.com/tensorflow/tensorflow ./tensorflow
cd ./tensorflow/
vi ./tensorflow/examples/tutorials/mnist/fully_connected_feed.py
# from tensorflow.examples.tutorials.mnist import input_data
# from tensorflow.examples.tutorials.mnist import mnist
import input_data
import mnist

fully_connected_feed.pyを実行

source activate tensorflow
python ./tensorflow/examples/tutorials/mnist/fully_connected_feed.py

実行結果に

Training Data Eval:
  Num examples: 55000  Num correct: 49327  Precision @ 1: 0.8969
Validation Data Eval:
  Num examples: 5000  Num correct: 4531  Precision @ 1: 0.9062
Test Data Eval:
  Num examples: 10000  Num correct: 9035  Precision @ 1: 0.9035

みたいに表示される。

TensorBoard起動

tensorboard --logdir=/usr/local/src/tensorflow/data

実行結果

Starting TensorBoard  on port 6006
(You can navigate to http://0.0.0.0:6006)

TensorBoardにて結果確認

ブラウザで http://IPaddress:6006 にアクセス クロスエントロピーやニューラルネットワークを見る事が出来れば、とりあえず動作完了です。

備考

  • TensorFlowを使わない時
source deactivate
  • TensorFlowを使う時
source activate tensorflow

このブログの人気の投稿

AnacondaとPythonのインストール(python2とpython3の共存)とDjango

PyCharmでAnaconda(Python)とDjangoの開発環境を構築する  その2

PyCharmでAnaconda(Python)とDjangoの開発環境を構築する  その1