操做系統版本 ubuntu18.0.4
機器樹莓派4Bpython
目標安裝 tensorflow linux
先看下面鏈接文章,下載到你須要的tensorflowgit
樹莓派4B安裝Tensorflow(Python3.5和3.7下分別進行安裝)github
下載的版本須要和你的機器、操做系統和python版本 三者對應ubuntu
在安裝tensorflow以前,須要安裝一些工具,再安裝一些依賴庫markdown
首先安裝 工具
sudo apt-get install libhdf5-dev
google
而後安裝cython(不是cpython)lua
sudo pip install Cython
spa
和wheel
sudo pip install wheel
準備工做已經作好
接下來能夠直接sudo pip install tensorflow-2.2.0-cp37-none-linux_aarch64.whl
pip會自動解決tensorflow的依賴庫,可是其中scipy和h5py會比較緩慢
keras-preprocessing, gast, absl-py, grpcio, h5py, opt-einsum, tensorflow-estimator, termcolor, protobuf, tensorboard-plugin-wit, wheel, pyasn1, rsa, cachetools, pyasn1-modules, google-auth, oauthlib, requests-oauthlib, google-auth-oauthlib, zipp, importlib-metadata, markdown, werkzeug, tensorboard, wrapt, astunparse, google-pasta, tensorflow
這些是sudo pip install tensorflow-2.2.0-cp37-none-linux_aarch64.whl命令運行的時候檢查並安裝的依賴庫,
若是安裝的時候卡住,退出手動安裝一下
sudo pip install xxxx
安裝完成後
運行下面代碼
import tensorflow as tf print(tf.__version__) 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)
若是輸出正常,說明tensorflow基本功能已經ok