代碼地址
使用OpenCV 4.5.4推理YOLOv5模型,分別使用C++,Python和ROS實現(xiàn)。
基于yolov5-opencv-cpp-python修改。
在原代碼的基礎(chǔ)上使用CMake編譯(能夠更方便的定義程序路徑),并且加入了對ROS傳入圖片的支持。
環(huán)境配置NOTE: The code depends on the output dimension of your network model, which means the variables dimensions and rows in ros.cpp should be the exact same size of output dimensions.
注意: 網(wǎng)絡(luò)推理的計算取決于網(wǎng)絡(luò)模型的輸出維度, 也就是說ros.cpp中的變量dimensions and rows應(yīng)該與其一致.
注意!!! 先于4.5.4的OpenCV版本不會正常運(yùn)行。
使用ROS/C++推理C++/ROS代碼在Yolo_ROS/ros.cpp。
git clone https://github.com/YellowAndGreen/Yolov5-OpenCV-Cpp-Python-ROS.git
cd Yolov5-OpenCV-Cpp-Python-ROS/Yolo_ROS
mkdir build && cd build
cmake ../
make
./yolo_ros
使用python推理Python代碼在python/yolo.py.
git clone https://github.com/YellowAndGreen/Yolov5-OpenCV-Cpp-Python-ROS.git
cd Yolov5-OpenCV-Cpp-Python-ROS
python python/yolo.py
使用GPU運(yùn)行:
git clone https://github.com/YellowAndGreen/Yolov5-OpenCV-Cpp-Python-ROS.git
cd Yolov5-OpenCV-Cpp-Python-ROS
python python/yolo.py cuda
python python/yolo-tiny.py cuda
使用C++推理C++代碼在cpp/yolo.cpp.
git clone https://github.com/YellowAndGreen/Yolov5-OpenCV-Cpp-Python-ROS.git
cd Yolov5-OpenCV-Cpp-Python-ROS/cpp
mkdir build && cd build
cmake ../
make
./yolo_example
導(dǎo)出Yolov5 模型到onnx格式https://github.com/ultralytics/yolov5/issues/251
我的指令是:
git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt
然后轉(zhuǎn)換模型:
$ python3 export.py --weights yolov5n.pt --img 640 --include onnx
export: data=data/coco128.yaml, weights=['yolov5n.pt'], imgsz=[640], batch_size=1, device=cpu, half=False, inplace=False, train=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx']
YOLOv5 🚀 v6.0-192-g436ffc4 torch 1.10.1+cu102 CPU
Fusing layers...
Model Summary: 213 layers, 1867405 parameters, 0 gradients
PyTorch: starting from yolov5n.pt (4.0 MB)
ONNX: starting export with onnx 1.10.2...
/home/user/workspace/smartcam/yolov5/models/yolo.py:57: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
if self.onnx_dynamic or self.grid[i].shape[2:4] != x[i].shape[2:4]:
ONNX: export success, saved as yolov5n.onnx (7.9 MB)
Export complete (1.33s)
Results saved to /home/doleron/workspace/smartcam/yolov5
Visualize with https://netron.app
Detect with `python detect.py --weights yolov5n.onnx` or `model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5n.onnx')
Validate with `python val.py --weights yolov5n.onnx`
$
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
文章名稱:Yolov5分別使用Cpp,Python,ROS部署-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://www.rwnh.cn/article6/doeoog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、用戶體驗、外貿(mào)建站、企業(yè)建站、營銷型網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)