Shortcuts

mmdet.apis

mmdet.datasets

datasets

api_wrappers

samplers

transforms

mmdet.engine

hooks

optimizers

runner

schedulers

mmdet.evaluation

functional

mmdet.evaluation.functional.average_precision(recalls, precisions, mode='area')[源代码]

Calculate average precision (for single or multiple scales).

参数
  • recalls (ndarray) – shape (num_scales, num_dets) or (num_dets, )

  • precisions (ndarray) – shape (num_scales, num_dets) or (num_dets, )

  • mode (str) – ‘area’ or ‘11points’, ‘area’ means calculating the area under precision-recall curve, ‘11points’ means calculating the average precision of recalls at [0, 0.1, …, 1]

返回

calculated average precision

返回类型

float or ndarray

mmdet.evaluation.functional.bbox_overlaps(bboxes1, bboxes2, mode='iou', eps=1e-06, use_legacy_coordinate=False)[源代码]

Calculate the ious between each bbox of bboxes1 and bboxes2.

参数
  • bboxes1 (ndarray) – Shape (n, 4)

  • bboxes2 (ndarray) – Shape (k, 4)

  • mode (str) – IOU (intersection over union) or IOF (intersection over foreground)

  • use_legacy_coordinate (bool) – Whether to use coordinate system in mmdet v1.x. which means width, height should be calculated as ‘x2 - x1 + 1` and ‘y2 - y1 + 1’ respectively. Note when function is used in VOCDataset, it should be True to align with the official implementation http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCdevkit_18-May-2011.tar Default: False.

返回

Shape (n, k)

返回类型

ious (ndarray)

mmdet.evaluation.functional.cityscapes_classes()list[源代码]

Class names of Cityscapes.

mmdet.evaluation.functional.coco_classes()list[源代码]

Class names of COCO.

mmdet.evaluation.functional.coco_panoptic_classes()list[源代码]

Class names of COCO panoptic.

mmdet.evaluation.functional.eval_map(det_results, annotations, scale_ranges=None, iou_thr=0.5, ioa_thr=None, dataset=None, logger=None, tpfp_fn=None, nproc=4, use_legacy_coordinate=False, use_group_of=False, eval_mode='area')[源代码]

Evaluate mAP of a dataset.

参数
  • det_results (list[list]) – [[cls1_det, cls2_det, …], …]. The outer list indicates images, and the inner list indicates per-class detected bboxes.

  • annotations (list[dict]) –

    Ground truth annotations where each item of the list indicates an image. Keys of annotations are:

    • bboxes: numpy array of shape (n, 4)

    • labels: numpy array of shape (n, )

    • bboxes_ignore (optional): numpy array of shape (k, 4)

    • labels_ignore (optional): numpy array of shape (k, )

  • scale_ranges (list[tuple] | None) – Range of scales to be evaluated, in the format [(min1, max1), (min2, max2), …]. A range of (32, 64) means the area range between (32**2, 64**2). Defaults to None.

  • iou_thr (float) – IoU threshold to be considered as matched. Defaults to 0.5.

  • ioa_thr (float | None) – IoA threshold to be considered as matched, which only used in OpenImages evaluation. Defaults to None.

  • dataset (list[str] | str | None) – Dataset name or dataset classes, there are minor differences in metrics for different datasets, e.g. “voc”, “imagenet_det”, etc. Defaults to None.

  • logger (logging.Logger | str | None) – The way to print the mAP summary. See mmengine.logging.print_log() for details. Defaults to None.

  • tpfp_fn (callable | None) – The function used to determine true/ false positives. If None, tpfp_default() is used as default unless dataset is ‘det’ or ‘vid’ (tpfp_imagenet() in this case). If it is given as a function, then this function is used to evaluate tp & fp. Default None.

  • nproc (int) – Processes used for computing TP and FP. Defaults to 4.

  • use_legacy_coordinate (bool) – Whether to use coordinate system in mmdet v1.x. which means width, height should be calculated as ‘x2 - x1 + 1` and ‘y2 - y1 + 1’ respectively. Defaults to False.

  • use_group_of (bool) – Whether to use group of when calculate TP and FP, which only used in OpenImages evaluation. Defaults to False.

  • eval_mode (str) – ‘area’ or ‘11points’, ‘area’ means calculating the area under precision-recall curve, ‘11points’ means calculating the average precision of recalls at [0, 0.1, …, 1], PASCAL VOC2007 uses 11points as default evaluate mode, while others are ‘area’. Defaults to ‘area’.

