参考:Paddle Lite官方文档
参考文章:树莓派摄像头的安装、配置与验证
完成gcc、g++、opencv、cmake的安装:
sudo apt-get update
sudo apt-get install gcc g++ make wget unzip libopencv-dev pkg-config
#下载cmake
wget https://www.cmake.org/files/v3.10/cmake-3.10.3.tar.gz
在这一步如果下载很慢,这里我也提供了cmake-3.10.3.tar.gz的包,需要的可以自行下载。
#解压
tar -zxvf cmake-3.10.3.tar.gz
#进入文件夹
cd cmake-3.10.3
#环境配置
sudo ./configure
#make
sudo make
sudo make install
Paddle Lite安装和demo相同
#下载Paddle Lite
git clone https://github.com/PaddlePaddle/Paddle-Lite-Demo
#博主已经将Paddle-Lite-Demo上传到码云上,读者可以选择用博主的码云地址下载,下载速度飞快
#git clone https://gitee.com/irving_gao/Paddle-Lite-Demo.git
cd Paddle-Lite-Demo/PaddleLite-armlinux-demo
./download_models_and_libs.sh # 下载模型和预测库
进入image_classification_demo文件夹
cd Paddle-Lite-Demo/PaddleLite-armlinux-demo/image_classification_demo
TARGET_ARCH_ABI=armv8
,打开第五行的,取消第5行TARGET_ARCH_ABI=armv7hf
sudo nano run.sh
在#run代码段找到参数../images/2001.jpg
和./result.jpg
,进行自定义设置即可,此处建议设置为:
#!/bin/bash
# configure
#TARGET_ARCH_ABI=armv8 # for RK3399, set to default arch abi
TARGET_ARCH_ABI=armv7hf # for Raspberry Pi 3B
PADDLE_LITE_DIR=../Paddle-Lite
if [ "x$1" != "x" ]; then
TARGET_ARCH_ABI=$1
fi
# build
rm -rf build
mkdir build
cd build
cmake -DPADDLE_LITE_DIR=${PADDLE_LITE_DIR} -DTARGET_ARCH_ABI=${TARGET_ARCH_ABI} ..
make
#注意,这里为run代码段!!!!!!
#run
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PADDLE_LITE_DIR}/libs/${TARGET_ARCH_ABI} ./object_detection_demo ../models/model.nb ../labels/pascalvoc_label_list ../images/2001.jpg ./result.jpg
sudo ./run.sh
在终端即可看到打印出的预测结果和性能数据,在build目录中可以看到生成的result.jpg。
cd Paddle-Lite-Demo/PaddleLite-armlinux-demo/object_detection_demo
TARGET_ARCH_ABI=armv8
,打开第五行的,取消第5行TARGET_ARCH_ABI=armv7hf
sudo nano run.sh
在#run代码段找到参数../images/2001.jpg
和./result.jpg
,进行自定义设置即可,此处建议设置为:
#!/bin/bash
# configure
#TARGET_ARCH_ABI=armv8 # for RK3399, set to default arch abi
TARGET_ARCH_ABI=armv7hf # for Raspberry Pi 3B
PADDLE_LITE_DIR=../Paddle-Lite
if [ "x$1" != "x" ]; then
TARGET_ARCH_ABI=$1
fi
# build
rm -rf build
mkdir build
cd build
cmake -DPADDLE_LITE_DIR=${PADDLE_LITE_DIR} -DTARGET_ARCH_ABI=${TARGET_ARCH_ABI} ..
make
#注意,这里为run代码段!!!!!!
#run
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PADDLE_LITE_DIR}/libs/${TARGET_ARCH_ABI} ./object_detection_demo ../models/ssd_mobilenet_v1_pascalvoc_for_cpu/model.nb ../labels/pascalvoc_label_list ../images/2001.jpg ./result.jpg
cd Paddle-Lite-Demo/PaddleLite-armlinux-demo/object_detection_demo
TARGET_ARCH_ABI=armv8
,打开第五行的,取消第5行TARGET_ARCH_ABI=armv7hf
sudo nano run.sh
将run.sh中的#run
修改参数,即该文件的最后一行参数,去掉../images/2001.jpg
和./result.jpg
后缀,取消图片预测模式,即可完成对run.sh
的视频流配置。
#!/bin/bash
# configure
#TARGET_ARCH_ABI=armv8 # for RK3399, set to default arch abi
TARGET_ARCH_ABI=armv7hf # for Raspberry Pi 3B
PADDLE_LITE_DIR=../Paddle-Lite
if [ "x$1" != "x" ]; then
TARGET_ARCH_ABI=$1
fi
# build
rm -rf build
mkdir build
cd build
cmake -DPADDLE_LITE_DIR=${PADDLE_LITE_DIR} -DTARGET_ARCH_ABI=${TARGET_ARCH_ABI} ..
make
#注意,这里为run代码段!!!!!!
#run
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PADDLE_LITE_DIR}/libs/${TARGET_ARCH_ABI} ./object_detection_demo ../models/ssd_mobilenet_v1_pascalvoc_for_cpu/model.nb ../labels/pascalvoc_label_list ../images/2001.jpg ./result.jpg
修改后的#run
代码段:
#run
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${PADDLE_LITE_DIR}/libs/${TARGET_ARCH_ABI} ./object_detection_demo ../models/model.nb ../labels/pascalvoc_label_list
./run.sh armv7hf
在终端即可看到打印出来的预测结果和性能数据,并且执行后会自动弹出实时视频预测画面。
为了避免尴尬,博主机智的戴上了(帅气的)口罩(:
好啦,到这里就结束了,如果你也跟着博主做出了项目,记得点个小赞赞哦~ ^ _ ^