London学生の技術日記

ロンドン、学生、ブログ。

Google Tensor Flow インストールしてみた

GoogleのTensorFlow インストールしてみた。

https://youtu.be/oZikw5k_2FM

 

紹介ページIntroductionにはざっくり線形回帰のコードが載ってます。

TensorFlow does not actually run any computation until the session is created and the run function is called. セッションつくってrunを呼ばないと実際に計算しない、とかなんとか。

 

で、MNISTを使った解説が続いてて、Biginner なら青、詳しいなら赤をクリックして進め、絶対使うなら端折ってもいいよ、的なことがかいてあるので、端折る。

 

で行きつく先はDownloadとSetup

https://www.tensorflow.org/versions/r0.8/get_started/os_setup.html

 ぼくはLinux, Ubuntu Anaconda python=2.7でインストールしてるので、

ターミナルでから

$ conda create -n tensorflow python=2.7

 

からの、太字のとこをやる。

$ source activate tensorflow
(tensorflow)$  # Your prompt should change

# Ubuntu/Linux 64-bit, CPU only:
(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled. Requires CUDA toolkit 7.5 and CuDNN v4.  For
# other versions, see "Install from sources" below.
(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

# Mac OS X, CPU only:
(tensorflow)$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl

 

残念なことにGPUもってないんですよね。だれか買ってくれ。

 

で、jupyter でDemoをしてみた。

In [3]:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a + b))
 
Hello, TensorFlow!
42

どうかね。できたっぽくね?

 

 で、Convolutional NNもためす。

 

下記みたいなアウトプットが出る。ちなみにめっちゃ遅い。()

 

 $ python convolutional.py
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
Initialized!
Step 0 (epoch 0.00), 16.7 ms
Minibatch loss: 12.053, learning rate: 0.010000
Minibatch error: 90.6%
Validation error: 84.6%
Step 100 (epoch 0.12), 816.4 ms
Minibatch loss: 3.283, learning rate: 0.010000

 

 

ーーーーーーーーーーーーーーーーーー

こんな感じ。みんなもやってみそ。