Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip dropout rate error #49

Closed
jvwilliams23 opened this issue Jul 23, 2022 · 4 comments
Closed

Skip dropout rate error #49

jvwilliams23 opened this issue Jul 23, 2022 · 4 comments

Comments

@jvwilliams23
Copy link

jvwilliams23 commented Jul 23, 2022

Hi,

I have noticed a potential issue in the following code:

keras2cpp/keras_model.cc

Lines 431 to 433 in ce407cc

} else if(layer_type == "Dropout") {
continue; // we dont need dropout layer in prediciton mode
}

Are you sure that we do not need to include dropout layer in prediction mode? In Figure 2 of Srivastava et al. (2014), they say that in training, the weights are randomly set to 0 with probably equal to the dropout rate. In prediction mode, the dropout rate is still there but is simply multiplied to all weights in the layer - which disagrees with the code.

Additionally, I have noticed major differences in my python keras models vs keras2cpp models with dropout when using the default keras_model.cc. Then, when the weights are multiplied by dropout rate, the error goes away.

Reference
Srivastava, N., Hinton, G., Krizhevsky, A., Sutskever, I. and Salakhutdinov, R., 2014. Dropout: a simple way to prevent neural networks from overfitting. The journal of machine learning research, 15(1), pp.1929-1958.

@pplonski
Copy link
Owner

@jvwilliams23 when I was testing the code the predictions were exactly the same as in keras. I dont think that dropout is used in prediction.

@jvwilliams23
Copy link
Author

@pplonski Interesting, I will look more into my code. Were you testing using the mnist example?

@pplonski
Copy link
Owner

Yes, with mnist data.

@jvwilliams23
Copy link
Author

Hi @pplonski
I just got around to looking into this further. It seems keras do not use dropout in prediction (https://github.com/keras-team/keras/blob/dc95ceca57cbfada596a10a72f0cb30e1f2ed53b/keras/layers/core.py#L116). I guess this is consistent then, but strange that it goes against the original paper. I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants