From 16639b60ebc63111d0283edf9cf37f4b5ce479b9 Mon Sep 17 00:00:00 2001
From: Ileal16 <145340765+Ileal16@users.noreply.github.com>
Date: Thu, 30 Nov 2023 13:49:24 +0100
Subject: [PATCH] Repair `convert_coco()` box-segment discarding (#6689)

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
---
 ultralytics/__init__.py       |  2 +-
 ultralytics/data/converter.py | 29 ++++++++++++++---------------
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py
index bb102a6652..2fb0250f22 100644
--- a/ultralytics/__init__.py
+++ b/ultralytics/__init__.py
@@ -1,6 +1,6 @@
 # Ultralytics YOLO 🚀, AGPL-3.0 license
 
-__version__ = '8.0.220'
+__version__ = '8.0.221'
 
 from ultralytics.models import RTDETR, SAM, YOLO
 from ultralytics.models.fastsam import FastSAM
diff --git a/ultralytics/data/converter.py b/ultralytics/data/converter.py
index 2f9a1dc1bb..5714320f20 100644
--- a/ultralytics/data/converter.py
+++ b/ultralytics/data/converter.py
@@ -118,22 +118,21 @@ def convert_coco(labels_dir='../coco/annotations/',
                 box = [cls] + box.tolist()
                 if box not in bboxes:
                     bboxes.append(box)
-                if use_segments and ann.get('segmentation') is not None:
-                    if len(ann['segmentation']) == 0:
-                        segments.append([])
-                        continue
-                    elif len(ann['segmentation']) > 1:
-                        s = merge_multi_segment(ann['segmentation'])
-                        s = (np.concatenate(s, axis=0) / np.array([w, h])).reshape(-1).tolist()
-                    else:
-                        s = [j for i in ann['segmentation'] for j in i]  # all segments concatenated
-                        s = (np.array(s).reshape(-1, 2) / np.array([w, h])).reshape(-1).tolist()
-                    s = [cls] + s
-                    if s not in segments:
+                    if use_segments and ann.get('segmentation') is not None:
+                        if len(ann['segmentation']) == 0:
+                            segments.append([])
+                            continue
+                        elif len(ann['segmentation']) > 1:
+                            s = merge_multi_segment(ann['segmentation'])
+                            s = (np.concatenate(s, axis=0) / np.array([w, h])).reshape(-1).tolist()
+                        else:
+                            s = [j for i in ann['segmentation'] for j in i]  # all segments concatenated
+                            s = (np.array(s).reshape(-1, 2) / np.array([w, h])).reshape(-1).tolist()
+                        s = [cls] + s
                         segments.append(s)
-                if use_keypoints and ann.get('keypoints') is not None:
-                    keypoints.append(box + (np.array(ann['keypoints']).reshape(-1, 3) /
-                                            np.array([w, h, 1])).reshape(-1).tolist())
+                    if use_keypoints and ann.get('keypoints') is not None:
+                        keypoints.append(box + (np.array(ann['keypoints']).reshape(-1, 3) /
+                                                np.array([w, h, 1])).reshape(-1).tolist())
 
             # Write
             with open((fn / f).with_suffix('.txt'), 'a') as file: