what(): Expected object of type Variable but found type CUDALongType for argument #2 ‘index’ (checked_ cast_ variable at … /… /torch/csrc/autograd/ VariableTypeManual.cpp:38 )
Problem Description: using the libtorch function torch:: index_ select(detections_ class_ Left, 0, index), the operation will report an error as above and enter the index_ The definition of select shows: static inline tensor index_ select(const Tensor & self, int64_ t dim, const Tensor & index)
Problem analysis:
through the error prompt, argument # 2 ‘index’ should be of variable type, and I use the tensor (data type is cudalongtype), so I always report an error.
Problem solving:
1. Make clear the difference between variable type and tensor, and quote another article’s interpretation: Zhihu’s article;
2. Turn the tensor into a variable and use the function: Torch:: autograd:: make_ variable(left_ index, false);// tensot—> Variable