【Ubuntu18.0.4】树莓派4B 安装 tensorflow(2.2.0)、numpy、h5py和scipy

2020-06-01 06-09-48 的屏幕截图_WPS图片.png

操做系统版本 ubuntu18.0.4
机器树莓派4Bpython

目标安装 tensorflow linux

先看下面链接文章,下载到你须要的tensorflowgit

树莓派4B安装Tensorflow(Python3.5和3.7下分别进行安装)github

11.png

12.png

下载的版本须要和你的机器操做系统python版本 三者对应ubuntu

在安装tensorflow以前,须要安装一些工具,再安装一些依赖库markdown

首先安装 工具

sudo apt-get install libhdf5-devgoogle

而后安装cython(不是cpython)lua

sudo pip install Cythonspa

和wheel

sudo pip install wheel

准备工做已经作好

temsorflow源代码下载地址

接下来能够直接
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

13.png

相关文章
相关标签/搜索