mmedit.structures
¶
Package Contents¶
Classes¶
A data structure interface of MMEditing. They are used as interfaces |
|
Data structure for pixel-level annnotations or predictions. |
- class mmedit.structures.EditDataSample(*, metainfo: Optional[dict] = None, **kwargs)[source]¶
Bases:
mmengine.structures.BaseDataElement
A data structure interface of MMEditing. They are used as interfaces between different components.
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, PixelData >>> data_sample = EditDataSample() >>> img_meta = dict(img_shape=(800, 1196, 3)) >>> img = torch.rand((3, 800, 1196)) >>> gt_img = PixelData(data=img, metainfo=img_meta) >>> data_sample.gt_img = gt_img >>> assert 'img_shape' in data_sample.gt_img.metainfo_keys() <EditDataSample( META INFORMATION DATA FIELDS _gt_img: <PixelData( META INFORMATION img_shape: (800, 1196, 3) DATA FIELDS data: tensor([[[0.8069, 0.4279, ..., 0.6603, 0.0292], ..., [0.8139, 0.0908, ..., 0.4964, 0.9672]]]) ) at 0x1f6ae000af0> gt_img: <PixelData( META INFORMATION img_shape: (800, 1196, 3) DATA FIELDS data: tensor([[[0.8069, 0.4279, ..., 0.6603, 0.0292], ..., [0.8139, 0.0908, ..., 0.4964, 0.9672]]]) ) at 0x1f6ae000af0> ) at 0x1f6a5a99a00>
- property gt_img: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch gt_img in PixelData.
- Returns
data element
- Return type
- property gt_samples: EditDataSample¶
This is the function to fetch gt_samples.
- Returns
gt samples.
- Return type
- property noise: torch.Tensor¶
This is the function to fetch noise.
- Returns
noise.
- Return type
torch.Tensor
- property pred_img: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch pred_img in PixelData.
- Returns
data element
- Return type
- property fake_img: Union[mmedit.structures.pixel_data.PixelData, torch.Tensor]¶
This is the function to fetch fake_img.
- Returns
The fake img.
- Return type
Union[PixelData, Tensor]
- property img_lq: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch img_lq in PixelData.
- Returns
data element
- Return type
- property ref_img: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch ref_img.
- Returns
data element
- Return type
- property ref_lq: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch ref_lq.
- Returns
data element
- Return type
- property gt_unsharp: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch gt_unsharp in PixelData.
- Returns
data element
- Return type
- property mask: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch mask.
- Returns
data element
- Return type
- property gt_heatmap: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch gt_heatmap.
- Returns
data element
- Return type
- property pred_heatmap: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch pred_heatmap.
- Returns
data element
- Return type
- property trimap: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch trimap.
- Returns
data element
- Return type
- property gt_alpha: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch gt_alpha.
- Returns
data element
- Return type
- property pred_alpha: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch pred_alpha.
- Returns
data element
- Return type
- property gt_fg: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch gt_fg.
- Returns
data element
- Return type
- property pred_fg: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch pred_fg.
- Returns
_description_
- Return type
- property gt_bg: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch gt_bg.
- Returns
data element
- Return type
- property pred_bg: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch pred_bg in PixelData.
- Returns
data element
- Return type
- property gt_merged: mmedit.structures.pixel_data.PixelData¶
This is the function to fetch gt_merged in PixelData.
- Returns
_description_
- Return type
- property sample_model: str¶
This is the function to fetch sample model.
- Returns
Mode of Sample model.
- Return type
str
- property ema: EditDataSample¶
This is the function to fetch ema results.
- Returns
Results of the ema model.
- Return type
- property orig: EditDataSample¶
This is the function to fetch original results.
- Returns
Results of the ema model.
- Return type
- property gt_label¶
This the function to fetch gt label.
- Returns
gt label.
- Return type
LabelData
- gt_img()¶
This is the function to fetch gt_img.
- gt_samples()¶
This is the function to delete gt_samples.
- noise()¶
This is the functionto delete noise.
- pred_img()¶
This is the function to fetch pred_img.
- fake_img()¶
This is the function to delete fake_img.
- img_lq()¶
This is the function to delete img_lq.
- ref_img()¶
This is the function to fetch ref_img.
- ref_lq()¶
This is the function to delete ref_lq.
- gt_unsharp()¶
This is the function to delete gt_unsharp.
- mask()¶
This is the function to delete mask.
- gt_heatmap()¶
This is the function to delete gt_heatmap.
- pred_heatmap()¶
This is the function to fetch pred_heatmap.
- trimap()¶
This is the function to delete trimap.
- gt_alpha()¶
This is the function to delete gt_alpha.
- pred_alpha()¶
This is the function to delete pred_alpha.
- gt_fg()¶
This is the function to delete gt_fg.
- pred_fg()¶
This is the function to delete pred_fg.
- gt_bg()¶
This is the function to delete gt_bg.
- pred_bg()¶
This is the function to fetch pred_bg.
- gt_merged()¶
This is the function to fetch gt_merged.
- sample_model()¶
This is the function to delete sample model.
- ema()¶
This is the function to delete ema results.
- orig()¶
This is the function to delete ema results.
- set_gt_label(value: Union[numpy.ndarray, torch.Tensor, Sequence[numbers.Number], numbers.Number]) EditDataSample [source]¶
Set label of
gt_label
.
- gt_label()¶
This is the function to delete gt label.
- class mmedit.structures.PixelData(*, metainfo: Optional[dict] = None, **kwargs)[source]¶
Bases:
mmengine.structures.PixelData
Data structure for pixel-level annnotations or predictions.
- Different from parent class:
Support value.ndim == 4 for frames.
All data items in
data_fields
ofPixelData
meet the following requirements:They all have 3 dimensions in orders of channel, height, and width.
They should have the same height and width.
Examples
>>> metainfo = dict( ... img_id=random.randint(0, 100), ... img_shape=(random.randint(400, 600), random.randint(400, 600))) >>> image = np.random.randint(0, 255, (4, 20, 40)) >>> featmap = torch.randint(0, 255, (10, 20, 40)) >>> pixel_data = PixelData(metainfo=metainfo, ... image=image, ... featmap=featmap) >>> print(pixel_data) >>> (20, 40)
>>> # slice >>> slice_data = pixel_data[10:20, 20:40] >>> assert slice_data.shape == (10, 10) >>> slice_data = pixel_data[10, 20] >>> assert slice_data.shape == (1, 1)
- __setattr__(name: str, value: Union[torch.Tensor, numpy.ndarray])[source]¶
Set attributes of
PixelData
.If the dimension of value is 2 and its shape meet the demand, it will automatically expend its channel-dimension.
- Parameters
name (str) – The key to access the value, stored in PixelData.
value (Union[torch.Tensor, np.ndarray]) – The value to store in. The type of value must be torch.Tensor or np.ndarray, and its shape must meet the requirements of PixelData.