mmedit.structures
¶
Package Contents¶
Classes¶
A data structure interface of MMEditing. They are used as interfaces |
- class mmedit.structures.EditDataSample(*, metainfo: Optional[dict] = None, **kwargs)[源代码]¶
Bases:
mmengine.structures.BaseDataElement
A data structure interface of MMEditing. They are used as interfaces between different components, e.g., model, visualizer, evaluator, etc. Typically, EditDataSample contains all the information and data from ground-truth and predictions.
- EditDataSample inherits from BaseDataElement. See more details in:
https://mmengine.readthedocs.io/en/latest/advanced_tutorials/data_element.html Specifically, an instance of BaseDataElement consists of two components, -
metainfo
, which contains some meta information,e.g., img_shape, img_id, etc.
data
, which contains the data used in the loop.
The attributes in
EditDataSample
are divided into several parts:gt_img
: Ground truth image(s).pred_img
: Image(s) of model predictions.ref_img
: Reference image(s).mask
: Mask in Inpainting.trimap
: Trimap in Matting.gt_alpha
: Ground truth alpha image in Matting.pred_alpha
: Predicted alpha image in Matting.gt_fg
: Ground truth foreground image in Matting.pred_fg
: Predicted foreground image in Matting.gt_bg
: Ground truth background image in Matting.pred_bg
: Predicted background image in Matting.gt_merged
: Ground truth merged image in Matting.
Examples:
>>> import torch >>> import numpy as np >>> from mmedit.structures import EditDataSample >>> img_meta = dict(img_shape=(800, 1196, 3)) >>> img = torch.rand((3, 800, 1196)) >>> data_sample = EditDataSample(gt_img=img, metainfo=img_meta) >>> assert 'img_shape' in data_sample.metainfo_keys() <EditDataSample( META INFORMATION img_shape: (800, 1196, 3) DATA FIELDS gt_img: tensor(...) ) at 0x1f6a5a99a00>
- property gt_label¶
This the function to fetch gt label.
- 返回
gt label.
- 返回类型
LabelData
- META_KEYS¶
- DATA_KEYS¶
- set_predefined_data(data: dict) None ¶
set or change pre-defined key-value pairs in
data_field
by parameterdata
.- 参数
data (dict) – A dict contains annotations of image or model predictions.
- set_tensor_data(data: dict) None ¶
convert input data to tensor, and then set or change key-value pairs in
data_field
by parameterdata
.- 参数
data (dict) – A dict contains annotations of image or model predictions.
- set_gt_label(value: Union[numpy.ndarray, torch.Tensor, Sequence[numbers.Number], numbers.Number]) EditDataSample ¶
Set label of
gt_label
.
- gt_label()¶
Delete gt label.
- classmethod stack(data_samples: Sequence[EditDataSample]) EditDataSample ¶
Stack a list of data samples to one. All tensor fields will be stacked at first dimension. Otherwise the values will be saved in a list.
- 参数
data_samples (Sequence['EditDataSample']) – A sequence of EditDataSample to stack.
- 返回
The stacked data sample.
- 返回类型
- split(allow_nonseq_value: bool = False) Sequence[EditDataSample] ¶
Split a sequence of data sample in the first dimension.
- 参数
allow_nonseq_value (bool) – Whether allow non-sequential data in split operation. If True, non-sequential data will be copied for all split data samples. Otherwise, an error will be raised. Defaults to False.
- 返回
The list of data samples after splitting.
- 返回类型
Sequence[EditDataSample]
- __len__()¶
Get the length of the data sample.