1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Tensorflow v1.0〜 keras2〜を入れる

Last updated at Posted at 2017-04-21

関係ないですがtfって初期化遅くないですか?どうにかならないものか。
https://github.com/fchollet/keras/issues/1746

メモ書き程度だが、2点ほどエラーで引っかかった。
pip install tensorflowとnumpyのエラー。

バージョンが新しくなって過去コードはエラーになるものもある。kerasのConv2D関数など。
tensorflow:v1〜
keras:2.0.0〜

環境

ubuntu14
python2.7

cudaのバージョンを確認する

だいたいcuda7.5か8あたりを想定

nvcc -V

cudaバージョンに合わせてtensorflowを入れる

pip install tensorflow      # Python 2.7; CPU support (no GPU support)
pip3 install tensorflow     # Python 3.n; CPU support (no GPU support)
pip install tensorflow-gpu  # Python 2.7;  GPU support
pip3 install tensorflow-gpu # Python 3.n; GPU support 

これで見つからなかったので直接指定した

Tensorflow v1.0〜 keras2〜

sudo pip  install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.0-cp27-none-linux_x86_64.whl

サンプルを動かす

tf.py
import tensorflow as tf

hello = tf.constant('Hello')
sess = tf.Session()
print(sess.run(hello))

a = tf.constant(10)
b = tf.constant(32)
print(sess.run(a+b))

実行してみる

tf.py

Helloと42が返ってくる

numpyエラーが出た場合

numpyの場所を探って指定されてる場所のフォルダ名を変える。

import numpy
numpy.__file__
mv numpy numpy_old
sudo pip install numpy

で 動いた

setuptoolsでエラーが出る場合

Could not import setuptools which is required to install from a source distribution.
Please install setuptools.

一回消して入れ直すとうまくいった。

pip uninstall setuptools
pip install setuptools

kerasを入れる

インストール

git clone https://github.com/fchollet/keras.git
cd keras
sudo python setup.py install
sudo pip install keras

kerasが動くことを確認

cd examples
python mnist_mlp.py
60000/60000 [==============================] - 7s - loss: 0.2438 - acc: 0.9251 - val_loss: 0.1072 - val_acc: 0.9669
Epoch 2/20
60000/60000 [==============================] - 5s - loss: 0.1016 - acc: 0.9692 - val_loss: 0.0834 - val_acc: 0.9737
Epoch 3/20
60000/60000 [==============================] - 5s - loss: 0.0748 - acc: 0.9776 - val_loss: 0.0769 - val_acc: 0.9779
Epoch 4/20
60000/60000 [==============================] - 5s - loss: 0.0599 - acc: 0.9819 - val_loss: 0.0808 - val_acc: 0.9777
Epoch 5/20
60000/60000 [==============================] - 5s - loss: 0.0501 - acc: 0.9846 - val_loss: 0.0780 - val_acc: 0.9792
Epoch 6/20
60000/60000 [==============================] - 5s - loss: 0.0428 - acc: 0.9870 - val_loss: 0.0778 - val_acc: 0.9826
Epoch 7/20
60000/60000 [==============================] - 3s - loss: 0.0367 - acc: 0.9893 - val_loss: 0.0945 - val_acc: 0.9799
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?