2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

appleがmac用tensorflowを出したようなのでintelのMacBookairにインストールしてみる

Last updated at Posted at 2020-11-21

mac用tensorflowのインストール

MacBook Air (Retina, 13-inch, 2019) macOS Big Surに下記を入れる
https://github.com/apple/tensorflow_macos

pyenv-virtualenvをメインで利用しているのでpyenv-verturalenvで使えるといいなぁ。。。

brewのupdateとpyenvのupdate

python 3.8が必要だと言われたのでpyenv 1.2.11をバージョンアップするため、brewのupdateから実施。

$ brew update
$ brew upgrade pyenv

更新をサボっていたので、いろいろなモジュールのアップデートが走る。。。
OSもBig Surになったので、いろいろbottleが変わっている模様。

pyenvのupgrade中、CLT(CommandLineTools)のバージョン不整合が起きている様なので、
下記記事にしたがってCLTの最新版をインストール。
https://qiita.com/gesutaka/items/fe34bd5de524a20b2b0a
最新版を入れてbrew doctorをしてbrew upgrade pyenvをやり直し
成功。
pyenvが1.2.21になった。

python 3.8.6が最新なので、せっかくなので最新版を入れる

$ pyenv install 3.8.6
$ pyenv virtualenv 3.8.6 mac-tensorflow
$ pyenv local mac-tensorflow

tensorflowのインストール

いよいよtensorflowのインストール。
To quickly try this out, copy and paste the following into Terminal:のところをそのまま実行。。。
すると

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)"

下記のように言うので、virtualenvであることは気づいている模様。

This script will download tensorflow_macos 0.1alpha0 and needed binary dependencies, then install them into a new 
or existing Python 3.8 virtual enviornoment.

下記のようにインストール先を聞かれるので、ちゃんと現在の環境を答える。
※答えないと、python3.8でないと怒られてインストールできない。

Path to new or existing virtual environment [default: /Users/notfolder/tensorflow_macos_venv/]: /Users/notfolder/.pyenv/versions/3.8.6/envs/mac-tensorflow/

インストール先がここでいいか、numpy等を入れるが良いか聞かれるのでよしと答える。

./install_venv.sh will perform the following operations:
-> Install tensorflow_macos 0.1a0 into existing virtual environment /Users/notfolder/.pyenv/versions/3.8.6/envs/mac-tensorflow.
-> Install bundled binary wheels for numpy-1.18.5, grpcio-1.33.2, h5py-2.10.0, scipy-1.5.4, tensorflow_addons-0.11.2+mlcompute into /Users/notfolder/.pyenv/versions/3.8.6/envs/mac-tensorflow.

Confirm [y/N]? y

どうやらインストールできた模様。
kerasを入れてチュートリアルのmnist.pyを実行する。

$ pip install keras
$ python mnist.py
2020-11-22 02:11:55.450120: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2020-11-22 02:11:55.869523: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
Epoch 1/20
469/469 [==============================] - 3s 5ms/step - loss: 0.9553 - accuracy: 0.7579 - val_loss: 0.3419 - val_accuracy: 0.9084
Epoch 2/20
469/469 [==============================] - 1s 2ms/step - loss: 0.3416 - accuracy: 0.9040 - val_loss: 0.2999 - val_accuracy: 0.9159
Epoch 3/20
469/469 [==============================] - 1s 2ms/step - loss: 0.3053 - accuracy: 0.9145 - val_loss: 0.2850 - val_accuracy: 0.9211
Epoch 4/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2905 - accuracy: 0.9180 - val_loss: 0.2793 - val_accuracy: 0.9235
Epoch 5/20
469/469 [==============================] - 1s 3ms/step - loss: 0.2809 - accuracy: 0.9213 - val_loss: 0.2752 - val_accuracy: 0.9244
Epoch 6/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2739 - accuracy: 0.9240 - val_loss: 0.2726 - val_accuracy: 0.9245
Epoch 7/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2753 - accuracy: 0.9226 - val_loss: 0.2726 - val_accuracy: 0.9246
Epoch 8/20
469/469 [==============================] - 1s 3ms/step - loss: 0.2673 - accuracy: 0.9265 - val_loss: 0.2715 - val_accuracy: 0.9250
Epoch 9/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2677 - accuracy: 0.9264 - val_loss: 0.2683 - val_accuracy: 0.9273
Epoch 10/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2592 - accuracy: 0.9285 - val_loss: 0.2661 - val_accuracy: 0.9267
Epoch 11/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2579 - accuracy: 0.9303 - val_loss: 0.2718 - val_accuracy: 0.9268
Epoch 12/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2572 - accuracy: 0.9298 - val_loss: 0.2683 - val_accuracy: 0.9265
Epoch 13/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2588 - accuracy: 0.9304 - val_loss: 0.2698 - val_accuracy: 0.9256
Epoch 14/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2482 - accuracy: 0.9317 - val_loss: 0.2684 - val_accuracy: 0.9267
Epoch 15/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2556 - accuracy: 0.9301 - val_loss: 0.2673 - val_accuracy: 0.9261
Epoch 16/20
469/469 [==============================] - 1s 3ms/step - loss: 0.2554 - accuracy: 0.9314 - val_loss: 0.2667 - val_accuracy: 0.9270
Epoch 17/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2509 - accuracy: 0.9319 - val_loss: 0.2693 - val_accuracy: 0.9261
Epoch 18/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2550 - accuracy: 0.9317 - val_loss: 0.2714 - val_accuracy: 0.9273
Epoch 19/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2519 - accuracy: 0.9329 - val_loss: 0.2689 - val_accuracy: 0.9285
Epoch 20/20
469/469 [==============================] - 1s 2ms/step - loss: 0.2506 - accuracy: 0.9333 - val_loss: 0.2710 - val_accuracy: 0.9267
313/313 [==============================] - 0s 1ms/step - loss: 0.2710 - accuracy: 0.9267

...CPUのまんまかーい!!
いや、もともと7秒暗いかかってたから、7倍早いけども。。。
メインは新しいM1用のtensorflowみたいなので、しょうがないか。。。
新しいMacbook air買いたいな。。。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?