mirror of
https://github.com/THU-MIG/yolov10.git
synced 2025-05-23 21:44:22 +08:00
Repair convert_coco()
box-segment discarding (#6689)
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
2e71f7f50e
commit
16639b60eb
@ -1,6 +1,6 @@
|
|||||||
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
||||||
|
|
||||||
__version__ = '8.0.220'
|
__version__ = '8.0.221'
|
||||||
|
|
||||||
from ultralytics.models import RTDETR, SAM, YOLO
|
from ultralytics.models import RTDETR, SAM, YOLO
|
||||||
from ultralytics.models.fastsam import FastSAM
|
from ultralytics.models.fastsam import FastSAM
|
||||||
|
@ -118,22 +118,21 @@ def convert_coco(labels_dir='../coco/annotations/',
|
|||||||
box = [cls] + box.tolist()
|
box = [cls] + box.tolist()
|
||||||
if box not in bboxes:
|
if box not in bboxes:
|
||||||
bboxes.append(box)
|
bboxes.append(box)
|
||||||
if use_segments and ann.get('segmentation') is not None:
|
if use_segments and ann.get('segmentation') is not None:
|
||||||
if len(ann['segmentation']) == 0:
|
if len(ann['segmentation']) == 0:
|
||||||
segments.append([])
|
segments.append([])
|
||||||
continue
|
continue
|
||||||
elif len(ann['segmentation']) > 1:
|
elif len(ann['segmentation']) > 1:
|
||||||
s = merge_multi_segment(ann['segmentation'])
|
s = merge_multi_segment(ann['segmentation'])
|
||||||
s = (np.concatenate(s, axis=0) / np.array([w, h])).reshape(-1).tolist()
|
s = (np.concatenate(s, axis=0) / np.array([w, h])).reshape(-1).tolist()
|
||||||
else:
|
else:
|
||||||
s = [j for i in ann['segmentation'] for j in i] # all segments concatenated
|
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 = (np.array(s).reshape(-1, 2) / np.array([w, h])).reshape(-1).tolist()
|
||||||
s = [cls] + s
|
s = [cls] + s
|
||||||
if s not in segments:
|
|
||||||
segments.append(s)
|
segments.append(s)
|
||||||
if use_keypoints and ann.get('keypoints') is not None:
|
if use_keypoints and ann.get('keypoints') is not None:
|
||||||
keypoints.append(box + (np.array(ann['keypoints']).reshape(-1, 3) /
|
keypoints.append(box + (np.array(ann['keypoints']).reshape(-1, 3) /
|
||||||
np.array([w, h, 1])).reshape(-1).tolist())
|
np.array([w, h, 1])).reshape(-1).tolist())
|
||||||
|
|
||||||
# Write
|
# Write
|
||||||
with open((fn / f).with_suffix('.txt'), 'a') as file:
|
with open((fn / f).with_suffix('.txt'), 'a') as file:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user