one_hot

dragon.vm.torch.one_hot(
  input,
  depth,
  on_value=1,
  off_value=0
)[source]

Return the one-hot representation for input.

\[\text{out}_{ij} = \begin{cases} 0, & \text{ if } \text{input}_{i} \neq j \\ 1, & \text{ otherwise } \end{cases} \]

The max value of input, i.e., the depth should be specified:

index = torch.tensor([0, 1, 2, 3])
print(torch.one_hot(index, depth=5))  # depth >= 4 will be ok

Use on_value or off_value custom filling:

index = torch.tensor([0, 1, 2, 3])
print(torch.one_hot(index, depth=4, on_value=2, off_value=3))
Parameters:
  • input (dragon.vm.torch.Tensor) – The input tensor.
  • depth (int) – The depth of channels.
  • on_value (number, optional, default=1) – The value for equal branch.
  • off_value (number, optional, default=0) – The value for not-equal branch.
Returns:

dragon.vm.torch.Tensor – The output tensor.