import torch


def label2one_hot_torch(labels, C=14):
    """ Converts an integer label torch.autograd.Variable to a one-hot Variable.

    Args:
      labels(tensor) : segmentation label
      C (integer) : number of classes in labels

    Returns:
      target (tensor) : one-hot vector of the input label

    Shape:
      labels: (B, 1, H, W)
      target: (B, N, H, W)
    """
    b,_, h, w = labels.shape
    one_hot = torch.zeros(b, C, h, w, dtype=torch.long).to(labels)
    target = one_hot.scatter_(1, labels.type(torch.long).data, 1) #require long type

    return target.type(torch.float32)