CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Optimize ConvolutionalLayer { } parameters.

Open gsrungarapu opened this issue 9 years ago • 4 comments

How to choose right values for our network model?

Scenario : I created a basic network model for the below image data. Images Size: 32x32 Number of Classes : 17 Training size: 25,000 images Test size: 9,500 images

Right now, I am using 3 layers with MaxPooling as below. Any suggestions to optimize the parameters? I am trying to understand the convolution feature from https://github.com/Microsoft/CNTK/wiki/Convolution But, If I go beyond 5 filters, I am getting input dimensions do not match error.

`def create_basic_model(input, out_dims):

net = Convolution((5,5), 32, init=glorot_uniform(), activation=relu, pad=False)(input)
net = MaxPooling((3,3), strides=(1,1))(net)

net = Convolution((5,5), 32, init=glorot_uniform(), activation=relu, pad=False)(net)
net = MaxPooling((3,3), strides=(1,1))(net)

net = Convolution((5,5), 64, init=glorot_uniform(), activation=relu, pad=False)(net)
net = MaxPooling((3,3), strides=(1,1))(net)

net = Dense(64, init=glorot_uniform())(net)
net = Dense(out_dims, init=glorot_uniform(), activation=None)(net)

return net`

gsrungarapu avatar May 16 '17 21:05 gsrungarapu

Every convolution with pad=False will reduce the image size by 4 pixels as you used 5x5 filters. Try to use smaller filter sizes (3x3, for example), or set pad=True.

cha-zhang avatar May 17 '17 14:05 cha-zhang

Perfect! Thank you. Yes, I did try them and those options work. Also, to make 5x5 filters work, I tried to use strides=(2,2) with Padding. In general are there any rules or optimizations techniques to follow in defining how many filters or other input parameters when creating a convolution layer?

Other than that we can close this issue. Thank you.

gsrungarapu avatar May 17 '17 15:05 gsrungarapu

This depends on the application. The more complicated the problem is, the more convolution layers you might need.

In general two 3x3 filters stacked are better than one 5x5 filter. The number of filters should probably double every time you have a pooling. Check the VGG paper for their recommendations.

Stride in convolution can be used to replace max pooling, although max pooling might have a small accuracy advantage.

cha-zhang avatar May 17 '17 15:05 cha-zhang

sure, thanks.

gsrungarapu avatar May 17 '17 15:05 gsrungarapu