Hello, the classifier trained by Resnet50 works well in python. The same test data has poor classification accuracy in C++(libtorch). I don’t know why and this is my main code.
//read image
srcImage = cv::imread(strFile, cv::ImreadModes::IMREAD_COLOR);
cv::cvtColor(srcImage, traImage, cv::COLOR_BGR2RGB);
cv::resize(traImage, resImage, cv::Size(224, 224),0, 0, CV_INTER_LINEAR);
resImage.convertTo(detImage, CV_32F, 1.0 / 255, 0);
// Image conversion
std::vector<int64_t> sizes = {1, detImage.rows, detImage.cols, 3};
at::Tensor tensorImage = torch::from_blob(detImage.data, at::IntList(sizes), at::kByte);
tensorImage = tensorImage.to(at::kFloat);
tensorImage = tensorImage.permute({0, 3, 1, 2});
tensorImage = tensorImage.to(torch::kCUDA);
std::vector<torch::jit::IValue> inputs;
inputs.emplace_back(tensorImage);
//calculate
at::Tensor result = ptModule->forward(inputs).toTensor();
auto max_result = result.max(1,true);