python3. + keras + TensorFlow install

Tensorflow + keras

TensorFlow

anaconda3-4.0.0が入ってる状態で,以下で新作業環境を作る.

% conda create -n {env name} python=3.5 anaconda

作業用ディレクトリを作って,その中で今作った環境を
pyenv localに設定する.

% pyenv local {env name}
% conda update anaconda

pyenv versionsでうまくいってるか確認.

以下を実行.

% sudo easy_install --upgrade six
% pip install --upgrade pip

以下のPATHをzshrcなりに通す.

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0rc0-py3-none-any.whl

以下でTensorFlowをpip install

% sudo pip3 install --upgrade $TF_BINARY_URL
% python
Python 3.5.1 |Anaconda 4.0.0 (x86_64)| (default, Dec  7 2015, 11:24:55)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>>

成功.

keras

以下を実行.

% sudo pip3 install keras

なんとこれだけ

% python
Python 3.5.1 |Anaconda 4.0.0 (x86_64)| (default, Dec  7 2015, 11:24:55)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using Theano backend.
>>>

バックエンドにTensorFlowをしてやる

% vim ~/.keras/keras.json
{
    "backend": "theano",
    "floatx": "float32",
    "image_dim_ordering": "th",
    "epsilon": 1e-07
}

これを

{
    "backend": "tensorflow",
    "floatx": "float32",
    "image_dim_ordering": "th",
    "epsilon": 1e-07
}

こうするだけ

すると

% python
Python 3.5.1 |Anaconda 4.0.0 (x86_64)| (default, Dec  7 2015, 11:24:55)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
Using TensorFlow backend.
>>>

なるほど.

Go Top