Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

'Please provide input shape. Given input shape - ', input_shape) ValueError: ('MXNet Backend: Cannot automatically infer shape for convolution operator.Please provide input shape. Given input shape - ', (0, 3, 0, 0)) #188

Open
wiwatarm opened this issue Oct 5, 2018 · 4 comments
Labels

Comments

@wiwatarm
Copy link

wiwatarm commented Oct 5, 2018

Hi! I'm using Keras-Mxnet backend (Keras version 2.1.6). When I started Keras, I used this command KERAS_BACKEND=mxnet python to start python. here is my following code. Usually, it worked just fine with Keras-tensorflow backend, but I have no idea where it has started to fail.

from keras import models
models.load_model(filepath=inception_trained.h5)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/models.py", line 357, in load_model
    model = model_from_config(model_config, custom_objects=custom_objects)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/models.py", line 434, in model_from_config
    return layer_module.deserialize(config, custom_objects=custom_objects)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 144, in deserialize_keras_object
    list(custom_objects.items())))
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/engine/topology.py", line 2525, in from_config
    process_layer(layer_data)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/engine/topology.py", line 2511, in process_layer
    custom_objects=custom_objects)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/layers/__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 144, in deserialize_keras_object
    list(custom_objects.items())))
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/engine/topology.py", line 2535, in from_config
    process_node(layer, node_data)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/engine/topology.py", line 2492, in process_node
    layer(input_tensors[0], **kwargs)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/engine/topology.py", line 619, in __call__
    output = self.call(inputs, **kwargs)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/layers/convolutional.py", line 172, in call
    dilation_rate=self.dilation_rate)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/backend/mxnet_backend.py", line 3112, in conv2d
    padding_mode=padding, data_format=data_format)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/backend/mxnet_backend.py", line 89, in func_wrapper
    train_symbol = func(*args, **kwargs)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/backend/mxnet_backend.py", line 4226, in _convnd
    filter_dilation)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/backend/mxnet_backend.py", line 4170, in _preprocess_padding_mode
    _validate_conv_input_shape(input_shape)
  File "/home/datawow/miniconda3/envs/mx_net/lib/python3.7/site-packages/keras/backend/mxnet_backend.py", line 4156, in _validate_conv_input_shape
    'Please provide input shape. Given input shape - ', input_shape)
ValueError: ('MXNet Backend: Cannot automatically infer shape for convolution operator.Please provide input shape. Given input shape - ', (0, 3, 0, 0))

I tried to fix it by infer to models.Layers.input = (256,256,3), but did not work.

@roywei
Copy link

roywei commented Oct 5, 2018

@wiwatarm thanks for this issue. is inception_trained.h5 trained using MXNet backend?

Also the version of keras and mxnet you are using would be helpful.
use pip list | grep mxnet in command line or import keras and keras.__version__

@roywei roywei added the training label Oct 5, 2018
@wiwatarm
Copy link
Author

@wiwatarm thanks for this issue. is inception_trained.h5 trained using MXNet backend?

Also the version of keras and mxnet you are using would be helpful.
use pip list | grep mxnet in command line or import keras and keras.__version__

thanks for the answer my keras version is '2.2.2', and no, the model has been trained by keras-tensorflow backend.

@roywei
Copy link

roywei commented Oct 17, 2018

@wiwatarm unfortunately, mxnet backend does not support load weights trained using other backends yet. You need to pre-train using mxnet backend and load it for fine-tuning

@hadjipantelis
Copy link

@roywei Thank you for your answer. It makes sense. That said, is there a chance that this functionality is supported? For example, even the relatively innocuous:

>>> from keras.applications.inception_v3 import InceptionV3
# Using MXNet backend
>>> InceptionV3_base_model = InceptionV3(weights="imagenet", include_top=False)

kills the code, so we canot use standard pre-trained keras models directly.
(keras-mxnet==2.2.4.2)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants