torchvision_sunner.transforms.categorical¶
Categorical API is the advance topic in this package. If you want to realize the whole usage, please refer to the tutorial here. This pages only shows the parameters. You only need to import the same module and you can start:
import torchvision_sunner.transforms as sunnertransforms
torchvision_sunner.transforms.categorical.getCategoricalMapping [source]¶
This function will obtain the pallete object. Here is the usage:
pallete = sunnertransforms.getCategoricalMapping(loader, path = 'pallete.json')
- Notice : You should make sure the tensor data range is
[0, 255], and the rank format isBHWC. You can useUnNormalizeandTransposefunction to achieve the requirement!!!! Check out the example to see the detail usage.
Parameters¶
- loader (torch.utils.data.DataLoader) - The data loader. You should create the loader first which only contains the RGB colorful label domain.
- path (str) -The path of the pallete record file you want to store.
Return¶
The list of pallete. In the usual usage, we only need the single pallete. Thus use pallete[0] to get the pallete object.
torchvision_sunner.transforms.categorical.CategoricalTranspose [source]¶
Transfer the tensor into particular representation. Here is the usage:
# Get the pallete object first
pallete = sunnertransforms.getCategoricalMapping(loader, path = 'pallete.json')
# Create transfer operator
goto_op = sunnertransforms.CategoricalTranspose(pallete = pallete, direction = sunnertransforms.COLOR2ONEHOT)
back_op = sunnertransforms.CategoricalTranspose(pallete = pallete, direction = sunnertransforms.ONEHOT2COLOR)
# Transfer!
label_index_format = goto_op(label)
label_color_format = back_op(label_index_format)
- Notice : You should transfer the tensor into rank format
BCHWfirst. - Notice : You should normalize the tensor into the range of [-1, 1]
Parameters¶
- pallete (OrderDict) - The pallete object.
- direction (int) - The direction you want to transfer. We provide for six direction:
sunnertransforms.ONEHOT2INDEX: Transfer the tensor from one-hot format into index formatsunnertransforms.INDEX2ONEHOT: Transfer the tensor from index format into one-hot formatsunnertransforms.ONEHOT2COLOR: Transfer the tensor from one-hot format into RGB colorful formatsunnertransforms.COLOR2ONEHOT: Transfer the tensor from RGB colorful format into one-hot formatsunnertransforms.INDEX2COLOR: Transfer the tensor from index format into RGB colorful formatsunnertransforms.COLOR2INDEX: Transfer the tensor from RGB colorful format into index format
- index_default (int) - The index of default while the color is not found in pallete
Return¶
The tensor with corresponding format