confusion_matrix: ValueError: not enough values to unpack (expected 4, got 1)
·
Error Note
sklearn의 confusion_matrix 함수를 다음과 같이 사용시 예측 라벨과 정답 라벨이 모두 일치할 때 발생하는 에러입니다. TN, FP, FN, TP = confusion_matrix(target, pred).ravel() 전체 에러 문구는 아래와 같습니다. ValueError: not enough values to unpack (expected 4, got 1) confusion_matrix는 아래처럼 예측 라벨과 정답 라벨이 모두 일치할 때 element 1개의 1차원 행렬을 반환합니다. >>> confusion_matrix([1, 1, 1, 1], [1, 1, 1, 1]).ravel() array([4], dtype=int64) 이런 경우에 반환 값은 1개인데 반환값을 받을 변수로 4개..
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (9969,) + inhomogeneous part.
·
Error Note
- 전체 에러 문구 ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (9969,) + inhomogeneous part. list 를 numpy 로 변환할 때 발생하는 에러입니다. x = [[1, 2], [3, 4, 5]] 처럼 list내에 서로 다른 길이의 리스트들이 존재하면 변환이 불가능하기 때문에 발생하는 에러입니다. - 해결방법 리스트들의 길이를 동일하게 맞춰주면 됩니다!
importerror: cannot import name 'builder' from 'google.protobuf.internal' (/opt/conda/lib/python3.10/site-packages/google/protobuf/internal/__init__.py)
·
Error Note
- 전체 에러 문구 importerror: cannot import name 'builder' from 'google.protobuf.internal' (/opt/conda/lib/python3.10/site-packages/google/protobuf/internal/__init__.py) - 해결 방법 pip install --upgrade protobuf
ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 512, 1, 1])
·
Error Note
- 전체 에러 문구 ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 512, 1, 1]) 마지막 batch를 돌 때 데이터가 하나 밖에 남지 않아 발생하는 에러였습니다. - 해결 방법 데이터 갯수에 따라 마지막 batch에서 데이터가 하나만 남지 않도록 batch size를 적절히 조정해주어야 합니다.