Computer Vision News - June 2021

To train our model, we need to bundle images together with their labels and then group them into mini-batches (makes the training process faster). We define the function make _ minibatch that takes as inputs the images ( X ) and their labels ( Y ) as well as the indices for the mini-batches ( idx ): 6 Computer Vision Tool 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 make _ minibatch takes the following steps: • Creates the X _ batch array of size 28x28x1x128 to store the mini-batches. • Stores the mini-batches in X _ batch . • One hot encodes the labels of the images. • Stores the labels in Y _ batch . The test data are loaded from the MNIST database and this creates an array with the indices of the train images corresponding to each mini-batch. function get_processed_data (args) # Load labels and images train_labels = MNIST.labels() train_imgs = MNIST.images() mb_idxs = partition( 1 :length(train_imgs), args.batch_size) train_set = [make_minibatch(train_imgs, train_labels, i) for i in mb_idxs] # Prepare test set as one giant minibatch: test_imgs = MNIST.images(:test) test_labels = MNIST.labels(:test) test_set = make_minibatch(test_imgs, test_labels, 1 :length(test_imgs)) return train_set, test_set end Here the model is built by creating three convolution layers and one classification layer. As the images are grayscale, only one channel is used (instead of three). When combined together, the convolutional layer structure would look like Conv(kernel, input_channels => output_channels, ...) . To reduce the size of each

RkJQdWJsaXNoZXIy NTc3NzU=