#include <torch/torch.h>
#include <torch/script.h> // One-stop header.
#include <iostream>
#include <memory>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;

int main() {
    
    std::cout << std::fixed << std::setprecision(4);
    torch::jit::script::Module module = torch::jit::load("/data2/aditya/classifiers/LHSRHS/lhsrhs_script.zip");
    torch::data::transforms::Normalize<> normalize_transform({0.485, 0.456, 0.406}, {0.229, 0.224, 0.225});
    
        
    Mat image_bgr, image, image1;
    image_bgr = imread("/data2/aditya/classifiers/LHSRHS/new_data801/RHS/100_5751_rhs_front_door_assy.png");
    cvtColor(image_bgr, image, COLOR_BGR2RGB);
    resize(image, image1, {448, 448});
    
//     cout<<image1<<'\n';
    
    torch::Tensor tensor_image = torch::from_blob(image1.data, {3, image1.rows, image1.cols}, at::kByte);
    tensor_image = tensor_image.to(torch::kFloat32).div_(255);
    cout<<tensor_image.sizes()<<'\n';
    
    module.eval();
    torch::Tensor tensor_image1 = normalize_transform(tensor_image).unsqueeze_(0);

    std::vector<torch::jit::IValue> input;
    input.push_back(tensor_image1);
    
    at::Tensor output = module.forward(tensor_image1).toTensor();
    
    at::Tensor output1 = torch::softmax(output, 1);
    
    std::cout<<output1<<'\n';
    
}
    

I trained a binary classifier in fastai and then using torch.jit.trace, I converted the model to torchscript and then I am loading the image and model in c++. But the predictions and the values which I am getting after softmax in c++ are very different and inaccurate as compared to torch in python. And I am not getting what is the problem. So, please check where I am going wrong.