Skip to content

Instantly share code, notes, and snippets.

@JulienPascal
Last active January 13, 2020 15:21
Show Gist options
  • Save JulienPascal/65f60aef1c8bdb0935c0af6e83bbdc0b to your computer and use it in GitHub Desktop.
Save JulienPascal/65f60aef1c8bdb0935c0af6e83bbdc0b to your computer and use it in GitHub Desktop.
CNN with Julia
# 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