mindspore.dataset.transforms.c_transforms.OneHot

class mindspore.dataset.transforms.c_transforms.OneHot(num_classes)[source]

Tensor operation to apply one hot encoding.

Parameters

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

Raises

RuntimeError – feature size is bigger than num_classes.

Examples

>>> # Assume that dataset has 10 classes, thus the label ranges from 0 to 9
>>> onehot_op = c_transforms.OneHot(num_classes=10)
>>> mnist_dataset = mnist_dataset.map(operations=onehot_op, input_columns=["label"])