mindspore.dataset.transforms.py_transforms.OneHotOp

class mindspore.dataset.transforms.py_transforms.OneHotOp(num_classes, smoothing_rate=0.0)[source]

Apply one hot encoding transformation to the input label, make label be more smoothing and continuous.

Parameters
  • num_classes (int) – Number of classes of objects in dataset. It should be larger than the largest label number in the dataset.

  • smoothing_rate (float, optional) – Adjustable hyperparameter for label smoothing level. (Default=0.0 means no smoothing is applied.)

Examples

>>> # Assume that dataset has 10 classes, thus the label ranges from 0 to 9
>>> transforms_list = [py_transforms.OneHotOp(num_classes=10, smoothing_rate=0.1)]
>>> transform = py_transforms.Compose(transforms_list)
>>> mnist_dataset = mnist_dataset.map(input_columns=["label"], operations=transform)