3
$\begingroup$

I have a simple fully convolutional network and I'm trying to figure out why I get this error

NetChain::valfail: Validation failed for ConvolutionLayer: kernel size 3*3 plus padding size 0*0 cannot exceed input size 2*2.

when I uncomment the 6-8th layers (which should be totally valid) in the following net:

el = ElementwiseLayer["SELU"];
bn = BatchNormalizationLayer[];
n = NetInitialize[NetChain[{
    ConvolutionLayer[24, {3, 3}], bn, el, 
    ConvolutionLayer[24, {3, 3}, "Dilation" -> 2], bn, el,
    ConvolutionLayer[24, {3, 3}, "Dilation" -> 4], bn, el, 
    ConvolutionLayer[24, {3, 3}, "Dilation" -> 8], bn, el, 
    ConvolutionLayer[24, {3, 3}, "Dilation" -> 16], bn, el, 
    (*
     ConvolutionLayer[24, {3,3},"Dilation" -> 32], bn, el,
     ConvolutionLayer[24, {3,3},"Dilation" -> 64], bn, el,
     ConvolutionLayer[24, {3,3},"Dilation" -> 128], bn, el,
    *) 
    ConvolutionLayer[24, {3, 3}, "Dilation" -> 1], bn, el,
    ConvolutionLayer[3, {1, 1}, "Dilation" -> 1]
    },
   "Input" -> NetEncoder[{"Image", ColorSpace -> "RGB"}], 
   "Output" -> NetDecoder[{"Image", ColorSpace -> "RGB"}]], 
  Method -> "Identity"];
n[ExampleData[{"TestImage", "Lena"}]]

It works without those three (dilations 32,64,128) layers:

enter image description here

$\endgroup$
5
$\begingroup$

By default, a ConvolutionLayer only returns the pixels where the whole convolution kernel "fits" (this is sometimes called a "valid" convolution). So for a 3x3 kernel, the output is 2 pixels smaller in both dimensions:

enter image description here

If you use dilation, the output gets even smaller:

enter image description here

So in your net, there's nothing left at the 6th layer.

If you use PaddingSize:

ConvolutionLayer[24, {3, 3}, "Dilation" -> 2, "PaddingSize" -> 2], bn, el, 
ConvolutionLayer[24, {3, 3}, "Dilation" -> 4, "PaddingSize" -> 4], bn, el, 
ConvolutionLayer[24, {3, 3}, "Dilation" -> 8, "PaddingSize" -> 8], bn, el, 
ConvolutionLayer[24, {3, 3}, "Dilation" -> 16, "PaddingSize" -> 16], bn, el,

you can add as many layers as you want. But the input to each layer will be padded with zeros.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.