Choosing Conv2D filters value to start off with

Viewed 2536

I realise that the following question may garner responses along the lines of "it's about experimenting and using experience" but I'm going to ask anyway because I think it would be useful to get an idea of what I should be looking to start off with.

In Keras, the Conv2D convolution layer, there's a parameter called filters, which I understand to be the "number of filter windows convolving on an image of a size defined by the kernel_size parameter". I.e. Conv2D(filters=32, kernel_size=(3,3)..) will mean 32 windows of size 3x3 will be scanning across an image.

My question is: if you are creating a brand new neural network to solve, let's say, an image classification/recognition problem without leveraging a pre-trained neural network (so starting from scratch), what filters value do you typically start off with for your first convolutional layer? Is there a rule of thumb? Is this just literally an experimentation answer?

Let's say I want a brand new model to be able to recognise whether or not there's a dog in an image without leveraging ResNet50 or InceptionV3 imagenet models, and I'm going to use coloured images of size 4160x3120 which I've scaled down to an input_shape of (224,168,3), what should my first Conv2D layer look like?

E.g. is this sample code a good starting point to solve my problem:

model = Sequential()
model.add(Conv2D(32, kernel_size=(3,3), activation="relu", input_shape=(224,168,3), data_format="channels_last"))
model.add(Conv2D(64, kernel_size=(3,3), activation="relu"))
#additional model design code

Is 32 a good starting point? Should I go smaller? Is doubling filters size from Conv2D layer to Conv2D layer an appropriate approach to solving a new problem?

Completely understand that this is an inherently complex subject and there's no "get rich quick" approach but I just want to get a better appreciation of the subject.

1 Answers

16 or 32 is fine.

The filters in the first few layers are usually less abstract and typically emulates edge detectors, blob detectors etc. You generally don't want too many filters applied to the input layer as there is only so much information extractable from the raw input layer. Most of the filters will be redundant if you add too many. You can check this by pruning (decrease number of filters until your performance metrics degrade)

The kernel size determines how much of the image you want affecting the output of your convolution (the 'receptive field' of the kernel). It's been seen smaller kernels are generally better than larger ones (i.e go with 3x3 instead of 5x5, 7x7).

The Inception Architecture takes these decisions out of the hand of the modeller as it lumps filters of different kernel size together and let the model learn the best ones to use.

As reference I would suggest going through Stanford's CS231n course on youtube to get a understanding of it all : https://www.youtube.com/playlist?list=PLC1qU-LWwrF64f4QKQT-Vg5Wr4qEE1Zxk

Related