jatinchowdhury18 / RTNeural

Real-time neural network inferencing
BSD 3-Clause "New" or "Revised" License
551 stars 57 forks source link

Unexpected Eigen Results #55

Closed bhostetler18 closed 2 years ago

bhostetler18 commented 2 years ago

Hello! First, thank you for providing such a useful and well-written library.

I am testing a basic port of a Keras model using the RTNeural static API (relevant code and json-formatted weights provided below). I get the correct result (approximately 0.007) when compiling with STL or XSIMD, but when I compile with Eigen as the backend I get pretty wonky answers (something like 5.29656e+18 in this example). Is this potentially a numerical issue, or am I doing something wrong?

I don't need to use Eigen at all, so absolutely no rush or even need to get this fixed. Just thought you might want to know if it is in fact an error and not something on my end.

RTNeural::ModelT<float, 24, 1,
        RTNeural::DenseT<float, 24, 24>,
        RTNeural::ReLuActivationT<float, 24>,
        RTNeural::DenseT<float, 24, 16>,
        RTNeural::ReLuActivationT<float, 16>,
        RTNeural::DenseT<float, 16, 1>,
        RTNeural::SigmoidActivationT<float, 1>> model;

std::ifstream jsonStream("./RT_test.json", std::ifstream::binary);
model.parseJson(jsonStream, true);

float input[24] = {0};
model.reset();
float output = model.forward(input);

RT_test.json.zip

jatinchowdhury18 commented 2 years ago

Thanks for reporting this! It ended up being a fairly straightforward issue, which only showed up with the Eigen backend for networks where an activation layer is the final layer. The issue should be fixed now on the main branch.

bhostetler18 commented 2 years ago

Thank you for the extremely quick fix! Glad I could help slightly by reporting.