Can KerasModelImport import arbitary sized image?

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))

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

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

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
Can view with Netron.

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).

ok, got it. Thanks, 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.

1 Like