m1芯片Macbook安裝tensorflow


結果:運行tensorflow的官方程序

教程

  1. 下載tensorflow包,地址:https://github.com/apple/tensorflow_macos/releases
  2. 解壓下載的包,內容如下
  3. 安裝miniconda。未安裝的可以參考這篇文章:https://www.cnblogs.com/Coder-Photographer/p/14320690.html
  4. 進入命令行,激活環境
conda create --name tf24_gta_cv  # name可以隨便取
conda activate tf24_gta_cv  # 激活環境
conda install -y python==3.8.6
conda install -y pandas matplotlib scikit-learn jupyterlab
  1. 安裝,切換到解壓tensorflow包的位置
pip install --force pip==20.2.4 wheel setuptools cached-property six # 安裝依賴
## 以下名字由於版本問題可能會變,下載后根據自己下的文件調整即可
pip install --upgrade --no-dependencies --force numpy-1.18.5-cp38-cp38-macosx_11_0_arm64.whl    
pip install --upgrade --no-dependencies --force grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl
pip install --upgrade --no-dependencies --force h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl
pip install absl-py astunparse flatbuffers gast google_pasta keras_preprocessing opt_einsum protobuf tensorflow_estimator termcolor typing_extensions wrapt wheel tensorboard typeguard
pip install --upgrade --force --no-dependencies tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl
  1. 測試程序,用Google官方的教程,新建hello,tensorflow.py的文件,內容如下
# 安裝 TensorFlow

import tensorflow as tf


mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)

model.evaluate(x_test,  y_test, verbose=2)
  1. 運行
    python hello,tensorflow.py

  2. 總結
    我是一路坐下來都挺順利的,部分東西下載慢的時候可以嘗試加速器


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM