easycv.datasets.detection package

class easycv.datasets.detection.DetDataset(data_source, pipeline, profiling=False, classes=None)[source]

Bases: Generic[torch.utils.data.dataset.T_co]

Dataset for Detection

__init__(data_source, pipeline, profiling=False, classes=None)[source]
Parameters
  • data_source – Data_source config dict

  • pipeline – Pipeline config list

  • profiling – If set True, will print pipeline time

  • classes – A list of class names, used in evaluation for result and groundtruth visualization

evaluate(results, evaluators=None, logger=None)[source]

Evaluates the detection boxes. :param results: A dictionary containing

detection_boxes: List of length number of test images.

Float32 numpy array of shape [num_boxes, 4] and format [ymin, xmin, ymax, xmax] in absolute image coordinates.

detection_scores: List of length number of test images,

detection scores for the boxes, float32 numpy array of shape [num_boxes].

detection_classes: List of length number of test images,

integer numpy array of shape [num_boxes] containing 1-indexed detection classes for the boxes.

img_metas: List of length number of test images,

dict of image meta info, containing filename, img_shape, origin_img_shape, scale_factor and so on.

Parameters

evaluators – evaluators to calculate metric with results and groundtruth_dict

visualize(results, vis_num=10, score_thr=0.3, **kwargs)[source]

Visulaize the model output on validation data. :param results: A dictionary containing

detection_boxes: List of length number of test images.

Float32 numpy array of shape [num_boxes, 4] and format [ymin, xmin, ymax, xmax] in absolute image coordinates.

detection_scores: List of length number of test images,

detection scores for the boxes, float32 numpy array of shape [num_boxes].

detection_classes: List of length number of test images,

integer numpy array of shape [num_boxes] containing 1-indexed detection classes for the boxes.

img_metas: List of length number of test images,

dict of image meta info, containing filename, img_shape, origin_img_shape, scale_factor and so on.

Parameters
  • vis_num – number of images visualized

  • score_thr – The threshold to filter box, boxes with scores greater than score_thr will be kept.

Returns: A dictionary containing

images: Visulaized images. img_metas: List of length number of test images,

dict of image meta info, containing filename, img_shape, origin_img_shape, scale_factor and so on.

class easycv.datasets.detection.DetImagesMixDataset(data_source, pipeline, dynamic_scale=None, skip_type_keys=None, profiling=False, classes=None, yolo_format=True, label_padding=True)[source]

Bases: Generic[torch.utils.data.dataset.T_co]

A wrapper of multiple images mixed dataset.

Suitable for training on multiple images mixed data augmentation like mosaic and mixup. For the augmentation pipeline of mixed image data, the get_indexes method needs to be provided to obtain the image indexes, and you can set skip_flags to change the pipeline running process. At the same time, we provide the dynamic_scale parameter to dynamically change the output image size.

output boxes format: cx, cy, w, h

Parameters
  • data_source (DetSourceCoco) – The dataset to be mixed.

  • pipeline (Sequence[dict]) – Sequence of transform object or config dict to be composed.

  • dynamic_scale (tuple[int], optional) – The image scale can be changed dynamically. Default to None.

  • skip_type_keys (list[str], optional) – Sequence of type string to be skip pipeline. Default to None.

  • label_padding – out labeling padding [N, 120, 5]

__init__(data_source, pipeline, dynamic_scale=None, skip_type_keys=None, profiling=False, classes=None, yolo_format=True, label_padding=True)[source]

Args: data_source: Data_source config dict pipeline: Pipeline config list profiling: If set True, will print pipeline time classes: A list of class names, used in evaluation for result and groundtruth visualization

update_skip_type_keys(skip_type_keys)[source]

Update skip_type_keys. It is called by an external hook.

Parameters

skip_type_keys (list[str], optional) – Sequence of type string to be skip pipeline.

update_dynamic_scale(dynamic_scale)[source]

Update dynamic_scale. It is called by an external hook.

Parameters

dynamic_scale (tuple[int]) – The image scale can be changed dynamically.

results2json(results, outfile_prefix)[source]

Dump the detection results to a COCO style json file.

There are 3 types of results: proposals, bbox predictions, mask predictions, and they have different data types. This method will automatically recognize the type, and dump them to json files.

Parameters
  • results (list[list | tuple | ndarray]) – Testing results of the dataset.

  • outfile_prefix (str) – The filename prefix of the json files. If the prefix is “somepath/xxx”, the json files will be named “somepath/xxx.bbox.json”, “somepath/xxx.segm.json”, “somepath/xxx.proposal.json”.

Returns

str]: Possible keys are “bbox”, “segm”, “proposal”, and values are corresponding filenames.

Return type

dict[str

format_results(results, jsonfile_prefix=None, **kwargs)[source]

Format the results to json (standard format for COCO evaluation).

Parameters
  • results (list[tuple | numpy.ndarray]) – Testing results of the dataset.

  • jsonfile_prefix (str | None) – The prefix of json files. It includes the file path and the prefix of filename, e.g., “a/b/prefix”. If not specified, a temp file will be created. Default: None.

Returns

(result_files, tmp_dir), result_files is a dict containing the json filepaths, tmp_dir is the temporal directory created for saving json files when jsonfile_prefix is not specified.

Return type

tuple

Submodules

easycv.datasets.detection.mix module

class easycv.datasets.detection.mix.DetImagesMixDataset(data_source, pipeline, dynamic_scale=None, skip_type_keys=None, profiling=False, classes=None, yolo_format=True, label_padding=True)[source]

Bases: Generic[torch.utils.data.dataset.T_co]

A wrapper of multiple images mixed dataset.

Suitable for training on multiple images mixed data augmentation like mosaic and mixup. For the augmentation pipeline of mixed image data, the get_indexes method needs to be provided to obtain the image indexes, and you can set skip_flags to change the pipeline running process. At the same time, we provide the dynamic_scale parameter to dynamically change the output image size.

output boxes format: cx, cy, w, h

Parameters
  • data_source (DetSourceCoco) – The dataset to be mixed.

  • pipeline (Sequence[dict]) – Sequence of transform object or config dict to be composed.

  • dynamic_scale (tuple[int], optional) – The image scale can be changed dynamically. Default to None.

  • skip_type_keys (list[str], optional) – Sequence of type string to be skip pipeline. Default to None.

  • label_padding – out labeling padding [N, 120, 5]

__init__(data_source, pipeline, dynamic_scale=None, skip_type_keys=None, profiling=False, classes=None, yolo_format=True, label_padding=True)[source]

Args: data_source: Data_source config dict pipeline: Pipeline config list profiling: If set True, will print pipeline time classes: A list of class names, used in evaluation for result and groundtruth visualization

update_skip_type_keys(skip_type_keys)[source]

Update skip_type_keys. It is called by an external hook.

Parameters

skip_type_keys (list[str], optional) – Sequence of type string to be skip pipeline.

update_dynamic_scale(dynamic_scale)[source]

Update dynamic_scale. It is called by an external hook.

Parameters

dynamic_scale (tuple[int]) – The image scale can be changed dynamically.

results2json(results, outfile_prefix)[source]

Dump the detection results to a COCO style json file.

There are 3 types of results: proposals, bbox predictions, mask predictions, and they have different data types. This method will automatically recognize the type, and dump them to json files.

Parameters
  • results (list[list | tuple | ndarray]) – Testing results of the dataset.

  • outfile_prefix (str) – The filename prefix of the json files. If the prefix is “somepath/xxx”, the json files will be named “somepath/xxx.bbox.json”, “somepath/xxx.segm.json”, “somepath/xxx.proposal.json”.

Returns

str]: Possible keys are “bbox”, “segm”, “proposal”, and values are corresponding filenames.

Return type

dict[str

format_results(results, jsonfile_prefix=None, **kwargs)[source]

Format the results to json (standard format for COCO evaluation).

Parameters
  • results (list[tuple | numpy.ndarray]) – Testing results of the dataset.

  • jsonfile_prefix (str | None) – The prefix of json files. It includes the file path and the prefix of filename, e.g., “a/b/prefix”. If not specified, a temp file will be created. Default: None.

Returns

(result_files, tmp_dir), result_files is a dict containing the json filepaths, tmp_dir is the temporal directory created for saving json files when jsonfile_prefix is not specified.

Return type

tuple

easycv.datasets.detection.raw module

class easycv.datasets.detection.raw.DetDataset(data_source, pipeline, profiling=False, classes=None)[source]

Bases: Generic[torch.utils.data.dataset.T_co]

Dataset for Detection

__init__(data_source, pipeline, profiling=False, classes=None)[source]
Parameters
  • data_source – Data_source config dict

  • pipeline – Pipeline config list

  • profiling – If set True, will print pipeline time

  • classes – A list of class names, used in evaluation for result and groundtruth visualization

evaluate(results, evaluators=None, logger=None)[source]

Evaluates the detection boxes. :param results: A dictionary containing

detection_boxes: List of length number of test images.

Float32 numpy array of shape [num_boxes, 4] and format [ymin, xmin, ymax, xmax] in absolute image coordinates.

detection_scores: List of length number of test images,

detection scores for the boxes, float32 numpy array of shape [num_boxes].

detection_classes: List of length number of test images,

integer numpy array of shape [num_boxes] containing 1-indexed detection classes for the boxes.

img_metas: List of length number of test images,

dict of image meta info, containing filename, img_shape, origin_img_shape, scale_factor and so on.

Parameters

evaluators – evaluators to calculate metric with results and groundtruth_dict

visualize(results, vis_num=10, score_thr=0.3, **kwargs)[source]

Visulaize the model output on validation data. :param results: A dictionary containing

detection_boxes: List of length number of test images.

Float32 numpy array of shape [num_boxes, 4] and format [ymin, xmin, ymax, xmax] in absolute image coordinates.

detection_scores: List of length number of test images,

detection scores for the boxes, float32 numpy array of shape [num_boxes].

detection_classes: List of length number of test images,

integer numpy array of shape [num_boxes] containing 1-indexed detection classes for the boxes.

img_metas: List of length number of test images,

dict of image meta info, containing filename, img_shape, origin_img_shape, scale_factor and so on.

Parameters
  • vis_num – number of images visualized

  • score_thr – The threshold to filter box, boxes with scores greater than score_thr will be kept.

Returns: A dictionary containing

images: Visulaized images. img_metas: List of length number of test images,

dict of image meta info, containing filename, img_shape, origin_img_shape, scale_factor and so on.