在我之前的一篇文章中有过生猪检测盒状态识别相关的项目实践,如下:
《Python基于yolov4实现生猪检测及状态识》
感兴趣的话可以自行移步阅读,这里主要是基于同样的技术思想,将原始体积较大的yolov4模型做无缝替换,使用当下比较优秀的轻量级yolov5s模型来实现目标检测,后续基于状态识别模型实现生猪状态的识别,首先看下效果图,如下所示:
简单看下数据集:
YOLO格式标注文件如下所示:
实例标注内容如下所示:
0 0.062744 0.558594 0.046387 0.16276
0 0.077637 0.701497 0.0625 0.126953
0 0.107422 0.805664 0.053711 0.087891
0 0.129883 0.798503 0.063477 0.138672
0 0.151367 0.811198 0.073242 0.123698
0 0.22876 0.842773 0.085449 0.115234
0 0.283936 0.794922 0.066895 0.227865
0 0.333496 0.773438 0.06543 0.197917
0 0.362793 0.812826 0.078125 0.166016
0 0.394043 0.848958 0.108398 0.167969
0 0.468994 0.878255 0.131348 0.105469
0 0.720459 0.733398 0.068848 0.19987
0 0.86499 0.628255 0.096191 0.091146
0 0.922607 0.434245 0.040527 0.164062
0 0.87915 0.301107 0.046387 0.146484
0 0.907715 0.297852 0.035156 0.120443
0 0.870117 0.166992 0.047852 0.108724
0 0.829102 0.145182 0.058594 0.097656
0 0.79126 0.264974 0.112793 0.135417
0 0.684326 0.127279 0.104004 0.078776
0 0.668213 0.068685 0.10498 0.064453
0 0.616699 0.142578 0.104492 0.174479
0 0.49292 0.151042 0.162598 0.098958
0 0.437256 0.417643 0.202637 0.212891
0 0.387207 0.329753 0.104492 0.210286
0 0.300049 0.403971 0.069824 0.222005
0 0.195312 0.514974 0.12207 0.227865
0 0.222168 0.451497 0.092773 0.133464
VOC格式标注文件如下所示:
实例标注数据如下所示:
<annotation>
<folder>DATASET</folder>
<filename>images/20190621141536.jpg</filename>
<source>
<database>The DATASET Database</database>
<annotation>DATASET</annotation>
<image>DATASET</image>
</source>
<owner>
<name>YMGZS</name>
</owner>
<size>
<width>2048</width>
<height>1536</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>775</xmin>
<ymin>1268</ymin>
<xmax>1072</xmax>
<ymax>1406</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>507</xmin>
<ymin>1279</ymin>
<xmax>785</xmax>
<ymax>1434</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>464</xmin>
<ymin>1130</ymin>
<xmax>728</xmax>
<ymax>1333</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>361</xmin>
<ymin>1197</ymin>
<xmax>507</xmax>
<ymax>1366</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>226</xmin>
<ymin>1164</ymin>
<xmax>399</xmax>
<ymax>1302</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>161</xmin>
<ymin>1171</ymin>
<xmax>321</xmax>
<ymax>1311</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>168</xmin>
<ymin>1025</ymin>
<xmax>314</xmax>
<ymax>1175</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>104</xmin>
<ymin>973</ymin>
<xmax>185</xmax>
<ymax>1161</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>87</xmin>
<ymin>754</ymin>
<xmax>166</xmax>
<ymax>987</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>68</xmin>
<ymin>641</ymin>
<xmax>178</xmax>
<ymax>736</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>70</xmin>
<ymin>580</ymin>
<xmax>179</xmax>
<ymax>656</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>71</xmin>
<ymin>425</ymin>
<xmax>218</xmax>
<ymax>592</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>266</xmin>
<ymin>335</ymin>
<xmax>487</xmax>
<ymax>440</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>464</xmin>
<ymin>321</ymin>
<xmax>673</xmax>
<ymax>454</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>530</xmin>
<ymin>508</ymin>
<xmax>768</xmax>
<ymax>717</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>709</xmin>
<ymin>521</ymin>
<xmax>909</xmax>
<ymax>847</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>787</xmin>
<ymin>209</ymin>
<xmax>1011</xmax>
<ymax>549</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>949</xmin>
<ymin>64</ymin>
<xmax>1261</xmax>
<ymax>233</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1045</xmin>
<ymin>237</ymin>
<xmax>1387</xmax>
<ymax>387</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1254</xmin>
<ymin>66</ymin>
<xmax>1476</xmax>
<ymax>218</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1295</xmin>
<ymin>135</ymin>
<xmax>1495</xmax>
<ymax>235</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1480</xmin>
<ymin>104</ymin>
<xmax>1661</xmax>
<ymax>197</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1649</xmin>
<ymin>142</ymin>
<xmax>1740</xmax>
<ymax>264</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1772</xmin>
<ymin>341</ymin>
<xmax>1891</xmax>
<ymax>560</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1828</xmin>
<ymin>553</ymin>
<xmax>1933</xmax>
<ymax>772</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1810</xmin>
<ymin>782</ymin>
<xmax>1939</xmax>
<ymax>977</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1364</xmin>
<ymin>902</ymin>
<xmax>1576</xmax>
<ymax>1216</ymax>
</bndbox>
</object>
<object>
<name>pig</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1342</xmin>
<ymin>1016</ymin>
<xmax>1514</xmax>
<ymax>1247</ymax>
</bndbox>
</object>
</annotation>
默认使用轻量级的yolov5s模型来进行模型的开发,默认训练100次epoch,结果详情如下所示:
【F1值曲线】
【PR曲线】
【Precision和Recall曲线】
数据可视化:
Batch计算实例:
可视化界面推理实例如下:
目标检测+状态识别在界面中做了集成实现。