[pytorch] ValueError: Expected input batch_size (_) to match target batch_size (_)


[pytorch] ValueError: Expected input batch_size (_) to match target batch_size (_)

#python #pytorch #RNN 안녕하세요 오늘의 에러는 ValueError: Expected input batch_size (_) to match target batch_size (_) 이고 발생 원인과 해결 방안을 알아보겠습니다. 발생원인 저의 경우에는 input size가 3차원이고, [배치, 문장길이, 사이즈]였는데요. 여기서 문장길이가 지정된 모델의 사이즈랑 안맞아서 발생했습니다. 즉, 모델에서 요구하는 2차원의 값은 20이었는데, 문장길이가 19였던 문제입니다. 해결방안 이를 해결하기 위하여 입력값의 shape를 확인해 보면서 어디서 틀어지는지 확인하는게 가장 좋았습니다. 이런 함수를 하나 써도 금방 잡힐 것 같네요. if ( (target.shape[0],target.shape[1]) != (2,20)): print('error') print(source.shape) print(target.shape)...


#python #pytorch #RNN

원문링크 : [pytorch] ValueError: Expected input batch_size (_) to match target batch_size (_)