返回

(mAP, [dict, dict, …])

返回类型

tuple

mmdet.evaluation.functional.eval_recalls(gts, proposals, proposal_nums=None, iou_thrs=0.5, logger=None, use_legacy_coordinate=False)[源代码]

Calculate recalls.

参数
  • gts (list[ndarray]) – a list of arrays of shape (n, 4)

  • proposals (list[ndarray]) – a list of arrays of shape (k, 4) or (k, 5)

  • proposal_nums (int | Sequence[int]) – Top N proposals to be evaluated.

  • iou_thrs (float | Sequence[float]) – IoU thresholds. Default: 0.5.

  • logger (logging.Logger | str | None) – The way to print the recall summary. See mmengine.logging.print_log() for details. Default: None.

  • use_legacy_coordinate (bool) – Whether use coordinate system in mmdet v1.x. “1” was added to both height and width which means w, h should be computed as ‘x2 - x1 + 1` and ‘y2 - y1 + 1’. Default: False.

返回

recalls of different ious and proposal nums

返回类型

ndarray

mmdet.evaluation.functional.evaluateImgLists(prediction_list: list, groundtruth_list: list, args: object, backend_args: Optional[dict] = None, dump_matches: bool = False)dict[源代码]

A wrapper of obj:``cityscapesscripts.evaluation.

evalInstanceLevelSemanticLabeling.evaluateImgLists``. Support loading groundtruth image from file backend. :param prediction_list: A list of prediction txt file. :type prediction_list: list :param groundtruth_list: A list of groundtruth image file. :type groundtruth_list: list :param args: A global object setting in

obj:cityscapesscripts.evaluation. evalInstanceLevelSemanticLabeling

参数
  • backend_args (dict, optional) – Arguments to instantiate the preifx of uri corresponding backend. Defaults to None.

  • dump_matches (bool) – whether dump matches.json. Defaults to False.

返回

The computed metric.

返回类型

dict

mmdet.evaluation.functional.get_classes(dataset)list[源代码]

Get class names of a dataset.

mmdet.evaluation.functional.imagenet_det_classes()list[源代码]

Class names of ImageNet Det.

mmdet.evaluation.functional.imagenet_vid_classes()list[源代码]

Class names of ImageNet VID.

mmdet.evaluation.functional.objects365v1_classes()list[源代码]

Class names of Objects365 V1.

mmdet.evaluation.functional.objects365v2_classes()list[源代码]

Class names of Objects365 V2.

mmdet.evaluation.functional.oid_challenge_classes()list[源代码]

Class names of Open Images Challenge.

mmdet.evaluation.functional.oid_v6_classes()list[源代码]

Class names of Open Images V6.

mmdet.evaluation.functional.plot_iou_recall(recalls, iou_thrs)[源代码]

Plot IoU-Recalls curve.

参数
  • recalls (ndarray or list) – shape (k,)

  • iou_thrs (ndarray or list) – same shape as recalls

mmdet.evaluation.functional.plot_num_recall(recalls, proposal_nums)[源代码]

Plot Proposal_num-Recalls curve.

参数
  • recalls (ndarray or list) – shape (k,)

  • proposal_nums (ndarray or list) – same shape as recalls

mmdet.evaluation.functional.pq_compute_multi_core(matched_annotations_list, gt_folder, pred_folder, categories, backend_args=None, nproc=32)[源代码]

Evaluate the metrics of Panoptic Segmentation with multithreading.

Same as the function with the same name in panopticapi.

参数
  • matched_annotations_list (list) – The matched annotation list. Each element is a tuple of annotations of the same image with the format (gt_anns, pred_anns).

  • gt_folder (str) – The path of the ground truth images.

  • pred_folder (str) – The path of the prediction images.

  • categories (str) – The categories of the dataset.

  • backend_args (object) – The file client of the dataset. If None, the backend will be set to local.

  • nproc (int) – Number of processes for panoptic quality computing. Defaults to 32. When nproc exceeds the number of cpu cores, the number of cpu cores is used.

mmdet.evaluation.functional.pq_compute_single_core(proc_id, annotation_set, gt_folder, pred_folder, categories, backend_args=None, print_log=False)[源代码]

The single core function to evaluate the metric of Panoptic Segmentation.

Same as the function with the same name in panopticapi. Only the function to load the images is changed to use the file client.

参数
  • proc_id (int) – The id of the mini process.

  • gt_folder (str) – The path of the ground truth images.

  • pred_folder (str) – The path of the prediction images.

  • categories (str) – The categories of the dataset.

  • backend_args (object) – The Backend of the dataset. If None, the backend will be set to local.

  • print_log (bool) – Whether to print the log. Defaults to False.

mmdet.evaluation.functional.print_map_summary(mean_ap, results, dataset=None, scale_ranges=None, logger=None)[源代码]

Print mAP and results of each class.

A table will be printed to show the gts/dets/recall/AP of each class and the mAP.

参数
  • mean_ap (float) – Calculated from eval_map().

  • results (list[dict]) – Calculated from eval_map().

  • dataset (list[str] | str | None) – Dataset name or dataset classes.

  • scale_ranges (list[tuple] | None) – Range of scales to be evaluated.

  • logger (logging.Logger | str | None) – The way to print the mAP summary. See mmengine.logging.print_log() for details. Defaults to None.

mmdet.evaluation.functional.print_recall_summary(recalls, proposal_nums, iou_thrs, row_idxs=None, col_idxs=None, logger=None)[源代码]

Print recalls in a table.

参数
  • recalls (ndarray) – calculated from bbox_recalls

  • proposal_nums (ndarray or list) – top N proposals

  • iou_thrs (ndarray or list) – iou thresholds

  • row_idxs (ndarray) – which rows(proposal nums) to print

  • col_idxs (ndarray) – which cols(iou thresholds) to print

  • logger (logging.Logger | str | None) – The way to print the recall summary. See mmengine.logging.print_log() for details. Default: None.

mmdet.evaluation.functional.voc_classes()list[源代码]

Class names of PASCAL VOC.

metrics

mmdet.models

backbones

data_preprocessors

dense_heads

detectors

layers

losses

necks

roi_heads

seg_heads

task_modules

test_time_augs

utils

mmdet.structures

structures

class mmdet.structures.DetDataSample(*, metainfo: Optional[dict] = None, **kwargs)[源代码]

A data structure interface of MMDetection. They are used as interfaces between different components.

The attributes in DetDataSample are divided into several parts:

  • ``proposals``(InstanceData): Region proposals used in two-stage

    detectors.

  • ``gt_instances``(InstanceData): Ground truth of instance annotations.

  • ``pred_instances``(InstanceData): Instances of detection predictions.

  • ``pred_track_instances``(InstanceData): Instances of tracking

    predictions.

  • ``ignored_instances``(InstanceData): Instances to be ignored during

    training/testing.

  • ``gt_panoptic_seg``(PixelData): Ground truth of panoptic

    segmentation.

  • ``pred_panoptic_seg``(PixelData): Prediction of panoptic

    segmentation.

  • ``gt_sem_seg``(PixelData): Ground truth of semantic segmentation.

  • ``pred_sem_seg``(PixelData): Prediction of semantic segmentation.

实际案例

>>> import torch
>>> import numpy as np
>>> from mmengine.structures import InstanceData
>>> from mmdet.structures import DetDataSample
>>> data_sample = DetDataSample()
>>> img_meta = dict(img_shape=(800, 1196),
...                 pad_shape=(800, 1216))
>>> gt_instances = InstanceData(metainfo=img_meta)
>>> gt_instances.bboxes = torch.rand((5, 4))
>>> gt_instances.labels = torch.rand((5,))
>>> data_sample.gt_instances = gt_instances
>>> assert 'img_shape' in data_sample.gt_instances.metainfo_keys()
>>> len(data_sample.gt_instances)
5
>>> print(data_sample)

<DetDataSample(

META INFORMATION

DATA FIELDS gt_instances: <InstanceData(

META INFORMATION pad_shape: (800, 1216) img_shape: (800, 1196)

DATA FIELDS labels: tensor([0.8533, 0.1550, 0.5433, 0.7294, 0.5098]) bboxes: tensor([[9.7725e-01, 5.8417e-01, 1.7269e-01, 6.5694e-01],

[1.7894e-01, 5.1780e-01, 7.0590e-01, 4.8589e-01], [7.0392e-01, 6.6770e-01, 1.7520e-01, 1.4267e-01], [2.2411e-01, 5.1962e-01, 9.6953e-01, 6.6994e-01], [4.1338e-01, 2.1165e-01, 2.7239e-04, 6.8477e-01]])

) at 0x7f21fb1b9190>

) at 0x7f21fb1b9880>
>>> pred_instances = InstanceData(metainfo=img_meta)
>>> pred_instances.bboxes = torch.rand((5, 4))
>>> pred_instances.scores = torch.rand((5,))
>>> data_sample = DetDataSample(pred_instances=pred_instances)
>>> assert 'pred_instances' in data_sample
>>> pred_track_instances = InstanceData(metainfo=img_meta)
>>> pred_track_instances.bboxes = torch.rand((5, 4))
>>> pred_track_instances.scores = torch.rand((5,))
>>> data_sample = DetDataSample(
...    pred_track_instances=pred_track_instances)
>>> assert 'pred_track_instances' in data_sample
>>> data_sample = DetDataSample()
>>> gt_instances_data = dict(
...                        bboxes=torch.rand(2, 4),
...                        labels=torch.rand(2),
...                        masks=np.random.rand(2, 2, 2))
>>> gt_instances = InstanceData(**gt_instances_data)
>>> data_sample.gt_instances = gt_instances
>>> assert 'gt_instances' in data_sample
>>> assert 'masks' in data_sample.gt_instances
>>> data_sample = DetDataSample()
>>> gt_panoptic_seg_data = dict(panoptic_seg=torch.rand(2, 4))
>>> gt_panoptic_seg = PixelData(**gt_panoptic_seg_data)
>>> data_sample.gt_panoptic_seg = gt_panoptic_seg
>>> print(data_sample)

<DetDataSample(

META INFORMATION

DATA FIELDS _gt_panoptic_seg: <BaseDataElement(

META INFORMATION

DATA FIELDS panoptic_seg: tensor([[0.7586, 0.1262, 0.2892, 0.9341],

[0.3200, 0.7448, 0.1052, 0.5371]])

) at 0x7f66c2bb7730>

gt_panoptic_seg: <BaseDataElement(

META INFORMATION

DATA FIELDS panoptic_seg: tensor([[0.7586, 0.1262, 0.2892, 0.9341],

[0.3200, 0.7448, 0.1052, 0.5371]])

) at 0x7f66c2bb7730>

) at 0x7f66c2bb7280> >>> data_sample = DetDataSample() >>> gt_segm_seg_data = dict(segm_seg=torch.rand(2, 2, 2)) >>> gt_segm_seg = PixelData(**gt_segm_seg_data) >>> data_sample.gt_segm_seg = gt_segm_seg >>> assert ‘gt_segm_seg’ in data_sample >>> assert ‘segm_seg’ in data_sample.gt_segm_seg

class mmdet.structures.ReIDDataSample(*, metainfo: Optional[dict] = None, **kwargs)[源代码]

A data structure interface of ReID task.

It’s used as interfaces between different components.

Meta field:
img_shape (Tuple): The shape of the corresponding input image.

Used for visualization.

ori_shape (Tuple): The original shape of the corresponding image.

Used for visualization.

num_classes (int): The number of all categories.

Used for label format conversion.

Data field:

gt_label (LabelData): The ground truth label. pred_label (LabelData): The predicted label. scores (torch.Tensor): The outputs of model.

set_gt_label(value: Union[numpy.ndarray, torch.Tensor, Sequence[numbers.Number], numbers.Number])mmdet.structures.reid_data_sample.ReIDDataSample[源代码]

Set label of gt_label.

set_gt_score(value: torch.Tensor)mmdet.structures.reid_data_sample.ReIDDataSample[源代码]

Set score of gt_label.

class mmdet.structures.TrackDataSample(*, metainfo: Optional[dict] = None, **kwargs)[源代码]

A data structure interface of tracking task in MMDetection. It is used as interfaces between different components.

This data structure can be viewd as a wrapper of multiple DetDataSample to some extent. Specifically, it only contains a property: video_data_samples which is a list of DetDataSample, each of which corresponds to a single frame. If you want to get the property of a single frame, you must first get the corresponding DetDataSample by indexing and then get the property of the frame, such as gt_instances, pred_instances and so on. As for metainfo, it differs from DetDataSample in that each value corresponds to the metainfo key is a list where each element corresponds to information of a single frame.

实际案例

>>> import torch
>>> from mmengine.structures import InstanceData
>>> from mmdet.structures import DetDataSample, TrackDataSample
>>> track_data_sample = TrackDataSample()
>>> # set the 1st frame
>>> frame1_data_sample = DetDataSample(metainfo=dict(
...         img_shape=(100, 100), frame_id=0))
>>> frame1_gt_instances = InstanceData()
>>> frame1_gt_instances.bbox = torch.zeros([2, 4])
>>> frame1_data_sample.gt_instances = frame1_gt_instances
>>> # set the 2nd frame
>>> frame2_data_sample = DetDataSample(metainfo=dict(
...         img_shape=(100, 100), frame_id=1))
>>> frame2_gt_instances = InstanceData()
>>> frame2_gt_instances.bbox = torch.ones([3, 4])
>>> frame2_data_sample.gt_instances = frame2_gt_instances
>>> track_data_sample.video_data_samples = [frame1_data_sample,
...                                         frame2_data_sample]
>>> # set metainfo for track_data_sample
>>> track_data_sample.set_metainfo(dict(key_frames_inds=[0]))
>>> track_data_sample.set_metainfo(dict(ref_frames_inds=[1]))
>>> print(track_data_sample)
<TrackDataSample(

META INFORMATION key_frames_inds: [0] ref_frames_inds: [1]

DATA FIELDS video_data_samples: [<DetDataSample(

META INFORMATION img_shape: (100, 100)

DATA FIELDS gt_instances: <InstanceData(

META INFORMATION

DATA FIELDS bbox: tensor([[0., 0., 0., 0.],

[0., 0., 0., 0.]])

) at 0x7f639320dcd0>

) at 0x7f64bd223340>, <DetDataSample(

META INFORMATION img_shape: (100, 100)

DATA FIELDS gt_instances: <InstanceData(

META INFORMATION

DATA FIELDS bbox: tensor([[1., 1., 1., 1.],

[1., 1., 1., 1.], [1., 1., 1., 1.]])

) at 0x7f64bd128b20>

) at 0x7f64bd1346d0>]

) at 0x7f64bd2237f0> >>> print(len(track_data_sample)) 2 >>> key_data_sample = track_data_sample.get_key_frames() >>> print(key_data_sample[0].frame_id) 0 >>> ref_data_sample = track_data_sample.get_ref_frames() >>> print(ref_data_sample[0].frame_id) 1 >>> frame1_data_sample = track_data_sample[0] >>> print(frame1_data_sample.gt_instances.bbox) tensor([[0., 0., 0., 0.],

[0., 0., 0., 0.]])

>>> # Tensor-like methods
>>> cuda_track_data_sample = track_data_sample.to('cuda')
>>> cuda_track_data_sample = track_data_sample.cuda()
>>> cpu_track_data_sample = track_data_sample.cpu()
>>> cpu_track_data_sample = track_data_sample.to('cpu')
>>> fp16_instances = cuda_track_data_sample.to(
...     device=None, dtype=torch.float16, non_blocking=False,
...     copy=False, memory_format=torch.preserve_format)
clone()mmengine.structures.base_data_element.BaseDataElement[源代码]

Deep copy the current data element.

返回

The copy of current data element.

返回类型

BaseDataElement

cpu()mmengine.structures.base_data_element.BaseDataElement[源代码]

Convert all tensors to CPU in data.

cuda()mmengine.structures.base_data_element.BaseDataElement[源代码]

Convert all tensors to GPU in data.

detach()mmengine.structures.base_data_element.BaseDataElement[源代码]

Detach all tensors in data.

npu()mmengine.structures.base_data_element.BaseDataElement[源代码]

Convert all tensors to NPU in data.

numpy()mmengine.structures.base_data_element.BaseDataElement[源代码]

Convert all tensors to np.ndarray in data.

to(*args, **kwargs)mmengine.structures.base_data_element.BaseDataElement[源代码]

Apply same name function to all tensors in data_fields.

to_tensor()mmengine.structures.base_data_element.BaseDataElement[源代码]

Convert all np.ndarray to tensor in data.

bbox

mask

mmdet.testing

mmdet.visualization

mmdet.utils

class mmdet.utils.AvoidOOM(to_cpu=True, test=False)[源代码]

Try to convert inputs to FP16 and CPU if got a PyTorch’s CUDA Out of Memory error. It will do the following steps:

  1. First retry after calling torch.cuda.empty_cache().

  2. If that still fails, it will then retry by converting inputs

to FP16.

  1. If that still fails trying to convert inputs to CPUs.

In this case, it expects the function to dispatch to CPU implementation.

参数
  • to_cpu (bool) – Whether to convert outputs to CPU if get an OOM error. This will slow down the code significantly. Defaults to True.

  • test (bool) – Skip _ignore_torch_cuda_oom operate that can use lightweight data in unit test, only used in test unit. Defaults to False.

实际案例

>>> from mmdet.utils.memory import AvoidOOM
>>> AvoidCUDAOOM = AvoidOOM()
>>> output = AvoidOOM.retry_if_cuda_oom(
>>>     some_torch_function)(input1, input2)
>>> # To use as a decorator
>>> # from mmdet.utils import AvoidCUDAOOM
>>> @AvoidCUDAOOM.retry_if_cuda_oom
>>> def function(*args, **kwargs):
>>>     return None

```

注解

  1. The output may be on CPU even if inputs are on GPU. Processing

    on CPU will slow down the code significantly.

  2. When converting inputs to CPU, it will only look at each argument

    and check if it has .device and .to for conversion. Nested structures of tensors are not supported.

  3. Since the function might be called more than once, it has to be

    stateless.

retry_if_cuda_oom(func)[源代码]

Makes a function retry itself after encountering pytorch’s CUDA OOM error.

The implementation logic is referred to https://github.com/facebookresearch/detectron2/blob/main/detectron2/utils/memory.py

参数

func – a stateless callable that takes tensor-like objects as arguments.

返回

a callable which retries func if OOM is encountered.

返回类型

func

mmdet.utils.all_reduce_dict(py_dict, op='sum', group=None, to_float=True)[源代码]

Apply all reduce function for python dict object.

The code is modified from https://github.com/Megvii- BaseDetection/YOLOX/blob/main/yolox/utils/allreduce_norm.py.

NOTE: make sure that py_dict in different ranks has the same keys and the values should be in the same shape. Currently only supports nccl backend.

参数
  • py_dict (dict) – Dict to be applied all reduce op.

  • op (str) – Operator, could be ‘sum’ or ‘mean’. Default: ‘sum’

  • group (torch.distributed.group, optional) – Distributed group, Default: None.

  • to_float (bool) – Whether to convert all values of dict to float. Default: True.

返回

reduced python dict object.

返回类型

OrderedDict

mmdet.utils.allreduce_grads(params, coalesce=True, bucket_size_mb=- 1)[源代码]

Allreduce gradients.

参数
  • params (list[torch.Parameters]) – List of parameters of a model

  • coalesce (bool, optional) – Whether allreduce parameters as a whole. Defaults to True.

  • bucket_size_mb (int, optional) – Size of bucket, the unit is MB. Defaults to -1.

mmdet.utils.collect_env()[源代码]

Collect the information of the running environments.

mmdet.utils.compat_cfg(cfg)[源代码]

This function would modify some filed to keep the compatibility of config.

For example, it will move some args which will be deprecated to the correct fields.

mmdet.utils.find_latest_checkpoint(path, suffix='pth')[源代码]

Find the latest checkpoint from the working directory.

参数
  • path (str) – The path to find checkpoints.

  • suffix (str) – File extension. Defaults to pth.

返回

File path of the latest checkpoint.

返回类型

latest_path(str | None)

引用

1

https://github.com/microsoft/SoftTeacher /blob/main/ssod/utils/patch.py

mmdet.utils.get_caller_name()[源代码]

Get name of caller method.

mmdet.utils.get_test_pipeline_cfg(cfg: Union[str, mmengine.config.config.ConfigDict])mmengine.config.config.ConfigDict[源代码]

Get the test dataset pipeline from entire config.

参数

cfg (str or ConfigDict) – the entire config. Can be a config file or a ConfigDict.

返回

the config of test dataset.

返回类型

ConfigDict

mmdet.utils.imshow_mot_errors(*args, backend: str = 'cv2', **kwargs)[源代码]

Show the wrong tracks on the input image.

参数

backend (str, optional) – Backend of visualization. Defaults to ‘cv2’.

mmdet.utils.log_img_scale(img_scale, shape_order='hw', skip_square=False)[源代码]

Log image size.

参数
  • img_scale (tuple) – Image size to be logged.

  • shape_order (str, optional) – The order of image shape. ‘hw’ for (height, width) and ‘wh’ for (width, height). Defaults to ‘hw’.

  • skip_square (bool, optional) – Whether to skip logging for square img_scale. Defaults to False.

返回

Whether to have done logging.

返回类型

bool

mmdet.utils.reduce_mean(tensor)[源代码]

“Obtain the mean of tensor on different GPUs.

mmdet.utils.register_all_modules(init_default_scope: bool = True)None[源代码]

Register all modules in mmdet into the registries.

参数

init_default_scope (bool) – Whether initialize the mmdet default scope. When init_default_scope=True, the global default scope will be set to mmdet, and all registries will build modules from mmdet’s registry node. To understand more about the registry, please refer to https://github.com/open-mmlab/mmengine/blob/main/docs/en/tutorials/registry.md Defaults to True.

