From 9272912f188bf63d6fa9bbd7d73e7cc8265090c0 Mon Sep 17 00:00:00 2001 From: manikanta5557 Date: Tue, 17 Dec 2024 14:38:44 +0530 Subject: [PATCH 1/2] Input Dimesion error while using rknn model --- examples/yolov8_seg/python/yolov8_seg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/yolov8_seg/python/yolov8_seg.py b/examples/yolov8_seg/python/yolov8_seg.py index 75217b9..ab4c5cb 100644 --- a/examples/yolov8_seg/python/yolov8_seg.py +++ b/examples/yolov8_seg/python/yolov8_seg.py @@ -305,7 +305,7 @@ def img_check(path): input_data = input_data.reshape(1,*input_data.shape).astype(np.float32) input_data = input_data/255. else: - input_data = img + input_data = np.expand_dims(img,0) outputs = model.run([input_data]) boxes, classes, scores, seg_img = post_process(outputs) From f3319a25e3572d3b6a4364a795d55e385142e6d7 Mon Sep 17 00:00:00 2001 From: manikanta5557 Date: Tue, 17 Dec 2024 15:07:02 +0530 Subject: [PATCH 2/2] Handling input shape error while using .rknn model and handling no detections error --- examples/yolov8_seg/python/yolov8_seg.py | 26 +++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/yolov8_seg/python/yolov8_seg.py b/examples/yolov8_seg/python/yolov8_seg.py index ab4c5cb..b44e8cd 100644 --- a/examples/yolov8_seg/python/yolov8_seg.py +++ b/examples/yolov8_seg/python/yolov8_seg.py @@ -193,13 +193,17 @@ def sp_flatten(_in): return boxes, classes, scores, seg_img def draw(image, boxes, scores, classes): - for box, score, cl in zip(boxes, scores, classes): - top, left, right, bottom = [int(_b) for _b in box] - print("%s @ (%d %d %d %d) %.3f" % (CLASSES[cl], top, left, right, bottom, score)) - cv2.rectangle(image, (top, left), (right, bottom), (255, 0, 0), 2) - cv2.putText(image, '{0} {1:.2f}'.format(CLASSES[cl], score), - (top, left - 6), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2) - + #loop through each detected object + if scores is not None: + for box, score, cl in zip(boxes, scores, classes): + top, left, right, bottom = [int(_b) for _b in box] + print("%s @ (%d %d %d %d) %.3f" % (CLASSES[cl], top, left, right, bottom, score)) + cv2.rectangle(image, (top, left), (right, bottom), (255, 0, 0), 2) + cv2.putText(image, '{0} {1:.2f}'.format(CLASSES[cl], score), + (top, left - 6), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2) + #no object is detected in the image + else: + print("No objects found") def _crop_mask(masks, boxes): """ "Crop" predicted masks by zeroing out everything not in the predicted bbox. @@ -314,12 +318,14 @@ def img_check(path): real_boxs = co_helper.get_real_box(boxes) real_segs = co_helper.get_real_seg(seg_img) img_p = merge_seg(img_src, real_segs, classes) - + # if there is no object detected in the image + img_p = img_src.copy() if args.img_show or args.img_save: print('\n\nIMG: {}'.format(img_name)) - - draw(img_p, real_boxs, scores, classes) + #draw masks only if there are any objects detected in the image + if boxes is not None: + draw(img_p, real_boxs, scores, classes) if args.img_save: if not os.path.exists('./result'):