見出し画像

[自分用メモ] MacBook Pro (M1, 2020) deep learning 遊ぶための設定

まずはなんとなく Homebrew をインストールしてみてました

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”

password を求められたりパスを通したりして諸々進める

ところがこれを確認すると、Tensorflow に対応していないみたいだったので、brew の Python をアンインストール

brew uninstall --ignore-dependencies python3

MiniForge を入れるのが良いということで、インストール。じゃないと Tensorflow 使えない

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
bash Miniforge3-MacOSX-arm64.sh

Python3.8 環境を構築

conda create --name dlplaying python=3.8

必要なライブラリをインストール

conda install numpy
conda install six
conda install matplotlib
conda install opencv
wget https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha2/tensorflow_macos-0.1alpha2.tar.gz
tar xvzf tensorflow_macos-0.1alpha2.tar.gz
env="$HOME/miniforge3/envs/python38"
libs="$PWD/tensorflow_macos/arm64/"
pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl"
pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl"
pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/tensorflow_addons_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl"
conda install -c conda-forge -y absl-py
conda install -c conda-forge -y astunparse
conda install -c conda-forge -y gast
conda install -c conda-forge -y opt_einsum
conda install -c conda-forge -y termcolor
conda install -c conda-forge -y typing_extensions
conda install -c conda-forge -y wheel
conda install -c conda-forge -y typeguard
pip install wrapt flatbuffers tensorflow_estimator google_pasta keras_preprocessing protobuf
pip install tensorboard
pip install --upgrade -t "$env/lib/python3.8/site-packages/" --no-dependencies --force "$libs/tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl"
Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:14) 
[Clang 12.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.__version__
'2.8.1'
>>> 

import できているっぽい

PyTorch もインストールしておくかということで確認

pip install でできるらしい

pip install torch
pip install torchvision
pip install torchaudio
Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:14) 
[Clang 12.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'1.8.0a0+71ca600'

できてるっぽい

先ほどのこちらの記事での「Object Detection APIによる物体検出」を試してみました

初回実行時は `zsh  bus error` 的なメッセージで動作しなかったのですが、この note 書いている時には無事動きました

スクショのみ

前述のエラーは結局、原因解明できず…下記を参考に動かしました

ちなみに openpose も動かせました

上記記事にあるように GitHub にある動画の推論は上手くいかないので、こちらの記事にあるコードを拝借しました。ありがとうございました

今は簡単な web app を flask 使ってやってみてるので、何か詰まったこととかあればまた備忘録書きます

この記事が気に入ったらサポートをしてみませんか?