2017-11-14 1 views
0

다음과 같이 여러 이미지를 저장했습니다.Pytorch 이미지를 텐서로 변환하는 방법

for name in image_names: 
    images.append(cv2.imread("./train_mini/"+name)) 

그리고 나중에 CNN 교육에서 이러한 이미지를 사용하고 싶습니다.

“RuntimeError: can’t convert a given np.ndarray to a tensor - it has an invalid type. The only supported types are: double, float, int64, int32, and uint8.” 

그래서 나는 이미지의 데이터 유형을 체크하고 "개체"이었다 : 나는 아래와 같이 "torch.utils.data.TensorDataset"에서 그 데이터를 저장 그러나, 그것은 오류가 표시됩니다.

train = torch.utils.data.TensorDataset(torch.from_numpy(X_train), torch.from_numpy(Y_train)) 

이 문제를 어떻게 해결할 수 있습니까? 나는 완전히 붙어있어 ...

+0

[읽는 방법] (https://stackoverflow.com/questions/3386259/how-to-make-a-multidimension-numpy-array-with-a-varying-row-size) 모양이 다른 배열의 목록입니다. 또한'TensorDataset'에 배열 목록을 전달할 수 있으므로'torch.from_numpy()'를 실행할 필요가 없습니다. –

+1

감사합니다. 이는 설치 이미지 크기가 다양했기 때문입니다. –

답변

0

나는 Pytorsh가 ndarray의 ndarray를 지원하지 않는다고 생각한다. 이것이 왜이 오류를 보게되는지이다.

관련 문제