Python based on lightweight YOLOv5 pig detection + status recognition analysis system

In one of my previous articles, I had a project practice related to the status recognition of the pig detection box, as follows:

"Python realizes pig detection and state recognition based on yolov4"

If you are interested, you can read it by yourself. This is mainly based on the same technical idea. The original larger yolov4 model is seamlessly replaced, and the current relatively excellent lightweight yolov5s model is used to achieve target detection, and the follow-up is based on state recognition. The model realizes the identification of the status of live pigs. First, look at the renderings, as shown below:

 Just look at the dataset:

 The YOLO format annotation file is as follows:

 The content of the example annotation is as follows:

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

The VOC format annotation file is as follows:

 The example annotation data is as follows:

<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>

By default, the lightweight yolov5s model is used for model development. The default training is 100 epochs. The result details are as follows:

【F1 Value Curve】

 【PR curve】

 【Precision and Recall curve】

 data visualization:

 Batch calculation example:

 Examples of visual interface reasoning are as follows:

 Target detection + state recognition is integrated in the interface.

Guess you like

Origin blog.csdn.net/Together_CZ/article/details/130389193