728x90
반응형

 

 

pytorch 에서의 input tensor 에서 주어진 k 값에 따라 가장 큰 값 k 개를 찾는 함수이다.

 

image classification 에서 train/validation 시 accuracy 측정할 때 자주 사용된다.

 

아래와 같은 에러는 TopK 범위를 잘못 지정하였을 때 나는 에러이다. 

 

RuntimeError: invalid argument 5: k not in range for dimension at /pytorch/aten/src/THC/generic/THCTensorTopK.cu:26

RuntimeError: invalid argument 5: k not in range for dimension at /pytorch/aten/src/THC/generic/THCTensorTopK.cu:26

 

 

당연한 이야기 이지만 TopK 범위는 class 갯수보다 적거나 같은 수여야 한다. 

 

 

 

 

 

 

 

 

 

 

 

참고자료 1 : stackoverflow.com/questions/63463510/finding-the-top-k-matches-in-pytorch

 

Finding the top k matches in Pytorch

I'm using the following code to find the topk matches using pytorch: def find_top(self, x, y, n_neighbors, unit_vectors=False, cuda=False): if not unit_vectors: x = __to_unit_torch__(x,...

stackoverflow.com

참고자료 2 : pytorch.org/docs/stable/generated/torch.topk.html

 

torch.topk — PyTorch 1.8.1 documentation

Shortcuts

pytorch.org

 

728x90
반응형