# Can KerasModelImport import arbitary sized image?

**URL:** https://community.konduit.ai/t/can-kerasmodelimport-import-arbitary-sized-image/545
**Category:** DL4J
**Created:** [May 21, 2020, 7:52am UTC](https://community.konduit.ai/t/can-kerasmodelimport-import-arbitary-sized-image/545 "2020-05-21T07:52:45Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![yptheangel](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/yptheangel/32/128_2.png) [@yptheangel](https://community.konduit.ai/u/yptheangel)
#### Post date: [May 21, 2020, 7:52am UTC](https://community.konduit.ai/t/can-kerasmodelimport-import-arbitary-sized-image/545/1 "2020-05-21T07:52:45Z")

</div>

After testing keras model import, can DL4J take in arbitary sized input image? Model is a FCN(fully convolutional network), yolov3 model trained in keras.  
in keras (not tf.keras)  
`Input(shape=(None, None, 3))`

keras model import worked when I set my input image to a fixed image, e.g. `Input(shape=(608, 608, 3))`

---

<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: [May 21, 2020, 2:46pm UTC](https://community.konduit.ai/t/can-kerasmodelimport-import-arbitary-sized-image/545/2 "2020-05-21T14:46:21Z")

</div>

Did you get any specific error when you tried to import it with the unspecified input sizes?

---

<div class="post-metadata">

### Author: ![yptheangel](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/yptheangel/32/128_2.png) [@yptheangel](https://community.konduit.ai/u/yptheangel)
#### Post date: [May 22, 2020, 3:05pm UTC](https://community.konduit.ai/t/can-kerasmodelimport-import-arbitary-sized-image/545/3 "2020-05-22T15:05:36Z")

</div>

I’m using this line  
model = KerasModelImport.importKerasModelAndWeights(“model.h5”);  
model.init();  
The error stack is

 ![kerasmodelimport](https://canada1.discourse-cdn.com/flex035/uploads/konduit/original/1X/a889e24b60cddf16510c9d94c44234be9769fb1d.jpeg)

The error went away when I resave my model with a fixed Input shape instead of `Input(shape=(None, None, 3))`

Model can be dowloaded here: [yolov3](https://drive.google.com/open?id=1g9ZtBOknSMgV8U-PJ1EaS95IHvHBZelx)  
Can view with Netron.

---

<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: [May 22, 2020, 4:42pm UTC](https://community.konduit.ai/t/can-kerasmodelimport-import-arbitary-sized-image/545/4 "2020-05-22T16:42:22Z")

</div>

> [@yptheangel](#):
>
> model.init();

You shouldn’t do that after import, as it initializes the model, i.e. it overwrites your imported weights.

But that isn’t the problem yet, as it does’t even get that far.

Because what you’re seeing is a validation error, I guess there is not way around defining an input shape.

But I think you should still be able to apply the imported model to arbitrary sized images (as long as they are big enough to not run into size issues at another point).

---

<div class="post-metadata">

### Author: ![yptheangel](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/yptheangel/32/128_2.png) [@yptheangel](https://community.konduit.ai/u/yptheangel)
#### Post date: [May 23, 2020, 12:51am UTC](https://community.konduit.ai/t/can-kerasmodelimport-import-arbitary-sized-image/545/5 "2020-05-23T00:51:51Z")

</div>

ok, got it. Thanks, surprisingly with `model.init()` the model is still able to work as expected

---

<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: [May 23, 2020, 9:07am UTC](https://community.konduit.ai/t/can-kerasmodelimport-import-arbitary-sized-image/545/6 "2020-05-23T09:07:27Z")

</div>

> [@yptheangel](#):
>
> surprisingly with `model.init()` the model is still able to work as expected

Oh, you’re actually right, I’ve double checked the code, and it has been like that for quite a long time already.

There is a check that an already initialized model doesn’t get reinitialized. I still advise against having that there, as it is a no-op in that case.
