CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

ConvReLULayer Inputs in Tutorial2

Open leoStark1 opened this issue 10 years ago • 9 comments

Hi Guys,

Just started working with CNTK and was following the MNIST example using CNN. I'm just wondering whether anyone can provide what each input is meant to be in ConvReLULayer of the following description from Tutorial2? The descriptions for Convolution function is provided but I couldn't find anything that describes inWCount, wScale and bValue?

Any help is much appreciated!

ConvReLULayer(inp, outMap, inWCount, kW, kH, hStride, vStride, wScale, bValue) = [ convW = LearnableParameter(outMap, inWCount, init="uniform", initValueScale=wScale) convB = ImageParameter(1, 1, outMap, init="fixedValue", value=bValue, imageLayout=$imageLayout$) conv = Convolution(convW, inp, kW, kH, outMap, hStride, vStride, zeroPadding=false, imageLayout=$imageLayout$) convPlusB = Plus(conv, convB) act = RectifiedLinear(convPlusB) ]

leoStark1 avatar May 17 '16 04:05 leoStark1

Hello, ConvReLULayer macro, which implements convolution + bias operation with subsequent application of ReLU activation function, has the following parameters:

  • inp - input node (convolution input)
  • outMap - number of output feature maps as a result of applying convolution
  • inWCount - the size of a convolution kernel (filter) which is: inWCount == kW * kH * inMap where inMap is number of feature maps in the input node. This parameter is really redundant and the only reason we have to use is lack of expressions support in NDL. If we had such support, then this parameter could have been expressed with something like: kW2 * kH2 * cMap1 for conv2 layer.
  • kW and kH - width and height of a convolutional kernel (filter). Kernel depth (z dimension/number of input feature maps) will be inferred based on the input inp,
  • hStride and vStride - horizontal and vertical strides when the kernel is applied to the input.
  • wScale and bValue - values that are used to initialize weight matrix (convolutional kernels) and bias vector. Note that in this case weights are initialized randomly (uniform distribution) while bias is set to a fixed value.

Hope this clarifies things a bit, let me know if you have questions.

Note that the syntax have changed slightly when we introduced ND-convolutions. Make sure to sync the latest version and compare macros like Conv2DReLULayer and ConvNDReLULayer

And take a look at documentation for Convolution and other nodes here.

Alexey-Kamenev avatar May 17 '16 16:05 Alexey-Kamenev

Hi Alexey,

Thank you very much for that quick clarification. One more question, what does cMap1 stand for?

Thanks again and much appreciated!

leoStark1 avatar May 17 '16 22:05 leoStark1

cMap1 is the number (c is for count) of feature maps in the first convolutional layer. And I think we should refactor our samples to use better names...

Alexey-Kamenev avatar May 17 '16 22:05 Alexey-Kamenev

hehe yeah, sometimes the names make sense, sometimes it doesn't. Thanks heaps for this Alexey, much appreciated :)

leoStark1 avatar May 17 '16 22:05 leoStark1

Had to be away for a while and just got back, I have another question Alexey, I used the default configuration and executed a couple of experiments by downsizing my images to 28x28 and now I want to use my original image sizes. I can make out most of the naming conventions now but I'm still tripping on the final part from 02_Convolution.cntk file in MNIST tutorial.

h1Dim = 128 # DNNImageSigmoidLayer and DNNLayer are defined in Macros.ndl h1 = DNNImageSigmoidLayer(7, 7, cMap2, h1Dim, pool2, 1) ol = DNNLayer(h1Dim, labelDim, h1, 1)

ce = CrossEntropyWithSoftmax(labels, ol)
err = ErrorPrediction(labels, ol)

This is the final fully connected layer right? From what I can understand, the output of the final pooling layer would be 4x4x32 {started with 28x28 and reduced by input->conv1->pool1->conv2->pool2 as 28x28x1->24x24x16->12x12x16->8x8x32->4x4x32} right?

In that case, what does h1Dim = 128 stand for and how is input to DDNImageSigmoidLayer 7x7? Am I missing something here? I would most appreciate it if you can detail the parameters for DNNImageSigmoidLayer and DNNLayer.

Thanks a lot in advance!

leoStark1 avatar Jun 05 '16 00:06 leoStark1

Also another question, in the tutorial it depicts that "Final Results: Minibatch[1-625]: errs = 2.39% * 10000; ce = 0.076812531 * 10000" is equivalent to an error rate of 2.39%. My output shows "Final Results: Minibatch[1-587]: SamplesSeen = 9380 err: ErrorPrediction/Sample = 0.31343284 ce: CrossEntropyWithSoftmax/Sample = 0.62181986 Perplexity = 1.8623141". Could you point out where the interpretation of these terms are? For instance, does "ErrorPrediction/Sample = 0.31343284" equate to an error rate of 0.31% or 31%?

Thanks again!

leoStark1 avatar Jun 06 '16 00:06 leoStark1

Hi Leo, we are in the process of updating the tutorial to match some recent changes to CNTK. With the switch to BrainScript, I will try to add and use an actual formula for computing the dimensions into the sample. That should solve the confusion once and for all. Please hang on for a day.

2.39% is indeed the error rate. You have pasted a log from an older CNTK version. 0.3134 from ErrorPrediction indeed means 31.34% error rate; % strictly means 1/100 in our context. There are obviously other criteria, such as square error, where the number means something different. The updated CNTK uses a simple heuristics--any criterion name ending with "s" will be printed as a percentage (assuming "s" indicates a plural of some countable thing, which is of course a very rough and very English-centric heuristic). But even if it gets it wrong, the number will still be correct if one reads % as /100.

frankseide avatar Jun 06 '16 15:06 frankseide

Hello, As for your sample question: first, note that Conv2DReLULayer and ConvNDReLULayer macros use Convolution node with padding, so layer dimensions will be 28x28x1 -> 28x28x16 -> 14x14x16 -> 14x14x32 -> 7x7x32. Just for the reference, the formula for the convolution without padding:

O = (I - K) / S + 1

while for automatic padding CNTK uses the following:

O = (I - 1) / S + 1

where O is number of outputs, I - inputs, K - kernel size, S - stride.

That's why h1 is defined as:

    h1 = DNNImageSigmoidLayer(7, 7, cMap2, h1Dim, pool2, 1)

h1 is just a fully connected layer with 128 neurons which input is 7x7x32 (that's why you have to use DNNImageSigmoidLayer macro). All macros are described in Macros.ndl file. Hope this helps.

Alexey-Kamenev avatar Jun 06 '16 16:06 Alexey-Kamenev

Thanks Alexey, that makes perfect sense.

leoStark1 avatar Jun 26 '16 07:06 leoStark1