Last active
January 13, 2020 15:21
-
-
Save JulienPascal/65f60aef1c8bdb0935c0af6e83bbdc0b to your computer and use it in GitHub Desktop.
CNN with Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Loss function | |
# See: https://github.com/FluxML/model-zoo/blob/master/vision/mnist/conv.jl | |
# `loss()` calculates the crossentropy loss between our prediction `y_hat` | |
function loss(x, y) | |
# Add some noise to the image | |
# we reduce the risk of overfitting the train sample by doing so: | |
x_aug = x .+ 0.1f0*gpu(randn(eltype(x), size(x))) | |
y_hat = model(x_aug) | |
return crossentropy(y_hat, y) | |
end | |
accuracy(x, y) = mean(onecold(model(x)) .== onecold(y)) | |
# ADAM optimizer | |
opt = ADAM(0.001); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment