A base data interface that supports Tensor-like and dict-like operations. A typical data elements refer to predicted results or ground truth labels on a task, such as predicted bboxes, instance masks, semantic segmentation masks, etc. Because groundtruth labels and predicted results
| 7 | |
| 8 | |
| 9 | class BaseDataElement: |
| 10 | """A base data interface that supports Tensor-like and dict-like |
| 11 | operations. |
| 12 | |
| 13 | A typical data elements refer to predicted results or ground truth labels |
| 14 | on a task, such as predicted bboxes, instance masks, semantic |
| 15 | segmentation masks, etc. Because groundtruth labels and predicted results |
| 16 | often have similar properties (for example, the predicted bboxes and the |
| 17 | groundtruth bboxes), MMEngine uses the same abstract data interface to |
| 18 | encapsulate predicted results and groundtruth labels, and it is recommended |
| 19 | to use different name conventions to distinguish them, such as using |
| 20 | ``gt_instances`` and ``pred_instances`` to distinguish between labels and |
| 21 | predicted results. Additionally, we distinguish data elements at instance |
| 22 | level, pixel level, and label level. Each of these types has its own |
| 23 | characteristics. Therefore, MMEngine defines the base class |
| 24 | ``BaseDataElement``, and implement ``InstanceData``, ``PixelData``, and |
| 25 | ``LabelData`` inheriting from ``BaseDataElement`` to represent different |
| 26 | types of ground truth labels or predictions. |
| 27 | |
| 28 | Another common data element is sample data. A sample data consists of input |
| 29 | data (such as an image) and its annotations and predictions. In general, |
| 30 | an image can have multiple types of annotations and/or predictions at the |
| 31 | same time (for example, both pixel-level semantic segmentation annotations |
| 32 | and instance-level detection bboxes annotations). All labels and |
| 33 | predictions of a training sample are often passed between Dataset, Model, |
| 34 | Visualizer, and Evaluator components. In order to simplify the interface |
| 35 | between components, we can treat them as a large data element and |
| 36 | encapsulate them. Such data elements are generally called XXDataSample in |
| 37 | the OpenMMLab. Therefore, Similar to `nn.Module`, the `BaseDataElement` |
| 38 | allows `BaseDataElement` as its attribute. Such a class generally |
| 39 | encapsulates all the data of a sample in the algorithm library, and its |
| 40 | attributes generally are various types of data elements. For example, |
| 41 | MMDetection is assigned by the BaseDataElement to encapsulate all the data |
| 42 | elements of the sample labeling and prediction of a sample in the |
| 43 | algorithm library. |
| 44 | |
| 45 | The attributes in ``BaseDataElement`` are divided into two parts, |
| 46 | the ``metainfo`` and the ``data`` respectively. |
| 47 | |
| 48 | - ``metainfo``: Usually contains the |
| 49 | information about the image such as filename, |
| 50 | image_shape, pad_shape, etc. The attributes can be accessed or |
| 51 | modified by dict-like or object-like operations, such as |
| 52 | ``.`` (for data access and modification), ``in``, ``del``, |
| 53 | ``pop(str)``, ``get(str)``, ``metainfo_keys()``, |
| 54 | ``metainfo_values()``, ``metainfo_items()``, ``set_metainfo()`` (for |
| 55 | set or change key-value pairs in metainfo). |
| 56 | |
| 57 | - ``data``: Annotations or model predictions are |
| 58 | stored. The attributes can be accessed or modified by |
| 59 | dict-like or object-like operations, such as |
| 60 | ``.``, ``in``, ``del``, ``pop(str)``, ``get(str)``, ``keys()``, |
| 61 | ``values()``, ``items()``. Users can also apply tensor-like |
| 62 | methods to all :obj:`torch.Tensor` in the ``data_fields``, |
| 63 | such as ``.cuda()``, ``.cpu()``, ``.numpy()``, ``.to()``, |
| 64 | ``to_tensor()``, ``.detach()``. |
| 65 | |
| 66 | Args: |
no outgoing calls
searching dependent graphs…