Last active
January 13, 2020 15:21
-
-
Save JulienPascal/56cd1d62fb65e068d07e177cec0f83c0 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
# Batching | |
# See: https://github.com/FluxML/model-zoo/blob/master/vision/mnist/conv.jl | |
# Bundle images together with labels and group into minibatchess | |
function make_minibatch(X, Y, idxs) | |
X_batch = Array{Float32}(undef, size(X[1])..., 1, length(idxs)) | |
for i in 1:length(idxs) | |
X_batch[:, :, :, i] = Float32.(X[idxs[i]]) | |
end | |
Y_batch = onehotbatch(Y[idxs], 0:9) | |
return (X_batch, Y_batch) | |
end | |
# The CNN only "sees" 128 images at each training cycle: | |
batch_size = 128 | |
mb_idxs = partition(1:length(train_imgs), batch_size) | |
# train set in the form of batches | |
train_set = [make_minibatch(train_imgs, train_labels, i) for i in mb_idxs]; | |
# train set in one-go: used to calculate accuracy with the train set | |
train_set_full = make_minibatch(train_imgs, train_labels, 1:length(train_imgs)); | |
# test set: to check we do not overfit the train data: | |
test_set = make_minibatch(test_imgs, test_labels, 1:length(test_imgs)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment