树莓派4B使用记录YOLOV5>NCNN(1)

部分相关包下载地址:
链接:https://pan.baidu.com/s/1ME-tebAsib9drdPXZavGXQ
提取码:1213
系统镜像安装:
推荐链接:https://blog.csdn.net/weixin_42108484/article/details/103806719
树莓派配置命令(若需要进行配置):

sudo raspi-config

树莓派4B部署yolov5记录:
opencv 编译安装:
修改源:

sudo vim /etc/apt/source.list 
	deb http://mirrors.tuna.tsinghua.edu.cn/raspberry-pi-os/raspbian/ buster main non-free contrib rpi
sudo vim /etc/apt/sources.list.d/raspi.list
	deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui

更新:

sudo apt-get update
sudo apt-get upgrade

opencv 第三方库:

sudo apt-get install build-essential cmake git pkg-config
sudo apt-get install libjpeg8-dev 
sudo apt-get install libtiff5-dev 
sudo apt-get install libjasper-dev
sudo apt-get install libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libdc1394-22-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libgtk-3-dev
sudo apt-get install libavresample-dev
sudo apt-get install libgphoto2-dev
sudo apt-get install libopenblas-dev
sudo apt-get install libopencv-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install libgstreamer-plugins-base1.0-dev

opencv 下载:
github下载:wget -O opencv-3.4.1.zip https://github.com/Itseez/opencv/archive/3.4.1.zip
前往官网下载:https://opencv.org/releases/
opencv 安装:

unzip opencv-3.4.1.zip
cd opencv-3.4.1
mkdir release
cd release

到这里就可以进行cmake指令了,但是为了后面编译不会出错,这里先把问题解决掉,执行下面指令,防止编译找不到头文件。

sudo ln -s /usr/include/libv4l1-videodev.h   /usr/include/linux/videodev.h
sudo cp /usr/include/opencv2/videoio/videoio_c.h  /usr/include/arm-linux-gnueabihf/sys
sudo ln -s /usr/include/arm-linux-gnueabihf/sys/videoio_c.h  /usr/include/arm-linux-gnueabihf/sys/videoio.h
vim opencv-3.4.1/modules/python/src2/cv2.cpp

打开文件后找到第885行附近做出如下修改

char* str=PyString_AsString(obj);前加上(char *),改为char* str=(char*)PyString_AsString(obj);

在这里插入图片描述

CMAKE:

sudo cmake -DCMAKE_BUILD_TYPE=RELEASE -DWITH_FFMPEG=ON  -DWITH_LIBV4L=ON -DENABLE_PRECOMPILED_HEADERS=OFF  -DCMAKE_INSTALL_PREFIX=/usr/local ..

树莓派4B使用记录YOLOV5>NCNN(1)_第1张图片
编译:

sudo make
sudo make install
sudo ldconfig

yolov5:

git clone https://github.com/ultralytics/yolov5

选择版本

git clone -b v3.1 https://github.com/ultralytics/yolov5.git

进入 requirements.txt 注释掉部分package:

sudo vim requirements.txt

树莓派4B使用记录YOLOV5>NCNN(1)_第2张图片

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt install libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools
sudo apt-get install libavutil-dev libavcodec-dev libavformat-dev libswscale-dev

torch 以及 torchvision 的安装:python3.7可以使用下载链接安装(免去编译过程):https://pan.baidu.com/s/11DUazcQep7g9fB5xyq7DVw 提取码:1213
PT>onnx:

pip install onnx onnxsimplifier

转onnx 之前先进入common.py 修改focus层的切片操作 (NCNN不支持切片,足够厉害可以自己写切片操作实现)
在这里插入图片描述

python models/export.py --weights 自己训练的权重 --images-size 图片大小 batch-size 批次大小

简化:

python -m onnxsim onnx权重 生成的onnx权重

NCNN的编译:

sudo apt-get install autoconf automake libtool curl make g++ unzip
git clone https://github.com/Tencent/ncnn.git
cd ncnn
mkdir -p build 
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/pi3.toolchain.cmake -DPI3=ON ..
make 

ONNX>>NCNN:

cd ncnn/tools/onnx
./onnx2ncnn 简化的onnx权重 生成的param 生成的bin

无任何报错以及unsupport step! 表示成功
测试:
树莓派4B使用记录YOLOV5>NCNN(1)_第3张图片
参考链接:https://my.oschina.net/u/3337401/blog/4708237

你可能感兴趣的:(部署,pytorch,边缘计算)