Ubuntu 24.04
Sponsored Link

TensorFlow : インストール (CPU Only)2024/06/21

 

機械学習ライブラリー, TensorFlow をインストールします。

当例では TensorFlow 2 (CPU オンリー) をインストールします。

[1]

こちらを参考に Python 3 をインストールしておきます

[2] 必要なパッケージをインストールしておきます。
root@dlp:~#
apt -y install python3-dev python3-pip gcc g++ make
[3] 任意の一般ユーザーでログインして、TensorFlow インストール用の Python 仮想環境を準備します。
ubuntu@dlp:~$
python3 -m venv --system-site-packages ~/tensorflow

ubuntu@dlp:~$
source ./tensorflow/bin/activate

(tensorflow) ubuntu@dlp:~$
[4] TensorFlow 2.9 をインストールします。
(tensorflow) ubuntu@dlp:~$
pip3 install --upgrade tensorflow-cpu==2.16.1
# run TensorFlow

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

2024-06-21 04:06:40.189271: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-06-21 04:06:40.221540: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
tf.Tensor(835.5763, shape=(), dtype=float32)

# Hello World on TensorFlow

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

2024-06-21 04:07:02.806418: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-06-21 04:07:02.838468: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
Hello, TensorFlow World
関連コンテンツ