數(shù)據(jù)集制作
我用手機(jī)拍了一張圖像
然后自己寫個(gè)代碼,每旋轉(zhuǎn)一度保存一張圖像,這樣就成功生成了360張圖像及其注釋文件,分為訓(xùn)練集與驗(yàn)證集。訓(xùn)練文件夾包含 320張帶有注釋的圖像。測試和驗(yàn)證文件夾都包含 40 張帶有注釋的圖像。數(shù)據(jù)集部分圖像顯示如下:
模型訓(xùn)練
準(zhǔn)備好數(shù)據(jù)集以后,直接按下面的命令行運(yùn)行即可:
yolo obb train data=pen_dataset.yaml model=yolov8s-obb.pt epochs=25 imgsz=640
導(dǎo)出與測試
模型導(dǎo)出與測試
# export model yolo export model=yolov8s-obb.pt format=onnx # inference model yoloobbpredictmodel=pen_best.ptsource=pen_rotate_test.png
部署推理
轉(zhuǎn)成ONNX格式文件以后,基于OpenVINO-Python部署推理,相關(guān)代碼如下
class_list=["pen"] colors=[(255,255,0),(0,255,0),(0,255,255),(255,0,0)] ie=Core() fordeviceinie.available_devices: print(device) #ReadIR model=ie.read_model(model="pen_best.onnx") compiled_model=ie.compile_model(model=model,device_name="CPU") output_layer=compiled_model.output(0) ##xywhr frame=cv.imread("D:/python/my_yolov8_train_demo/four_pen.jpg") bgr=format_yolov8(frame) img_h,img_w,img_c=bgr.shape start=time.time() image=cv.dnn.blobFromImage(bgr,1/255.0,(640,640),swapRB=True,crop=False) res=compiled_model([image])[output_layer]#1x25x8400 rows=np.squeeze(res,0).T boxes,confidences,angles,class_ids=post_process(rows) indexes=cv.dnn.NMSBoxes(boxes,confidences,0.25,0.45) M=np.zeros((2,3),dtype=np.float32) forindexinindexes: box=boxes[index] d1=-angles[index] color=colors[int(class_ids[index])%len(colors)] pts=[(box[0],box[1]),(box[0]+box[2],box[1]),(box[0]+box[2],box[1]+box[3]),(box[0],box[1]+box[3])] rrt_pts=get_rotate_point(pts,M,d1,box) cv.drawContours(frame,[np.asarray(rrt_pts).astype(np.int32)],0,(255,0,255),2) cv.putText(frame,class_list[class_ids[index]],(int(box[0]+box[2]/2),int(box[1]+box[3]/2)),cv.FONT_HERSHEY_SIMPLEX,1.0,(0,0,255),2) end=time.time() inf_end=end-start fps=1/inf_end fps_label="FPS:%.2f"%fps cv.putText(frame,fps_label,(20,45),cv.FONT_HERSHEY_SIMPLEX,1,(0,0,255),2) cv.imshow("YOLOv8-OBBRotateObjectDetection",frame) cv.imwrite("D:/pen_result.jpg",frame) cv.waitKey(0) cv.destroyAllWindows()
審核編輯:劉清
-
python
+關(guān)注
關(guān)注
56文章
4807瀏覽量
85041 -
數(shù)據(jù)集
+關(guān)注
關(guān)注
4文章
1209瀏覽量
24836 -
OpenVINO
+關(guān)注
關(guān)注
0文章
95瀏覽量
228
原文標(biāo)題:YOLOv8 OBB實(shí)現(xiàn)自定義旋轉(zhuǎn)對象檢測
文章出處:【微信號:CVSCHOOL,微信公眾號:OpenCV學(xué)堂】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
基于YOLOv8實(shí)現(xiàn)自定義姿態(tài)評估模型訓(xùn)練
![基于<b class='flag-5'>YOLOv8</b><b class='flag-5'>實(shí)現(xiàn)</b><b class='flag-5'>自定義</b>姿態(tài)評估模型訓(xùn)練](https://file1.elecfans.com/web2/M00/B8/CF/wKgaomWI-H2ASr8SAAAhgnugle4325.png)
使用YOLOv8做目標(biāo)檢測和實(shí)例分割的演示
YOLOv8自定義數(shù)據(jù)集訓(xùn)練到模型部署推理簡析
TensorRT 8.6 C++開發(fā)環(huán)境配置與YOLOv8實(shí)例分割推理演示
![TensorRT 8.6 C++開發(fā)環(huán)境配置與<b class='flag-5'>YOLOv8</b>實(shí)例分割推理演示](https://file1.elecfans.com/web2/M00/82/3C/wKgaomRHQBuAbc9BAAA5BtJaaeQ655.png)
在AI愛克斯開發(fā)板上用OpenVINO?加速YOLOv8目標(biāo)檢測模型
![在AI愛克斯開發(fā)板上用OpenVINO?加速<b class='flag-5'>YOLOv8</b>目標(biāo)<b class='flag-5'>檢測</b>模型](https://file1.elecfans.com/web2/M00/82/B1/wKgZomRdkeGAd8S2AAAm8DCq3H4572.png)
YOLOv8版本升級支持小目標(biāo)檢測與高分辨率圖像輸入
![<b class='flag-5'>YOLOv8</b>版本升級支持小目標(biāo)<b class='flag-5'>檢測</b>與高分辨率圖像輸入](https://file1.elecfans.com/web2/M00/82/CE/wKgZomRi9ZiAQ_8gAABAHdjYHvo467.png)
AI愛克斯開發(fā)板上使用OpenVINO加速YOLOv8目標(biāo)檢測模型
![AI愛克斯開發(fā)板上使用OpenVINO加速<b class='flag-5'>YOLOv8</b>目標(biāo)<b class='flag-5'>檢測</b>模型](https://file1.elecfans.com/web2/M00/88/B7/wKgaomRwIXSAVKmcAAAm8DCq3H4143.png)
教你如何用兩行代碼搞定YOLOv8各種模型推理
![教你如何用兩行代碼搞定<b class='flag-5'>YOLOv8</b>各種模型推理](https://file1.elecfans.com/web2/M00/8A/05/wKgZomSOf3iAf_ATAABcweWVywE605.png)
三種主流模型部署框架YOLOv8推理演示
YOLOv8+OpenCV實(shí)現(xiàn)DM碼定位檢測與解析
![<b class='flag-5'>YOLOv8</b>+OpenCV<b class='flag-5'>實(shí)現(xiàn)</b>DM碼定位<b class='flag-5'>檢測</b>與解析](https://file1.elecfans.com/web2/M00/90/01/wKgZomTUW2uAdbtqAAAg9NuNq4g524.png)
基于YOLOv8的自定義醫(yī)學(xué)圖像分割
![基于<b class='flag-5'>YOLOv8</b>的<b class='flag-5'>自定義</b>醫(yī)學(xué)圖像分割](https://file1.elecfans.com/web2/M00/B6/E6/wKgaomWCWJiAM1oBAAARpnn1nSs514.jpg)
如何基于深度學(xué)習(xí)模型訓(xùn)練實(shí)現(xiàn)圓檢測與圓心位置預(yù)測
![如何基于深度學(xué)習(xí)模型訓(xùn)練<b class='flag-5'>實(shí)現(xiàn)</b>圓<b class='flag-5'>檢測</b>與圓心位置預(yù)測](https://file1.elecfans.com/web2/M00/B7/4B/wKgaomWDqHaAD0sdAAAhk_hgLq0225.png)
YOLOv8實(shí)現(xiàn)旋轉(zhuǎn)對象檢測
![<b class='flag-5'>YOLOv8</b><b class='flag-5'>實(shí)現(xiàn)</b><b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>對象</b><b class='flag-5'>檢測</b>](https://file1.elecfans.com/web2/M00/BC/FC/wKgaomWfVjqAQnDnAABPfe5K8eA744.png)
YOLOv8+PyQT5打造細(xì)胞計(jì)數(shù)與識(shí)別應(yīng)用說明
![<b class='flag-5'>YOLOv8</b>+PyQT5打造細(xì)胞計(jì)數(shù)與識(shí)別應(yīng)用說明](https://file1.elecfans.com/web2/M00/BD/90/wKgaomWk-cOAURjwAAAlq1fPoVY684.png)
OpenCV4.8 C++實(shí)現(xiàn)YOLOv8 OBB旋轉(zhuǎn)對象檢測
![OpenCV4.8 C++<b class='flag-5'>實(shí)現(xiàn)</b><b class='flag-5'>YOLOv8</b> <b class='flag-5'>OBB</b><b class='flag-5'>旋轉(zhuǎn)</b><b class='flag-5'>對象</b><b class='flag-5'>檢測</b>](https://file1.elecfans.com/web2/M00/C0/8A/wKgZomXWrpyAA-X_AABPfe5K8eA015.png)
評論