Ultralytics YOLO Format¶
Support for Ultralytics YOLO pose format.
sleap_io.io.main.load_ultralytics(dataset_path, split='train', skeleton=None, **kwargs)
¶
Load an Ultralytics YOLO pose dataset as a SLEAP Labels object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_path
|
str
|
Path to the Ultralytics dataset root directory containing data.yaml. |
required |
split
|
str
|
Dataset split to read ('train', 'val', or 'test'). Defaults to 'train'. |
'train'
|
skeleton
|
Skeleton | None
|
Optional skeleton to use. If not provided, will be inferred from data.yaml. |
None
|
**kwargs
|
Additional arguments passed to |
required |
Returns:
| Type | Description |
|---|---|
Labels
|
The dataset as a |
Source code in sleap_io/io/main.py
def load_ultralytics(
dataset_path: str,
split: str = "train",
skeleton: Skeleton | None = None,
**kwargs,
) -> Labels:
"""Load an Ultralytics YOLO pose dataset as a SLEAP `Labels` object.
Args:
dataset_path: Path to the Ultralytics dataset root directory containing
data.yaml.
split: Dataset split to read ('train', 'val', or 'test'). Defaults to 'train'.
skeleton: Optional skeleton to use. If not provided, will be inferred from
data.yaml.
**kwargs: Additional arguments passed to `ultralytics.read_labels`.
Currently supports:
- image_size: Tuple of (height, width) for coordinate denormalization.
Defaults to
(480, 640). Will attempt to infer from actual images if available.
Returns:
The dataset as a `Labels` object.
"""
from sleap_io.io import ultralytics
return ultralytics.read_labels(
dataset_path, split=split, skeleton=skeleton, **kwargs
)
sleap_io.io.main.save_ultralytics(labels, dataset_path, split_ratios={'train': 0.8, 'val': 0.2}, **kwargs)
¶
Save a SLEAP dataset to Ultralytics YOLO pose format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Labels
|
A SLEAP |
required |
dataset_path
|
str
|
Path to save the Ultralytics dataset. |
required |
split_ratios
|
dict
|
Dictionary mapping split names to ratios (must sum to 1.0). Defaults to {"train": 0.8, "val": 0.2}. |
{'train': 0.8, 'val': 0.2}
|
**kwargs
|
Additional arguments passed to |
required |
Source code in sleap_io/io/main.py
def save_ultralytics(
labels: Labels,
dataset_path: str,
split_ratios: dict = {"train": 0.8, "val": 0.2},
**kwargs,
):
"""Save a SLEAP dataset to Ultralytics YOLO pose format.
Args:
labels: A SLEAP `Labels` object.
dataset_path: Path to save the Ultralytics dataset.
split_ratios: Dictionary mapping split names to ratios (must sum to 1.0).
Defaults to {"train": 0.8, "val": 0.2}.
**kwargs: Additional arguments passed to `ultralytics.write_labels`.
Currently supports:
- class_id: Class ID to use for all instances (default: 0).
- image_format: Image format to use for saving frames. Either "png"
(default, lossless) or "jpg".
- image_quality: Image quality for JPEG format (1-100). For PNG, this is
the compression
level (0-9). If None, uses default quality settings.
- verbose: If True (default), show progress bars during export.
- use_multiprocessing: If True, use multiprocessing for parallel image
saving. Default is False.
- n_workers: Number of worker processes. If None, uses CPU count - 1.
Only used if
use_multiprocessing=True.
"""
from sleap_io.io import ultralytics
ultralytics.write_labels(labels, dataset_path, split_ratios=split_ratios, **kwargs)