RuntimeError: Class values must be smaller than num_classes.


RuntimeError: Class values must be smaller than num_classes.

torch 라이브러리에는 one_hot 이라는 함수가 있습니다. numpy.argmax 를 사용하여 한 채널로 된 행렬을 다시 다채널로 바꾸는 등...에 사용합니다. 말로 설명하려니 힘드네요... 가령, 1 x 100 x 100 (C x H x W) 의 0~6 값으로 채워져있는 행렬이 있으면, 값에 따라 7 x 100 x 100으로 변환해줍니다. 에러 메세지가 발생하도록 만들어 볼게요. >>> import torch >>> x = torch.arange(0,8) >>> x tensor([0, 1, 2, 3, 4, 5, 6, 7]) >>> torch.nn.functional.one_hot(x) tensor([[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0], [...


#one_hot #pytorch #RuntimeError #딥러닝

원문링크 : RuntimeError: Class values must be smaller than num_classes.