coco91_to_coco80_class
Converts 91-index COCO class IDs to 80-index COCO class IDs.
Returns:
Type | Description |
---|---|
list
|
A list of 91 class IDs where the index represents the 80-index class ID and the value is the corresponding 91-index class ID. |
Source code in ultralytics/yolo/data/converter.py
convert_coco
Converts COCO dataset annotations to a format suitable for training YOLOv5 models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labels_dir |
str
|
Path to directory containing COCO dataset annotation files. |
'../coco/annotations/'
|
use_segments |
bool
|
Whether to include segmentation masks in the output. |
False
|
use_keypoints |
bool
|
Whether to include keypoint annotations in the output. |
False
|
cls91to80 |
bool
|
Whether to map 91 COCO class IDs to the corresponding 80 COCO class IDs. |
True
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the labels_dir path does not exist. |
Example Usage
convert_coco(labels_dir='../coco/annotations/', use_segments=True, use_keypoints=True, cls91to80=True)
Output
Generates output files in the specified output directory.
Source code in ultralytics/yolo/data/converter.py
rle2polygon
Convert Run-Length Encoding (RLE) mask to polygon coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segmentation |
dict, list
|
RLE mask representation of the object segmentation. |
required |
Returns:
Type | Description |
---|---|
list
|
A list of lists representing the polygon coordinates for each contour. |
Note
Requires the 'pycocotools' package to be installed.
Source code in ultralytics/yolo/data/converter.py
min_index
Find a pair of indexes with the shortest distance between two arrays of 2D points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arr1 |
np.array
|
A NumPy array of shape (N, 2) representing N 2D points. |
required |
arr2 |
np.array
|
A NumPy array of shape (M, 2) representing M 2D points. |
required |
Returns:
Type | Description |
---|---|
tuple
|
A tuple containing the indexes of the points with the shortest distance in arr1 and arr2 respectively. |
Source code in ultralytics/yolo/data/converter.py
merge_multi_segment
Merge multiple segments into one list by connecting the coordinates with the minimum distance between each segment. This function connects these coordinates with a thin line to merge all segments into one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segments |
List[List]
|
Original segmentations in COCO's JSON file. Each element is a list of coordinates, like [segmentation1, segmentation2,...]. |
required |
Returns:
Name | Type | Description |
---|---|---|
s |
List[np.ndarray]
|
A list of connected segments represented as NumPy arrays. |
Source code in ultralytics/yolo/data/converter.py
delete_dsstore
Delete Apple .DS_Store files in the specified directory and its subdirectories.
Source code in ultralytics/yolo/data/converter.py
Created 2023-05-06, Updated 2023-05-17
Authors: Glenn Jocher (3)