LoginSignup
12
10

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-06-29

CentOSにて、とりあえずTensorFlowの動作を確認出来る所までを記載します。

前提

  • CentOS7
  • Anaconda

手順

Anaconda環境準備

CentOS7にAnacondaの環境構築の手順で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
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
12
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10