Complete YOLOv5 target recognition from scratch (7) A simple way to complete target counting

Previous articles:

Complete YOLOv5 target recognition from scratch (6) Use continuous training to complete large-scale data set training (take FLIR as an example)

​​​​​​Complete YOLOv5 target recognition from scratch (5) A way to expand the data set

from scratch Start to complete Yolov5 target recognition (4) Encapsulate a cross-device YOLOv5 detection software

Complete YOLOv5 target recognition from scratch (3) Use PyQt5 to display the recognition results of YOLOv5

Complete Yolov5 target recognition from scratch (2) Make and train your own training set

Complete Yolov5 target recognition from scratch (1) preparations

The first thing readers should realize is that counting anchor boxes in YOLOv5 is a very simple task, and there are only two lines of code to modify. But now the price of the code peddled on CSDN is nearly 100. In particular, the method of target counting is recorded below:

Count in detect.py/main.py:

The previous series of the book uses PyQt5 to display the training results in real time:

Modify from main.py line 138 to:

                    count=1
                    for *xyxy, conf, cls in reversed(det):
                        c=int(cls)
                        label='%s %d' % (self.names[int(cls)],count)
                        name_list.append(self.names[int(cls)])
                    
                        single_info = plot_one_box(xyxy, showimg, label=label, color=self.colors[int(cls)], line_thickness=1)
                        count+=1

Among them, the label variable records the variables that need to be displayed. It was originally the label name names+confidence degree conf, and after the modification, it displays names+count count. If you need to display other variables, you can continue to modify the label.

The drawing method in plot.py called by plot_one_box.

Show results:

 Note: This operation must be effective in the case of single target counting , multi-target has not been tried

Readers who do not follow the series of articles can also modify the code in detect.py to achieve the same effect.

Guess you like

Origin blog.csdn.net/WZT725/article/details/123982937