code: def to_onehot(
      indices: torch.Tensor, num_classes: int
  ) -> torch.Tensor:
      """Convert a tensor of indices of any shape `(N, ...)` to a
      tensor of one-hot indicators of shape `(N, num_classes, ...)` and of type uint8. Output's device is equal to the
      input's device`.
  
      Args:
          indices: input tensor to convert.
          num_classes: number of classes for one-hot tensor.
  
      .. versionchanged:: 0.4.3
          This functions is now torchscriptable.
      """
      new_shape = (indices.shape[0], num_classes) + indices.shape[1:]
      onehot = torch.zeros(
          new_shape, dtype=torch.uint8, device=indices.device
      )
      return onehot.scatter_(1, indices.unsqueeze(1), 1)
  
imports: import collections.abc
  import functools
  import hashlib
  import logging
  import random
  import shutil
  import warnings
  from pathlib import Path
  from typing import Any, Callable, cast, Dict, List, Optional, TextIO, Tuple, Type, TypeVar, Union
  import torch
label_desc: Use image node_id 6 for calling a global function with example usage: to_onehot(indices, num_classes) and returns: onehot