1、安装miniconda 或者 Anaconda3
bash ~/miniconda.sh -b -p $HOME/miniconda
source ~/miniconda/bin/activate
conda install -c apple tensorflow-deps
#Anaconda3 自己百度安装,都行
2、配置 miniconda 环境变量 ,在~/.zshrc 文件中添加如下代码
source ~/miniconda/bin/activate
3、安装 TensorFlow
python -m pip install tensorflow-macos
4、按照 tensorflow-metal plug-in
python -m pip install tensorflow-metal
5、验证 python 跑下面的python 代码
import tensorflow as tf
cifar = tf.keras.datasets.cifar100
(x_train, y_train), (x_test, y_test) = cifar.load_data()
model = tf.keras.applications.ResNet50(
include_top=True,
weights=None,
input_shape=(32, 32, 3),
classes=100,)
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer="adam", loss=loss_fn, metrics=["accuracy"])
model.fit(x_train, y_train, epochs=5, batch_size=64)
打开 活动监视器 -> 窗口 -> GPU历史窗口, 看看有红色代表使用了GPU