Why my trained model output is same for each random input?
I trained my model on the Python platform. after training, I faced up with same output for each random input. I solved this problem by deactivating BatchNorm layers with the model.eval() method. but when I tried to load my trained model in C++ with Pytorch C++ API, this problem showed up again, and model.eval() not helping me at this time. I faced the same output for each random input again.
This is my C++ model loading function:
std::vector&lt;torch::jit::script::Module&gt; module_loader(std::string file_addr) {
    std::vector&lt;torch::jit::script::Module&gt; modul;
    torch::jit::script::Module model = torch::jit::load(file_addr);
    model.eval();
    modul.push_back(model);
    return modul;
}

And this is my testing function:
void test(std::vector&lt;torch::jit::script::Module&gt; &amp;model) {
    std::vector&lt;torch::jit::IValue&gt; inputs;
    inputs.push_back(torch::rand({1, 2, 64, 172}));
    torch::Tensor output = model[0].forward(inputs).toTensor();
    std::cout &lt;&lt; output &lt;&lt; std::endl;
}

After all, I put it all together in main() like this:
int main() {
    auto modul = module_loader(MODEL_ADDRESS);
    test(modul);
}

MODEL_ADDRESS is a macro for the address of the trained model on my local disk.
The output of the program is this for every run:

0.3231 [ CPUFloatType{1,1} ]


I debugged multiple times my code and retry to save the model. Finally, I found the answer. I used a server to train my model, and for exporting the model to C++ I load my model weight in Python Shell into a model object. The problem is here, I should go to eval() before exporting the model for C++. C++ eval() does not work for the model is trained in Python. This solved my problem.
