Primary competition visual

Lacuna - Correct Field Detection Challenge

Helping East Africa
$10 000 USD
Challenge completed over 4 years ago
Prediction
Earth Observation
629 joined
110 active
Starti
Mar 26, 21
Closei
Jul 04, 21
Reveali
Jul 04, 21
User avatar
skaak
Ferra Solutions
CNN - informal (now includes a full CNN starter kit!)
Notebooks · 17 Jun 2021, 11:01 · edited 30 minutes later · 3

Hi - also see my FAQ - informal for some background.

Somebody messaged me and asked me to help in setting up a CNN workflow. There are many steps involved and many parameters to tune. Without going into all the details herewith a sample that could help you get going. I've used a number of different approaches and have a few of these lying around, but this is one of the utilities I am using at present.

# Create and return a CNN 2d convolution layer

# features - int giving number of features

# kernel_size - int giving size of kernel

# activation - string giving name of activation e.g. tanh or relu

# batch_normal - boolean True to add a batch normalization layer

# max_pool - int 0 for no or a number to add a max pooling layer

# avg_pool - int 0 for no or a number to add an average pooling layer

# input_layer - the input layer

# Return the output layer

def make_c2d_layer ( features, kernel_size, batch_normal, activation, max_pool, avg_pool, input_layer ):

next_layer = layers.Conv2D ( features, kernel_size, activation = activation, padding = padding ) ( input_layer )

if batch_normal:

next_layer = layers.BatchNormalization () ( next_layer )

if max_pool > 0:

next_layer = layers.MaxPooling2D ( max_pool, padding = padding ) ( next_layer )

if avg_pool > 0:

next_layer = layers.AveragePooling2D ( avg_pool, padding = padding ) ( next_layer )

return next_layer

This utility will take some input layer and convolve it based on the parameters and return the resulting output layer. You probably want to use features that are powers of 2, e.g. 2, 4, 8, 16, 32 ... You will create a few of these and hook them up to the image and, there, close to the inputs, use a lower value, say 16. Then as you chain these or combine e.g. the RGB and spectral images or multiple of the RGBs you'd start increasing the features, so the next layer may use 32 and then 64. Here are some excellent references to get you started.

  • https://www.pyimagesearch.com/2018/12/31/keras-conv2d-and-convolutional-layers
  • http://elib.dlr.de/118154/2/07924548.pdf

For parameters use e.g. "relu" for activation and use 2 for a max pooling filter of size 2, that will then reduce the image size by a factor of 2 as well. And most of the time you'd pass True for normalization. For padding, use "same" or "none" but then (none) beware, the image will shrink as the pooling is applied.

FWIW I've tried that approach in many different alternative implementations, but still could not really make progress in solving this problem. I've since tried quite a few non-CNN approaches, some showing lots of promise, but, reviewing the many many many models I've built, it seems the CNNs have been best, so I am now again trying those.

Why CNN?

Just a few informal observations, but CNN on the surface seems the man for this job as it deals with images and spatial information and has relatively few weights (compared to e.g. a NN where you just connect the input pixels to some hidden layer). CNNs also allow you to combine the RGB and spectral and the multiple RGB images. Also, using simple methods e.g. SVM or K-means or quadratic discriminants (or many others) does not seem to be able to bite into this, although I am sure some of the more creative applications of simple methods are currently on the LB.

The trouble with CNNs start on the output side.

Often times a CNN is used for classification and is connected up to some dense layer, but this is not a classification challenge - or is it?

Discussion 3 answers

Thank you so much

17 Jun 2021, 11:49
Upvotes 0
User avatar
skaak
Ferra Solutions

Well - pay close attention now ...

Since you asked for a sample workflow I created a notebook that takes you through the whole process, from loading and preprocessing the images and metadata to constructing and training a full CNN to validating the network using a hold out sample to finally writing a submission file that I just tested and it all works perfectly fine.

This should really get you going.

If you go to my homepage (www.ferrasolutions.com) you will see, right at the bottom of the page, under the heading of Lacuna, a link to the page from where you can download this notebook as well as the CSV output it produces.

Have fun.

FWIW I prepared this while waiting for what I believe is a much better model to finish.

The simple CNN scores 0.238 on the leaderboard while the better model, a monstrous ensemble CNN, yields 0.235 - really not that much better than the simple model's score! Sadly, the all zeros solution fares even better and will produce 0.230.

This, I believe, is due to the data being so dirty. Simple models stand a good chance in this competition given the quality of the data. So there you go, see if you can use this notebook to produce a better score. I'll continue with my monstrous CNN to try and beat that as well.

Fantastic effort

28 Jun 2021, 12:12
Upvotes 0