Tensorflow・Keras:インストール

基本的には上記を参考に進めていきます。

ただし、TF(tensorflow)のインストールのとき、対象ファイルは当然下記を参照し、環境に合わせて変える必要があります。

import tensorflow as tf 実行時のエラー

ただし、書いてある通り進めてもimport tensorflowで下記のエラーが出てしまいました。

[code lang=”python” title=””]

import tensorflow as tf

#ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in [‘/root/.pyenv/versions/anaconda3-2018.12/envs/py36/lib/python3.6/site-packages/numpy’]. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.

[/code]

numpyのバージョンの問題の様ですが、numpyだけをバージョンアップしてもダメなようでした。

一度tensorflowをアンイトンスールしました。

tensorflowアンイトンスール

[code lang=”python” title=””]

pip uninstall tensorflow

[/code]

どうやら、anaconda環境下でpipを使うのは良くないようです

 
よって仮想環境内向にて、下記サイトを参考にして進めていきます。

condaアップデート

[code lang=”python” title=””]

conda update -n base conda

[/code]

tensorflowインストール

[code lang=”python” title=””]

conda install tensorflow

[/code]

[code lang=”python” title=””]

>>>import tensorflow as tf
>>>hello = tf.constant(‘Hello, TensorFlow!’)
>>>sess = tf.Session()
>>>print(sess.run(hello))

 
#helloと表示されれば成功です!

[/code]

実行時のメッセージ

[code lang=”python” title=””]

#I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX

#I tensorflow/core/common_runtime/process_util.cc:69] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.

#helloの前に上記のメッセージが表示されると思いますが、エラーではなく、こうすると処理速度が速くなります、ということらしいです。
[/code]

kerasインストール

[code lang=”python” title=””]

conda install keras

[/code]

kerasインストールの確認

[code lang=”python” title=””]
>>> import keras

>>> print(keras.__version__)

#バージョンが帰ってくれば成功です

[/code]

その他

仮想環境の削除

[code lang=”python” title=””]

conda remove -n 仮想環境名 –all

[/code]

pipアップデート

[code lang=”python” title=””]

pip install –upgrade pip

[/code]

未分類

Posted by iser