JavaScriptを有効にしてください

TensorflowをNehalem以前のPCへの導入する方法

 ·   3 min read

はじめに

ディープラーニングのライブラリKerasを導入した。
このとき、Kerasがバックエンドで使用するTensorflowのインストールにやや詰まったため、備忘録として手順を残す。
Nehalem以前のCPUを持つPCでは、Tensorflowのバージョンを1.5とする必要がある。

環境

サブのノートPC(2010年製)にインストールした。PythonのインストールにはAnacondaを使用している。

  • OS: Linux Mint Ver. 19
  • CPU: Intel Core 2 Duo U9400

ソフトウェアのバージョンは以下の通り。

ソフトウェア バージョン
Conda 4.5.8
Python 3.6.5
Tensorflow 1.5
Keras 2.2.4

Tensorflowのインストール

KerasのバックエンドとしてTensorflowが必要なため、まずTensorflowからインストールする。CPUが古いのでTensorflowのバージョンを1.5に落とす。ターミナルに以下を入力する。

1
$ pip install tensorflow==1.5

次にPythonを起動してTensorflowをインポートし、インストールが成功したか確認する。

1
$ python
1
2
3
4
5
6
7
8
9
>>> import  tensorflow
/home/ysd/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
2018-10-28 21:16:18.140490: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1
>>> sess = tf.Session()
>>> print(sess.run(hello))
b'Hello, TensorFlow!'

NumpyのFutureWarningが出たが、ひとまず成功した。

ちなみに、Tensorflowの最新版(v1.11)をインストールすると、pipインストール時は問題がなさそうに見えるが、Pythonでインポート時にエラーが発生してPythonが矯正終了していまう。

1
2
3
4
5
6
7
8
9
$ pip install tensorflow
(中略)
$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import  tensorflow
Illegal instruction (コアダンプ)
$

原因は、Tensorflowの1.5.1以降でAVXという命令セットを使用してコンパイルしており、これにNehalem世代以前のCPUが対応していないためらしい。

Tensorflowを1.6以上にすると、CPUによっては実行できなくなる/tensorflowのバージョン指定インストールの方法 - ‘BOKU’のITな日常
Intel AVX ‐ 通信用語の基礎知識

これを回避するため、GitからTensorflowのソースコードを落として自分でコンパイルすると、古いPCUでも最新のTensorflowを使えそうだが、本稿では扱わない。

Kerasのインストール

Kerasの最新版をインストールしても特に問題はなかった。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ pip install keras
(中略)
$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import  keras
/home/ysd/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
シェアする

Helve
WRITTEN BY
Helve
関西在住、電機メーカ勤務のエンジニア。X(旧Twitter)で新着記事を配信中です

サイト内検索