mmdet.utils.replace_cfg_vals(ori_cfg)[源代码]

Replace the string “${key}” with the corresponding value.

Replace the “${key}” with the value of ori_cfg.key in the config. And support replacing the chained ${key}. Such as, replace “${key0.key1}” with the value of cfg.key0.key1. Code is modified from `vars.py < https://github.com/microsoft/SoftTeacher/blob/main/ssod/utils/vars.py>`_ # noqa: E501

参数

ori_cfg (mmengine.config.Config) – The origin config with “${key}” generated from a file.

返回

The config with “${key}” replaced by the corresponding value.

返回类型

updated_cfg [mmengine.config.Config]

mmdet.utils.setup_cache_size_limit_of_dynamo()[源代码]

Setup cache size limit of dynamo.

Note: Due to the dynamic shape of the loss calculation and post-processing parts in the object detection algorithm, these functions must be compiled every time they are run. Setting a large value for torch._dynamo.config.cache_size_limit may result in repeated compilation, which can slow down training and testing speed. Therefore, we need to set the default value of cache_size_limit smaller. An empirical value is 4.

mmdet.utils.setup_multi_processes(cfg)[源代码]

Setup multi-processing environment variables.

mmdet.utils.split_batch(img, img_metas, kwargs)[源代码]

Split data_batch by tags.

