一些代码的实验

1、1-hot encodes a tensor

点击查看代码
def to_categorical(y, num_classes):
    """ 1-hot encodes a tensor """
    new_y = torch.eye(num_classes)[y.cpu().data.numpy(),]
    if (y.is_cuda):
        return new_y.cuda()
    return new_y

posted @ 2022-01-10 19:30  原来是只呆燕  阅读(54)  评论(0)    收藏  举报