树莓派4B_tensorflow


树莓派4B_tensorflow

安装python virtualenv

  • 远程ssh登陆操作

ping raspberrypi.local

  • 获取树莓派的内网ip,我的是 192.168.1.6,ssh登陆并输入密码:

ssh pi@192.168.1.6

  • 安装Python

python --version

# 安装venv
$ sudo pip3 install virtualenv virtualenvwrapper

# (可选)为了尽快下载,可以用国内镜像下载
$ sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualenv virtualenvwrapper 


# 查看版本
$ virtualenv --version
16.7.7


# 新建测试目录
$ mkdir venvtest && cd venvtest

# 安装python的隔离环境,python相关目录放在ENV文件夹
$ virtualenv ENV
Using base prefix '/usr'
New python executable in /home/pi/venvtest/ENV/bin/python3
Also creating executable in /home/pi/venvtest/ENV/bin/python
Installing setuptools, pip, wheel...
done.

安装TensorFlow Lite

从github下载pi4b_tensorflow_lite

git clone https://github.com/whgreate/pi4b_tensorflow_lite
# 安装tensorflow lite
$ pip install tflite_runtime-1.14.0-cp37-cp37m-linux_armv7l.whl 

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Processing ./tflite_runtime-1.14.0-cp37-cp37m-linux_armv7l.whl
Installing collected packages: tflite-runtime
Successfully installed tflite-runtime-1.14.0

# numpy pillow库需要的一些依赖
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install libjpeg-dev

# 安装 numpy pillow
$ pip install -r requirements.txt

进行测试

运行图像分类模型
选取TensorFlow Example的图片,执行以下命令:

python label_image.py -m mobilenet_v1_1.0_224_quant.tflite -l labels_mobilenet_quant_v1_224.txt -i grace_hopper.bmp


INFO: Initialized TensorFlow Lite runtime.
0.658824: military uniform
0.149020: Windsor tie
0.039216: bow tie
0.027451: mortarboard
0.019608: bulletproof vest

用摄像头拍摄一张照片进行测试:
raspistill -o demo.jpg


python label_image.py -m mobilenet_v1_1.0_224_quant.tflite -l labels_mobilenet_quant_v1_224.txt -i demo.jpg


0.266667: barbershop
0.098039: potter's wheel
0.050980: laptop
0.043137: barber chair
0.043137: shoe shop


文章作者: 万鲲鹏
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 万鲲鹏 !
评论
  目录