ONNX-YOLOv8-Instance-Segmentation icon indicating copy to clipboard operation
ONNX-YOLOv8-Instance-Segmentation copied to clipboard

yolov8 instance segmentation

Open shamstuqa opened this issue 1 year ago • 0 comments

Hello I want to use yolov8 to do the segmentation ,,, and I have a dataset,, but some of the images in the dataset do not contain an object that yolo can segment for, so it returns the value "None",, how to make yolo skip images that do not contain an object that yolo can You detect it and move to the other image without error?? I tried more than one condition, but it didn't work for me.

this is the line code for filename in os.listdir(input_folder): if filename.endswith(('.jpg', '.png')): img = cv2.imread(os.path.join(input_folder, filename))

# detect objects using YOLO
result = ys.detect(img)
if result is None:
    continue  # skip this image if YOLO fails to detect any objects

bboxes, classes, segmentations, scores = result

for bbox, class_id, seg, score in zip(bboxes, classes, segmentations, scores):
        (x, y, x2, y2) = bbox
        cv2.polylines(img, [seg], True, (0, 255, 0), 2)
        mask = np.zeros_like(img[:,:,0])
        cv2.fillPoly(mask, [seg], 1)
        object = img * np.expand_dims(mask, axis=2)

and the error after one houres

AttributeError Traceback (most recent call last) in 21 22 # detect objects using YOLO ---> 23 result = ys.detect(img) 24 if result is None: 25 continue # skip this image if YOLO fails to detect any objects

/content/drive/MyDrive/yolov8_segmentation-pysource.com/yolo_segmentation.py in detect(self, img) 16 result = results[0] 17 segmentation_contours_idx = [] ---> 18 for seg in result.masks.segments: 19 # contours 20 seg[:, 0] *= width

AttributeError: 'NoneType' object has no attribute 'segments'

shamstuqa avatar Mar 24 '23 17:03 shamstuqa