mmagic.models.utils.tensor_utils
¶
Module Contents¶
Functions¶
|
Get 1-channel unknown area tensor from the 3 or 1-channel trimap tensor. |
|
Normalize vector with it's lengths at the last dimension. If vector is |
- mmagic.models.utils.tensor_utils.get_unknown_tensor(trimap, unknown_value=128 / 255)[source]¶
Get 1-channel unknown area tensor from the 3 or 1-channel trimap tensor.
- Parameters
trimap (Tensor) – Tensor with shape (N, 3, H, W) or (N, 1, H, W).
unknown_value (float) – Scalar value indicating unknown region in trimap. If trimap is pre-processed using ‘rescale_to_zero_one’, then 0 for bg, 128/255 for unknown, 1 for fg, and unknown_value should set to 128 / 255. If trimap is pre-processed by
FormatTrimap(to_onehot=False)()
, then 0 for bg, 1 for unknown, 2 for fg and unknown_value should set to 1. If trimap is pre-processed byFormatTrimap(to_onehot=True)()
, then trimap is 3-channeled, and this value is not used.
- Returns
Unknown area mask of shape (N, 1, H, W).
- Return type
Tensor
- mmagic.models.utils.tensor_utils.normalize_vecs(vectors: torch.Tensor) torch.Tensor [source]¶
Normalize vector with it’s lengths at the last dimension. If vector is two-dimension tensor, this function is same as L2 normalization.
- Parameters
vector (torch.Tensor) – Vectors to be normalized.
- Returns
Vectors after normalization.
- Return type
torch.Tensor