select-nms
时间: 2023-10-23 08:13:53 浏览: 101
select-nms是一个目标检测领域常用的算法,用于在检测结果中进行非极大值抑制(Non-Maximum Suppression,简称NMS)。NMS的目的是根据一定的阈值,从多个重叠的候选框中选择出最具代表性的框。
NMS的基本思想是,首先根据检测结果的置信度进行排序,然后从置信度最高的框开始,依次判断其与后续框的重叠程度,如果重叠程度大于设定的阈值,则将该框移除。这样可以保留最具代表性的框,并且去除冗余的框。
相关问题
super(Ui_MainWindow, self).__init__(parent) parser_car_det = argparse.ArgumentParser() # parser.add_argument('--weights', type=str, default='weights-s/best1.pt', help='model.pt path') parser_car_det.add_argument('--weights', type=str, default='weights-s/best1.pt', help='model.pt path') parser_car_det.add_argument('--source', type=str, default='input/3.mp4', help='source') # file/folder, 0 for webcam # parser.add_argument('--source', type=str, default='rtsp://admin:hik12345@192.168.1.64:554//Streaming/Channels/101', help='source') # file/folder, 0 for webcam parser_car_det.add_argument('--output', type=str, default='inference/output', help='output folder') # output folder parser_car_det.add_argument('--img-size', type=int, default=640, help='inference size (pixels)') parser_car_det.add_argument('--conf-thres', type=float, default=0.4, help='object confidence threshold') parser_car_det.add_argument('--iou-thres', type=float, default=0.5, help='IOU threshold for NMS') parser_car_det.add_argument('--fourcc', type=str, default='mp4v', help='output video codec (verify ffmpeg support)') parser_car_det.add_argument('--device', default='cpu', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') parser_car_det.add_argument('--view-img', action='store_true', help='display results') parser_car_det.add_argument('--save-txt', action='store_true', help='save results to *.txt') parser_car_det.add_argument('--classes', nargs='+', type=int, help='filter by class') parser_car_det.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS') parser_car_det.add_argument('--augment', action='store_true', help='augmented inference') parser_car_det.add_argument('--idx', default='2', help='idx') self.opt_car_det = parser_car_det.parse_args() self.opt_car_det.img_size = check_img_size(self.opt_car_det.img_size) half = 0 source_car_det, weights_car_det, view_img_car_det, save_txt_car_det, imgsz_car_det = self.opt_car_det.source, self.opt_car_det.weights, self.opt_car_det.view_img, self.opt_car_det.save_txt, self.opt_car_det.img_size self.device_car_det = torch_utils.select_device(self.opt_car_det.device) self.half_car_det = 0 # half precision only supported on CUDA cudnn.benchmark = True
super(Ui_MainWindow, self).__init__(parent) 表示使用父类的构造函数来初始化子类,这里父类是 Ui_MainWindow。
parser_car_det = argparse.ArgumentParser() 表示定义了一个解析器,用来解析输入的参数。
解释代码: def detect_cma(self): # pass model = self.model output_size = self.output_size # source = self.img2predict # file/dir/URL/glob, 0 for webcam imgsz = [640, 640] # inference size (pixels) conf_thres = 0.25 # confidence threshold iou_thres = 0.45 # NMS IOU threshold max_det = 1000 # maximum detections per image # device = self.device # cuda device, i.e. 0 or 0,1,2,3 or cpu view_img = False # show results save_txt = False # save results to *.txt save_conf = False # save confidences in --save-txt labels save_crop = False # save cropped prediction boxes nosave = False # do not save images/videos classes = None # filter by class: --class 0, or --class 0 2 3 agnostic_nms = False # class-agnostic NMS augment = False # ugmented inference visualize = False # visualize features line_thickness = 3 # bounding box thickness (pixels) hide_labels = False # hide labels hide_conf = False # hide confidences half = False # use FP16 half-precision inference dnn = False # use OpenCV DNN for ONNX inference source = str(self.vid_source) device = select_device(self.device) stride, names, pt, jit, onnx = model.stride, model.names, model.pt, model.jit, model.onnx imgsz = check_img_size(imgsz, s=stride) # check image size save_img = not nosave and not source.endswith('.txt') # save inference images
这段代码用于使用 YOLOv5 模型对图像或视频进行目标检测。它首先从类的属性中获取模型、输出大小、视频源等信息。然后设置了一些参数,如推理尺寸、置信度阈值、NMS IOU 阈值等。接着根据设备类型选择使用 CPU 还是 GPU 进行推理。最后,它检查图像的大小是否符合模型要求,设置是否保存推理结果图片,然后返回检测结果。
阅读全文