# Error input size in multilayer conf

**URL:** <https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450>\
**Category:** DL4J\
**Created:** [April 25, 2020, 1:20pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450 "2020-04-25T13:20:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![getCamBill](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@getCamBill](https://community.konduit.ai/u/getCamBill)\
**Post date:** [April 25, 2020, 1:20pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450/1 "2020-04-25T13:20:12Z")

</div>

Hello I’m a french computer science student and I’m starting to use DL4J. But one exception (among others I guess) gives me a hard time:  
Exception in thread “main” org.deeplearning4j.exception.DL4JInvalidInputException: Input size (1 columns; shape = [15, 1]) is invalid: does not match layer input size (layer # inputs = 2) (layer name: layer0, layer index: 0, layer type: DenseLayer)

I have a csv file with 2 columns and looks like this (with about 30,000 lines):  
13264.620117,2  
14.82,5  
1505.619995,6  
20.98,1  
23.27,7  
35.57,3  
36.150002,9

The second column represents the label and the first one a value (any)

My model configuration is as follows:

Does anyone have any answers or advice

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/konduit/original/1X/a52e410b9ca45f8fc0d50c1b9200e420b0fca4ee.png)

---

<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:** [April 25, 2020, 1:56pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450/2 "2020-04-25T13:56:53Z")

</div>

There are a few things wrong here.

> [@getCamBill](#):
>
> I have a csv file with 2 columns and looks like this (with about 30,000 lines)

> [@getCamBill](#):
>
> The second column represents the label and the first one a value (any)

Those two statements together mean that you have _one_ (=1) input and _one_ output.

Yet you setup your model to use two inputs and outputs:  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/konduit/original/1X/8556a3e0831ca94286945e2eb91f0ff685ff94c9.png)

Then, you go on and configure your network very weirdly:  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/konduit/original/1X/4c514633f4c9da61338764e610bd1b25a55cb6e5.png)  
What you are doing here is that you tell your model that the first layer is going to get `numInputs` _and_ your second (=output in this case) layer is going to get `numInputs` while at the same time, you tell it to use `outputNum` outputs.

Given that you say that you have struggled with other problems, I expect that you probably had `numInputs` and `numOutputs` as different values orginally, but at some point changed that to `2` so they are equal and things don’t “break”.

`.nIn` and `.nOut` specify for _each layer_ what they expect to get in, and how much they should output. For example, if you wanted to configure a network that gets an MNIST sized input (28x28 pixel=784 values) and then goes though several layers getting smaller until it goes to the final 10 possible results, i.e. a 6 layer network that goes like 784 → 512 → 256 → 128 → 64 → 32 → 10, you would start with the first layer having `.nIn(784).nOut(512)` and the next layer having `.nIn(512).nOut(256)`, the next layer having `.nIn(256).nOut(128)`, …, with the output layer then having `.nIn(32).nOut(10)`.

As you can see that is a lot of redundancy, that can be automatically inferred, so instead of setting `.nIn` on every layer manually, you can also add `.setInputType(InputType.feedForward(numInputs))` and it would take care of calculating the correct `.nIn` value for you, even when you go on to creating more complex networks. For the example I’ve given above it would look like this: `.setInputType(InputType.feedForward(784))` and then only setting `.nOut` would still be required.

---

<div class="post-metadata">

**Author:** ![getCamBill](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@getCamBill](https://community.konduit.ai/u/getCamBill)\
**Post date:** [April 25, 2020, 2:47pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450/5 "2020-04-25T14:47:58Z")

</div>

Thank you  
So I changed the Multilayer conf as follows:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/konduit/original/1X/76ec8934389520a48706ff9d1d1d7d31ce80771c.png)  
But I have the same exception coming back:

Exception in thread “main” org.deeplearning4j.exception.DL4JInvalidInputException: Input size (1 columns; shape = [15, 1]) is invalid: does not match layer input size (layer # inputs = 2) (layer name: layer0, layer index: 0, layer type: DenseLayer)

Perhaps my error is in my DataSetIterator…?

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/konduit/original/1X/4a4bdc84c1006ba86ef430e6b6e62f68c7f2d9ac.png)

Or maybe I misunderstood your explanation, too.

Also, (silly question) why the error occurs when :

for(int i=0; i\<1000; i++ ) {  
model.fit(trainIter); ← THAT LINE ???  
}

The nIn are comment’s

---

<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:** [April 25, 2020, 3:00pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450/6 "2020-04-25T15:00:14Z")

</div>

Ideally, you would edit your posts instead of posting new ones. I’ve merged them now.

Your problem is that you _still_ used `numInputs = 2`, which says that you have 2 input values, while you have said yourself:

> [@getCamBill](#):
>
> The second column represents the label and the first one a value (any)

So you actually only have a single input value and you have to reflect that in your numInputs variable!  
That was the very first thing I told you in my first answer.

> [@getCamBill](#):
>
> Also, (silly question) why the error occurs when :
> 
> for(int i=0; i\<1000; i++ ) {  
> model.fit(trainIter); ← THAT LINE ???  
> }

The training only starts at this point. This is where the data first meets the model. And the error you are getting is telling you exactly that: The data you are feeding it (15 examples with 1 value) doesn’t match what it expects (examples with 2 values).

---

<div class="post-metadata">

**Author:** ![getCamBill](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@getCamBill](https://community.konduit.ai/u/getCamBill)\
**Post date:** [April 25, 2020, 3:15pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450/7 "2020-04-25T15:15:09Z")

</div>

Thanks, I’ll take a closer look.

For both posts, as I’m a new user, I can’t put 2 pictures per post, so I made 2 posts.

And thanks again

---

<div class="post-metadata">

**Author:** ![getCamBill](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@getCamBill](https://community.konduit.ai/u/getCamBill)\
**Post date:** [April 25, 2020, 3:31pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450/8 "2020-04-25T15:31:58Z")

</div>

Yeah, that was the mistake all along.  
And then I had this mistake:  
Exception in thread “main” java.lang.IllegalArgumentException: Labels and preOutput must have equal shapes: got shapes [15, 10] vs [15, 2]

So I modified numOutpus = 10  
now it’s rolling!

All that’s left is to make a relevant and viable model.

Thanks again @treo !  
PS : I didn’t know this forum and it was hard to find docs for DL4j and in french not worth it …

Translated with [DeepL Translate: The world's most accurate translator](http://www.DeepL.com/Translator) (free version)

---

<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:** [April 25, 2020, 5:43pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450/9 "2020-04-25T17:43:14Z")

</div>

> [@getCamBill](#):
>
> I didn’t know this forum and it was hard to find docs for DL4j and in french not worth it …

Can you tell me more about that? The docs and this forum are linked directly from [deeplearning4j.org](http://deeplearning4j.org), and the forum is again linked from the documentation.  
Is there anything we can do to make this any easier?

---

<div class="post-metadata">

**Author:** ![getCamBill](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@getCamBill](https://community.konduit.ai/u/getCamBill)\
**Post date:** [April 25, 2020, 6:16pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450/10 "2020-04-25T18:16:24Z")

</div>

> [@treo](#):
>
> [deeplearning4j.org](http://deeplearning4j.org)

I expressed myself badly, I would say that one falls very often on the gitter forum (and its continuous chat format is not very practical to my taste) and rarely on this forum. And I didn’t search enough on [deeplearning4j.org](http://deeplearning4j.org) to find it then.

so there’s not much to really change.  
I’d say, I need to look for something better.

---

<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:** [April 25, 2020, 6:36pm UTC](https://community.konduit.ai/t/error-input-size-in-multilayer-conf/450/11 "2020-04-25T18:36:17Z")

</div>

> [@getCamBill](#):
>
> one falls very often on the gitter forum (and its continuous chat format is not very practical to my taste)

I see. That is actually the reason we abandoned gitter in favor of this forum.
