# Advice on non-square input

**URL:** <https://community.konduit.ai/t/advice-on-non-square-input/273>\
**Category:** DL4J\
**Created:** [March 15, 2020, 5:25pm UTC](https://community.konduit.ai/t/advice-on-non-square-input/273 "2020-03-15T17:25:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbitteur](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@hbitteur](https://community.konduit.ai/u/hbitteur)\
**Post date:** [March 15, 2020, 5:25pm UTC](https://community.konduit.ai/t/advice-on-non-square-input/273/1 "2020-03-15T17:25:29Z")

</div>

Bonjour,

I would appreciate any advice on a CNN architecture for non-square input.

Typically, I’m trying to adapt ResNet50 (coded for 224x224x3 input) to work on smaller and non-square gray images (112x56x1 would be nice).  
My inputs are thus 24 times smaller than the original ResNet50 inputs.

I understand the convolution itself can cope with my specific input dimensions. The problem is with the following layers (pooling for example), for which there seems to be only the nOut() method to size the output. This is OK for a square but not for a rectangle, for which width and height values are different.

So, is there any way in Deeplearning4J configurations to explicitly provide layer width and height output values rather than a single nOut value?  
I’m still searching, but I did not find any in the zoo models.

Thanks in advance for any advice,  
/Hervé

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [March 16, 2020, 6:47am UTC](https://community.konduit.ai/t/advice-on-non-square-input/273/2 "2020-03-16T06:47:36Z")

</div>

The nOut values on CNN layers in DL4J set the number of output channels, so they should be able to cope with non-sequare inputs anyway.

I guess you tried something and did get an error? Can you share the full stack trace?

---

<div class="post-metadata">

**Author:** ![hbitteur](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@hbitteur](https://community.konduit.ai/u/hbitteur)\
**Post date:** [March 16, 2020, 5:05pm UTC](https://community.konduit.ai/t/advice-on-non-square-input/273/3 "2020-03-16T17:05:57Z")

</div>

Here is my attempt. I basically copied ResNet50 source code into a similar ResNet50Custtomized class and replaced the line:

> private int inputShape = new int{3, 224, 224};

by the following line:

> private int inputShape = new int{1, 56, 112};

Then at run time, I got this output:

> Exception in thread “main” org.deeplearning4j.exception.DL4JInvalidConfigException: Invalid configuration for layer (idx=77, name=res4a\_branch2b, type=ConvolutionLayer) for width dimension: Invalid input configuration for kernel width. Require 0 \< kW \<= inWidth + 2\*padW; got (kW=3, inWidth=2, padW=0)  
> Input type = InputTypeConvolutional(h=4,w=2,c=256), kernel = [3, 3], strides = [1, 1], padding = [0, 0], layer size (output channels) = 256, convolution mode = Same  
> at org.deeplearning4j.nn.conf.layers.InputTypeUtil.getOutputTypeCnnLayers(InputTypeUtil.java:329)  
> at org.deeplearning4j.nn.conf.layers.ConvolutionLayer.getOutputType(ConvolutionLayer.java:192)  
> at org.deeplearning4j.nn.conf.graph.LayerVertex.getOutputType(LayerVertex.java:131)  
> at org.deeplearning4j.nn.conf.ComputationGraphConfiguration.getLayerActivationTypes(ComputationGraphConfiguration.java:536)  
> at org.deeplearning4j.nn.conf.ComputationGraphConfiguration.addPreProcessors(ComputationGraphConfiguration.java:449)  
> at org.deeplearning4j.nn.conf.ComputationGraphConfiguration$GraphBuilder.build(ComputationGraphConfiguration.java:1201)  
> at org.audiveris.omrdataset.train.ResNet50Customized.init(ResNet50Customized.java:108)  
> at org.audiveris.omrdataset.train.Training.process(Training.java:241)  
> at org.audiveris.omrdataset.Main.main(Main.java:83)

Thanks for your help,  
/Hervé

---

<div class="post-metadata">

**Author:** ![GPSforLEGENDS](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/gpsforlegends/32/65_2.png) [@GPSforLEGENDS](https://community.konduit.ai/u/GPSforLEGENDS)\
**Post date:** [March 17, 2020, 3:19pm UTC](https://community.konduit.ai/t/advice-on-non-square-input/273/4 "2020-03-17T15:19:36Z")

</div>

The width dimension of the input for the 77th layer is smaller than the kernel for the convultion layer. You would have to change the kernel size to 4, 2 (or 2, 4. I’m not sure whether width or height is the first argument) in order to match the input.

---

<div class="post-metadata">

**Author:** ![hbitteur](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@hbitteur](https://community.konduit.ai/u/hbitteur)\
**Post date:** [March 22, 2020, 9:18am UTC](https://community.konduit.ai/t/advice-on-non-square-input/273/5 "2020-03-22T09:18:13Z")

</div>

Thanks for your remarks.

It took me some time to understand that shrinking the input image size implied to also modify the network architecture. The reason is the combined size reductions performed one after the other by all the convolutional layers.

So, I discarded ResNet50 for something much smaller: ResNet18, as least as a starting point. And it works.

Thank you all,  
/Hervé
