StratifiedDataSplitter

class cocohelper.splitters.stratified.StratifiedDataSplitter[source]

Bases: ProportionalDataSplitter

Split a COCO dataset into N datasets.

Each split will contain a part of the original dataset samples proportionally to the arguments.

Parameters:

*proportions – Describe the split proportions for each split.

Method List

_compute_label_ratios(images_by_label)

Computes the ratio of labels within the COCO dataset.

_get_ids(ch)

Get the ids needed for the stratified dataset splitting.

_get_n_samples(n_images)

Get the number of samples for each split.

apply(coco)

Applies the splitter to the given COCOHelper.

Attributes List

_abc_impl

Methods Details

static _compute_label_ratios(images_by_label)[source]

Computes the ratio of labels within the COCO dataset.

Parameters:

images_by_label (dict) – a dictionary grouping images by their labels.

Returns:

A dictionary with the ratios of labels in the COCO dataset.

Return type:

dict

_get_ids(ch)[source]

Get the ids needed for the stratified dataset splitting.

Parameters:

ch (COCOHelper) – a COCOHelper with the source COCO dataset.

Returns:

A list of ids for each subset.

Return type:

List

_get_n_samples(n_images)

Get the number of samples for each split. :param n_images: the total number of images in the dataset.

Returns:

A list of integers with the number of samples for each split.

apply(coco)

Applies the splitter to the given COCOHelper.

Parameters:

coco (COCOHelper) – a COCOHelper containing the source dataset to be split.

Returns:

A list containing the splits of the source COCO dataset.

Return type:

List[COCOHelper]

Attribute Details

_abc_impl = <_abc._abc_data object>