mmedit.structures.edit_data_sample¶
Module Contents¶
Classes¶
A data structure interface of MMEditing. They are used as interfaces |
Functions¶
|
Convert label of various python types to |
|
Check whether input is a splitable variable. |
- mmedit.structures.edit_data_sample.format_label(value: Union[torch.Tensor, numpy.ndarray, Sequence, int], num_classes: int = None) mmengine.structures.LabelData[源代码]¶
Convert label of various python types to
mmengine.LabelData.Supported types are:
numpy.ndarray,torch.Tensor,Sequence,int.- 参数
value (torch.Tensor | numpy.ndarray | Sequence | int) – Label value.
num_classes (int, optional) – The number of classes. If not None, set it to the metainfo. Defaults to None.
- 返回
The foramtted label data.
- 返回类型
mmengine.LabelData
- mmedit.structures.edit_data_sample.is_splitable_var(var: Any) bool[源代码]¶
Check whether input is a splitable variable.
- 参数
var (Any) – The input variable to check.
- 返回
Whether input variable is a splitable variable.
- 返回类型
bool
- class mmedit.structures.edit_data_sample.EditDataSample(*, metainfo: Optional[dict] = None, **kwargs)[源代码]¶
Bases:
mmengine.structures.BaseDataElementA 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
EditDataSampleare 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>
- set_predefined_data(data: dict) None[源代码]¶
set or change pre-defined key-value pairs in
data_fieldby 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_fieldby 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.
- 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]