# BatchNormalization Layer only support single int as nIn and nOut?

**URL:** <https://community.konduit.ai/t/batchnormalization-layer-only-support-single-int-as-nin-and-nout/900>\
**Category:** DL4J\
**Created:** [October 1, 2020, 3:21am UTC](https://community.konduit.ai/t/batchnormalization-layer-only-support-single-int-as-nin-and-nout/900 "2020-10-01T03:21:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![XJ8](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/xj8/32/326_2.png) [@XJ8](https://community.konduit.ai/u/XJ8)\
**Post date:** [October 1, 2020, 3:21am UTC](https://community.konduit.ai/t/batchnormalization-layer-only-support-single-int-as-nin-and-nout/900/1 "2020-10-01T03:21:28Z")

</div>

I tired to use BatchNormalization layer after my 1DCNN, however, it always gives me an error message showing either nIn/nOut is not specified, or does not support rank 3, so I can’t use it.

My workaround is to reshape the output of 1DCNN from 2D to 1D, specify nOut as a singer int. In this way I successfully added Batch Normalization layer into my model. Is it correct to do it in this way?

The problem is that when I trained a model in Keras, the model with BN is better than the model without BN. But when I use the above workaround in DL4J, and the model with BN perform worth than the model without. I am wondering what the reason is, and how to fix it?

Thanks.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [October 1, 2020, 4:12am UTC](https://community.konduit.ai/t/batchnormalization-layer-only-support-single-int-as-nin-and-nout/900/2 "2020-10-01T04:12:48Z")

</div>

@XJ8 did you try using keras model import? [https://deeplearning4j.konduit.ai/keras-import/overview](https://deeplearning4j.konduit.ai/keras-import/overview)

---

<div class="post-metadata">

**Author:** ![XJ8](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/xj8/32/326_2.png) [@XJ8](https://community.konduit.ai/u/XJ8)\
**Post date:** [October 1, 2020, 2:18pm UTC](https://community.konduit.ai/t/batchnormalization-layer-only-support-single-int-as-nin-and-nout/900/3 "2020-10-01T14:18:04Z")

</div>

@agibsonccc Thank you, Adam.

I did try importing a different Keras model before, but batch normalization gave me problem. I think I should try again. Try to train from an imported model, and see if there is any performance difference.

---

<div class="post-metadata">

**Author:** ![XJ8](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/xj8/32/326_2.png) [@XJ8](https://community.konduit.ai/u/XJ8)\
**Post date:** [October 6, 2020, 3:39pm UTC](https://community.konduit.ai/t/batchnormalization-layer-only-support-single-int-as-nin-and-nout/900/4 "2020-10-06T15:39:32Z")

</div>

@agibsonccc It turns out my workaround is incorrect. I tried the same workaround logic in Keras, the performance is indeed worse with this BN workaround than without. Need to really understand BN to see the reasons.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [October 6, 2020, 10:17pm UTC](https://community.konduit.ai/t/batchnormalization-layer-only-support-single-int-as-nin-and-nout/900/5 "2020-10-06T22:17:39Z")

</div>

> [@XJ8](#):
>
> odel. Is it correct to do it in this way?
> 
> The problem is that when I trained a model in Keras, the mode

@XJ8 Could you post your architecture? Happy to help dive in a bit.

---

<div class="post-metadata">

**Author:** ![XJ8](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/xj8/32/326_2.png) [@XJ8](https://community.konduit.ai/u/XJ8)\
**Post date:** [October 6, 2020, 10:45pm UTC](https://community.konduit.ai/t/batchnormalization-layer-only-support-single-int-as-nin-and-nout/900/6 "2020-10-06T22:45:43Z")

</div>

Thanks. I posted the model in the same google drive folder. Because BN in DL4J doesn’t support rank 3, so for 1DCNN, I have to reshape it, batch normalize, and reshape back.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [October 6, 2020, 11:05pm UTC](https://community.konduit.ai/t/batchnormalization-layer-only-support-single-int-as-nin-and-nout/900/7 "2020-10-06T23:05:52Z")

</div>

@XJ8 could you post your architecture? That doesn’t sound right. If you’re using a 1d cnn, it should just be inserting a 1 in to the dimension for batch norm if needed, if needed any pre processor should take care of that.
