Last active
March 11, 2023 16:25
-
-
Save kreyssel/27dd80dffb233095c42ba4b894b53b95 to your computer and use it in GitHub Desktop.
Install Tensorflow on M1 Mac with Python 3.10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# a fixed installatioon script for https://developer.apple.com/metal/tensorflow-plugin/ | |
# | |
bash ~/miniconda.sh -b -p $HOME/miniconda | |
source ~/miniconda/bin/activate | |
conda deactivate | |
conda create --name tf310 python=3.10 | |
conda activate tf310 | |
# look for the newest tensorflow-macos 2.10 at https://pypi.org/project/tensorflow-macos/#history | |
python -m pip install tensorflow-macos==2.10.0 | |
# look for the newest tensorflow-metal 0.6 at https://pypi.org/project/tensorflow-metal/#history | |
python -m pip install tensorflow-metal==0.6.0 | |
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))" | |
# then run test_installation.py script - copy test_installation.py below to local directory | |
python test_installation.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment