CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

Operands incompatible shapes for 128*128 images

Open sofeikov opened this issue 10 years ago • 3 comments

Hi guys,

I've got this error when running training process for CIFAR-10 with resized images. I resized all images to 128*128 to bring this closer in terms of size to the data we're going to use, I've also changed sizes for all readers in cntk config. In ndl macros I've also did so. However, when I run the training I've got the following message:

Validating --> labels = InputValue() :  -> [10 x *]
Validating --> ol.W = LearnableParameter() :  -> [10 x 64]
Validating --> h1.W = LearnableParameter() :  -> [64 x 3 x 3 x 64]
Validating --> conv3_act.W = LearnableParameter() :  -> [64 x 800]
Validating --> conv2_act.W = LearnableParameter() :  -> [32 x 800]
Validating --> conv1_act.W = LearnableParameter() :  -> [32 x 75]
Validating --> features = InputValue() :  -> [128 x 128 x 3 x *]
Validating --> featOffs = LearnableParameter() :  -> [1 x 1]
Validating --> featScaled = Minus (features, featOffs) : [128 x 128 x 3 x *], [1 x 1] -> [128 x 128 x 3 x *]
Validating --> conv1_act.c = Convolution (conv1_act.W, featScaled) : [32 x 75], [128 x 128 x 3 x *] -> [128 x 128 x 32 x *]
Validating --> conv1_act.b = LearnableParameter() :  -> [1 x 1 x 32]
Validating --> conv1_act.p = Plus (conv1_act.c, conv1_act.b) : [128 x 128 x 32 x *], [1 x 1 x 32] -> [128 x 128 x 32 x *]
Validating --> conv1_act.y = RectifiedLinear (conv1_act.p) : [128 x 128 x 32 x *] -> [128 x 128 x 32 x *]
Validating --> pool1 = MaxPooling (conv1_act.y) : [128 x 128 x 32 x *] -> [63 x 63 x 32 x *]
Validating --> conv2_act.c = Convolution (conv2_act.W, pool1) : [32 x 800], [63 x 63 x 32 x *] -> [63 x 63 x 32 x *]
Validating --> conv2_act.b = LearnableParameter() :  -> [1 x 1 x 32]
Validating --> conv2_act.p = Plus (conv2_act.c, conv2_act.b) : [63 x 63 x 32 x *], [1 x 1 x 32] -> [63 x 63 x 32 x *]
Validating --> conv2_act.y = RectifiedLinear (conv2_act.p) : [63 x 63 x 32 x *] -> [63 x 63 x 32 x *]
Validating --> pool2 = MaxPooling (conv2_act.y) : [63 x 63 x 32 x *] -> [31 x 31 x 32 x *]
Validating --> conv3_act.c = Convolution (conv3_act.W, pool2) : [64 x 800], [31 x 31 x 32 x *] -> [31 x 31 x 64 x *]
Validating --> conv3_act.b = LearnableParameter() :  -> [1 x 1 x 64]
Validating --> conv3_act.p = Plus (conv3_act.c, conv3_act.b) : [31 x 31 x 64 x *], [1 x 1 x 64] -> [31 x 31 x 64 x *]
Validating --> conv3_act.y = RectifiedLinear (conv3_act.p) : [31 x 31 x 64 x *] -> [31 x 31 x 64 x *]
Validating --> pool3 = MaxPooling (conv3_act.y) : [31 x 31 x 64 x *] -> [15 x 15 x 64 x *]
Validating --> h1.t = Times (h1.W, pool3) : [64 x 3 x 3 x 64], [15 x 15 x 64 x *] -> [64 x *]
Validating --> h1.b = LearnableParameter() :  -> [64 x 1]
Validating --> h1.z = Plus (h1.t, h1.b) : [64 x *], [64 x 1] -> [64 x 1 x *]
Validating --> h1.y = RectifiedLinear (h1.z) : [64 x 1 x *] -> [64 x 1 x *]
Validating --> h1_d = Dropout (h1.y) : [64 x 1 x *] -> [64 x 1 x *]
Validating --> ol.t = Times (ol.W, h1_d) : [10 x 64], [64 x 1 x *] -> [10 x 1 x *]
Validating --> ol.b = LearnableParameter() :  -> [10]
Validating --> ol.z = Plus (ol.t, ol.b) : [10 x 1 x *], [10] -> [10 x 1 x *]
Validating --> CE = CrossEntropyWithSoftmax (labels, ol.z) : [10 x *], [10 x 1 x *] -> [1]
Validating --> Err = ErrorPrediction (labels, ol.z) : [10 x *], [10 x 1 x *] -> [1]

Validating network. 21 nodes to process in pass 2.


Validating network, final pass.


Using cuDNN convolution engine for geometry: Input: 128 x 128 x 3, Output: 128 x 128 x 32, Kernel: 5 x 5 x 3, Map: 1 x 1 x 32, Stride: 1 x 1 x 3, Sharing: (1), AutoPad: (1), LowerPad: 0, UpperPad: 0.

Using cuDNN convolution engine for geometry: Input: 128 x 128 x 32, Output: 63 x 63 x 32, Kernel: 3 x 3 x 1, Map: 1, Stride: 2 x 2 x 1, Sharing: (1), AutoPad: (0), LowerPad: 0, UpperPad: 0.

Using cuDNN convolution engine for geometry: Input: 63 x 63 x 32, Output: 63 x 63 x 32, Kernel: 5 x 5 x 32, Map: 1 x 1 x 32, Stride: 1 x 1 x 32, Sharing: (1), AutoPad: (1), LowerPad: 0, UpperPad: 0.

Using cuDNN convolution engine for geometry: Input: 63 x 63 x 32, Output: 31 x 31 x 32, Kernel: 3 x 3 x 1, Map: 1, Stride: 2 x 2 x 1, Sharing: (1), AutoPad: (0), LowerPad: 0, UpperPad: 0.

Using cuDNN convolution engine for geometry: Input: 31 x 31 x 32, Output: 31 x 31 x 64, Kernel: 5 x 5 x 32, Map: 1 x 1 x 64, Stride: 1 x 1 x 32, Sharing: (1), AutoPad: (1), LowerPad: 0, UpperPad: 0.

Using cuDNN convolution engine for geometry: Input: 31 x 31 x 64, Output: 15 x 15 x 64, Kernel: 3 x 3 x 1, Map: 1, Stride: 2 x 2 x 1, Sharing: (1), AutoPad: (0), LowerPad: 0, UpperPad: 0.
Validating --> h1.t = Times (h1.W, pool3) : [64 x 3 x 3 x 64], [15 x 15 x 64 x *] -> [64 x *] FAILED

EXCEPTION occurred: h1.t Times operation: Left [64 x 3 x 3 x 64] and right [15 x 15 x 64] operands' shapes are not compatible.

I do believe, I've changed sized everywhere where it was required. Am I doing something wrong? If so, for me it's really hard to understand what.

I'm attaching config files: 01_Convolution.ndl.txt Macros.ndl.txt 01_Conv.cntk.txt

Thanks.

sofeikov avatar May 24 '16 08:05 sofeikov

Alright, so it's turned out that I needed to change fully connected layer geometry manually in order to make it matching with output of the pooling layer. So in NDL file instead of

h1 = DNNImageReLULayer(3, 3, cMap3, hiddenDim, pool3, fc1WScale, fc1BValue)

we want to put

h1 = DNNImageReLULayer(15, 15, cMap3, hiddenDim, pool3, fc1WScale, fc1BValue)

when using 128*128 images.

I wonder if I missed this being described somewhere in the wiki?

sofeikov avatar May 24 '16 14:05 sofeikov

Right, sometimes it is easier to look at the output of CNTK to figure out correct dimensions rather than computing everything manually. The good news is in BrainScript (much better version of NDL, will be documented soon) you won't need to compute anything and will be able to use expressions to represent dimensions (like you would do in Python etc).

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

Issue seems resolved. Closing.

gaizkan avatar Jun 03 '16 06:06 gaizkan