RN50 Differences Preprocessing with OpenCV and Pillow

I have two implementations, C++ (opencv) and Python (pillow), for doing rn50 preprocessing; however the accuracies are different. I know that the differences stem from image resizing step. torchvision applies antialiasing, but opencv does not. And, using better interpolation in opencv reduces the gap but does not eliminate it.

I have tried to make resize for opencv as close to torchvision (transforms, pillow) as possible but I am still unable to reproduce. Any suggestions on how to resolve ?


cv::Mat image = cv::imread(filename);

cv::resize(image, image, cv::Size(resize_height, resize_width), 0.5, 0.5,cv::INTER_AREA);
cv::cvtColor(image, image, cv::COLOR_BGR2RGB);

centerCrop(&image, crop_height, crop_width, &image);
image.convertTo(image, CV_32FC3, 1.0f / 255.0f);

 // Normalize  
cv::Mat mean(crop_height, crop_width, CV_32FC3, cv::Scalar(0.485, 0.456, 0.406));
cv::Mat std(crop_height, crop_width, CV_32FC3, cv::Scalar(0.229, 0.224, 0.225));
cv::subtract(image, mean, image);
cv::divide(image, std, image);

 auto options = torch::TensorOptions().dtype(at::kFloat);
 at::Tensor tensor = torch::from_blob(image.data, {1, crop_height, crop_width, 3}).clone();
tensor = tensor.permute({0, 3, 1, 2});
 tensor = tensor.to(at::kFloat);


cal_loader = torch.utils.data.DataLoader(datasets.ImageFolder("calibration_dataset/", transforms.Compose([

            batch_size=batch_size, shuffle=False,
            num_workers=1, pin_memory=True)