CentOS 8
Sponsored Link

TensorFlow : インストール2020/07/23

 
機械学習ライブラリー, TensorFlow をインストールします。
当例では TensorFlow 2.0 をインストールします。
[1]
[2] 必要なパッケージをインストールしておきます。
[root@dlp ~]#
dnf -y install python36-devel python3-virtualenv gcc gcc-c++ make
[3] 任意の一般ユーザーでログインして、TensorFlow インストール用の Python 仮想環境を準備します。
TensorFlow をシステムワイドにインストールする場合は、当作業は不要で、root ユーザーで [4] を実行すれば OK です。
[cent@dlp ~]$
virtualenv --system-site-packages -p python3 ./venv

Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/cent/venv/bin/python3
Also creating executable in /home/cent/venv/bin/python
Installing setuptools, pip, wheel...done.

[cent@dlp ~]$
source ./venv/bin/activate

(venv) [cent@dlp ~]$
[4] TensorFlow 2.0 をインストールします。
(venv) [cent@dlp ~]$
pip3 install --upgrade tensorflow==2.0.0b1
# numpy バージョン確認

(venv) [cent@dlp ~]$
pip3 show numpy
Name: numpy
Version: 1.19.1
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: /home/cent/venv/lib/python3.6/site-packages
Requires:
Required-by: tensorflow, tb-nightly, Keras-Preprocessing, Keras-Applications, h5py

# TensorFlow 2.0 で numpy が 1.17 以上では 実行時に

# Warning が大量に出力されるため 1.16 にダウングレード

(venv) [cent@dlp ~]$
pip3 install --upgrade numpy==1.16.0

(venv) [cent@dlp ~]$
pip3 show numpy

Name: numpy
Version: 1.16.0
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: /home/cent/venv/lib/python3.6/site-packages
Requires:
Required-by: tensorflow, tb-nightly, Keras-Preprocessing, Keras-Applications, h5py

# TensorFlow 実行

(venv) [cent@dlp ~]$
python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

2020-07-22 21:16:17.047533: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2801355000 Hz
2020-07-22 21:16:17.048084: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5633e28df970 executing computations on platform Host. Devices:
2020-07-22 21:16:17.048148: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
tf.Tensor(545.2815, shape=(), dtype=float32)

# TensorFlow で Hello World

(venv) [cent@dlp ~]$
python3 -c "import tensorflow as tf; hello = tf.constant('Hello, TensorFlow World'); tf.print(hello)"

2020-07-22 21:17:51.815296: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2801355000 Hz
2020-07-22 21:17:51.815812: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5633f4d64910 executing computations on platform Host. Devices:
2020-07-22 21:17:51.815899: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
Hello, TensorFlow World
関連コンテンツ