Computer Vision News - June 2021

7 image a ReLU andMaxPool operations are performed. The classification layer outputs a vector of 10 dimensions (a dense layer), which is the number of predicted classes. ConvNets using Julia and the Flux machine learning framework function build_model (args; imgsize = ( 28 , 28 , 1 ), nclasses = 10 ) cnn_output_size = Int .(floor.([imgsize[ 1 ]/ 8 ,imgsize[ 2 ]/ 8 , 32 ])) return Chain( # First convolution, operating upon a 28x28 image Conv(( 3 , 3 ), imgsize[ 3 ]=> 16 , pad=( 1 , 1 ), relu), MaxPool(( 2 , 2 )), # Second convolution, operating upon a 14x14 image Conv(( 3 , 3 ), 16 => 32 , pad=( 1 , 1 ), relu), MaxPool(( 2 , 2 )), # Third convolution, operating upon a 7x7 image Conv(( 3 , 3 ), 32 => 32 , pad=( 1 , 1 ), relu), MaxPool(( 2 , 2 )), # Reshape 3d tensor into a 2d one using `Flux.flatten`, at this point it should be (3, 3, 32, N) flatten, Dense(prod(cnn_output_size), 10 )) end To chain the layers of a model we use the Flux function Chain. It enables us to call the layers in sequence on a given input. Also, we use the function flatten to reshape the output image from the last convolution layer. Finally, we call the Dense function to create the classification layer. Before training our model, we need to define a few functions that will be helpful for the process: • augment augments the data by adding gaussian random noise to our image to make it more robust: • anynan checks whether any element of the params is NaN or not: • accuracy computes the accuracy of our ConvNet: augment(x) = x .+ gpu( 0.1f0 *randn(eltype(x), size(x))) anynan(x) = any(y -> any(isnan, y), x) accuracy(x, y, model) = mean(onecold(cpu(model(x))) .== onecold(cpu(y)))

RkJQdWJsaXNoZXIy NTc3NzU=