def detect(image, model, num_classes, max_per_image): images, meta = pre_process(image, 1) images = images.to("cuda") output, dets = process(images, model, return_time=True) detection_result = [] dets = post_process(dets, meta, num_classes, max_per_image) results = merge_outputs(dets, num_classes, max_per_image) images = images.to("cpu") image_detection = None # image_detection = np.zeros((384,384,3)) for j in range(1, num_classes + 1): for bbox in results[j]: # print("the bbox is {}".format(bbox)) # print("the type of bbox is ",type(bbox)) if bbox[4] > 0.01: detection_result.append( [bbox[0], bbox[1], bbox[2], bbox[3], bbox[4], j]) image_detection = add_coco_bbox(image, bbox, j - 1, conf=1, show_txt=True, img_id='default') # else: # detection_result.append([0,0,0,0,0]) # cv2.imshow("detection",image_detection) # cv2.waitKey(10) return image_detection, detection_result
def detect_eval(image, model, num_classes, max_per_image): images, meta = pre_process(image, 1) images = images.to("cuda") output, dets = process(images, model, return_time=True) detection_result = [] dets = post_process(dets, meta, num_classes, max_per_image) results = merge_outputs(dets, num_classes, max_per_image) # images = images.to("cpu") for j in range(1, num_classes + 1): for bbox in results[j]: if bbox[4] > 0.1: detection_result.append( [bbox[0], bbox[1], bbox[2], bbox[3], bbox[4], j - 1]) return detection_result
def detect(image, model, num_classes): images, meta = pre_process(image, 1) images = images.to("cuda") output, dets = process(images, model, return_time=True) # print("the wh is {}".format(output["wh"])) dets = post_process(dets, meta, num_classes) results = merge_outputs(dets, num_classes, max_per_image) for j in range(1, num_classes + 1): for bbox in results[j]: if bbox[4] > 0.3: image_detection = add_coco_bbox(image, bbox, bbox[4], conf=1, show_txt=True, img_id='default') cv2.imshow("detection", image_detection) cv2.waitKey(1) return image_detection