Code is modified from <https://github.com/microsoft/SoftTeacher/blob/main/ssod/utils/structure_utils.py> # noqa: E501

参数
  • img (Tensor) – of shape (N, C, H, W) encoding input images. Typically these should be mean centered and std scaled.

  • img_metas (list[dict]) – List of image info dict where each dict has: ‘img_shape’, ‘scale_factor’, ‘flip’, and may also contain ‘filename’, ‘ori_shape’, ‘pad_shape’, and ‘img_norm_cfg’. For details on the values of these keys, see mmdet.datasets.pipelines.Collect.

  • kwargs (dict) – Specific to concrete implementation.

返回

a dict that data_batch splited by tags,

such as ‘sup’, ‘unsup_teacher’, and ‘unsup_student’.

返回类型

data_groups (dict)

mmdet.utils.sync_random_seed(seed=None, device='cuda')[源代码]

Make sure different ranks share the same seed.

All workers must call this function, otherwise it will deadlock. This method is generally used in DistributedSampler, because the seed should be identical across all processes in the distributed group.

In distributed sampling, different ranks should sample non-overlapped data in the dataset. Therefore, this function is used to make sure that each rank shuffles the data indices in the same order based on the same seed. Then different ranks could use different indices to select non-overlapped data from the same data list.

参数
  • seed (int, Optional) – The seed. Default to None.

  • device (str) – The device where the seed will be put on. Default to ‘cuda’.

返回

Seed to be used.

返回类型

int

mmdet.utils.update_data_root(cfg, logger=None)[源代码]

Update data root according to env MMDET_DATASETS.

If set env MMDET_DATASETS, update cfg.data_root according to MMDET_DATASETS. Otherwise, using cfg.data_root as default.

参数
  • cfg (Config) – The model config need to modify

  • logger (logging.Logger | str | None) – the way to print msg

Read the Docs v: stable
Versions
latest
stable
3.x
v3.3.0
v3.2.0
v3.1.0
v3.0.0
v2.28.2
v2.28.1
v2.28.0
v2.27.0
v2.26.0
v2.25.3
v2.25.2
v2.25.1
v2.25.0
v2.24.1
v2.24.0
v2.23.0
v2.22.0
v2.21.0
v2.20.0
v2.19.1
v2.19.0
v2.18.1
v2.18.0
v2.17.0
v2.16.0
v2.15.1
v2.15.0
v2.14.0
v2.13.0
dev-3.x
dev
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.