if __name__ == '__main__':
parser = argparse.ArgumentParser()
#默认值default='yolov5s.pt',指定网络模型,实现下载
parser.add_argument('--weights', nargs='+', type=str, default='yolov5s.pt', help='model.pt path(s)')
#设置图片的输入default='data/images'
parser.add_argument('--source', type=str, default='data/images', help='source') # file/folder, 0 for webcam
#训练照片大小规定,但是不是非640,结果会进行匹配,回复原有大小
parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
#conf置信度,当置信度大于0.25才相信这是一个需要测试的物体
parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
#iou置信度,两块区域的交集部分除两个区域的并集部分的结果是0.45,两个框重合区域大于0.45时相信两个框检测的是同一个物体,变为一个框
parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')
#设备如cudo/cpu
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
#指定是否显示结果 python detect.py --view-img ,不指定则为false不显示,指定则为true显示判断结果
parser.add_argument('--view-img', action='store_true', help='display results')
#是否将结果保存为txt
parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')
#是否保存结果的置信度
parser.add_argument('--save-conf', action='store_true', help='save confidences in --save-txt labels')
#是否不保存图片和视频
parser.add_argument('--nosave', action='store_true', help='do not save images/videos')
#nargs='+' python detect.py --class 0可以将0赋值给class,,这样可以实现只保留class的0类,就是人,而不保留其他的类别
parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
#增强的nms/augment,设置之后nms/augment会更加强大,实现检测效果更佳
parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')
parser.add_argument('--augment', action='store_true', help='augmented inference')
#修改模型中的参数,只保留需要的那部分比如优化器之类(不用管)
parser.add_argument('--update', action='store_true', help='update all models')
#设置测试结果保存的位置,默认位runs,可通过这个修改
parser.add_argument('--project', default='runs/detect', help='save results to project/name')
#保存结果名字的文件夹
parser.add_argument('--name', default='exp', help='save results to project/name')
#设置为true保存的结果就在原来的文件夹中保存,false则新建文件夹
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
opt = parser.parse_args()
print(opt)
check_requirements(exclude=('pycocotools', 'thop'))
with torch.no_grad():
if opt.update: # update all models (to fix SourceChangeWarning)
for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']:
detect()
strip_optimizer(opt.weights)
else:
detect()
2023.4.9 yolov5_detect.py学习记录
于 2023-04-09 22:29:18 首次发布