TensorFlow : インストール2021/04/14 |
機械学習ライブラリー, TensorFlow をインストールします。
当例では TensorFlow 2 (CPU オンリー) をインストールします。
|
|
[1] | |
[2] | 必要なパッケージをインストールしておきます。 |
[root@dlp ~]# dnf -y install python38-devel gcc gcc-c++ make
|
[3] | 任意の一般ユーザーでログインして、TensorFlow インストール用の Python 仮想環境を準備します。 TensorFlow をシステムワイドにインストールする場合は、当作業は不要で、root ユーザーで [4] を実行すれば OK です。 |
[cent@dlp ~]$ pip3 install --upgrade virtualenv --user Collecting virtualenv Downloading https://files.pythonhosted.org/packages/91/fb/ca6c071f4231e06a9f0c3bd81c15c233bbacd4a7d9dbb7438d95fece8a1e/virtualenv-20.4.3-py2.py3-none-any.whl (7.2MB) ..... .....[cent@dlp ~]$ virtualenv --system-site-packages -p python3 ./venv created virtual environment CPython3.8.6.final.0-64 in 326ms creator CPython3Posix(dest=/home/redhat/venv, clear=False, no_vcs_ignore=False, global=True) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/redhat/.local/share/virtualenv) added seed packages: pip==21.0.1, setuptools==54.1.2, wheel==0.36.2 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator[cent@dlp ~]$ source ./venv/bin/activate (venv) [cent@dlp ~]$ |
[4] | TensorFlow 2.2 をインストールします。 |
(venv) [cent@dlp ~]$
pip3 install --upgrade tensorflow-cpu==2.2
# TensorFlow 実行 (venv) [cent@dlp ~]$ python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))" 2021-04-13 19:11:49.602683: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2021-04-13 19:11:49.612976: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2593990000 Hz 2021-04-13 19:11:49.615331: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x562020232300 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2021-04-13 19:11:49.615391: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version tf.Tensor(360.39587, shape=(), dtype=float32) # TensorFlow で Hello World (venv) [cent@dlp ~]$ python3 -c "import tensorflow as tf; hello = tf.constant('Hello, TensorFlow World'); tf.print(hello)" 2021-04-13 19:12:37.181153: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2021-04-13 19:12:37.189207: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2593990000 Hz 2021-04-13 19:12:37.191854: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55c24453b570 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2021-04-13 19:12:37.194723: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version Hello, TensorFlow World |
Sponsored Link |