keras-team / tf-keras

The TensorFlow-specific implementation of the Keras API, which was the default Keras from 2019 to 2023.
Apache License 2.0
58 stars 28 forks source link

MobileNetV3 models can't infer the static shape #133

Open shkarupa-alex opened 3 years ago

shkarupa-alex commented 3 years ago

System information.

Describe the problem. MobileNetV3 models can't estimate output shape of the intermediate layers because some functions (activations like hard_swith, i suppose) did not wrapped with layers.

Describe the current behavior. Exception raised when compute_output_shape executed.

Describe the expected behavior. Just like ALL other models in keras.applications, MobileNetV3* models should be able to compute their output shapes.

Contributing.

Standalone code to reproduce the issue.

Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/Jupyter/any notebook.

Source code / logs.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in compute_output_shape(self, input_shape)
    782         try:
--> 783           outputs = self(inputs, training=False)
    784         except TypeError as e:

9 frames
/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
    976       return self._functional_construction_call(inputs, args, kwargs,
--> 977                                                 input_list)
    978 

/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
   1114       outputs = self._keras_tensor_symbolic_call(
-> 1115           inputs, input_masks, args, kwargs)
   1116 

/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs)
    847     else:
--> 848       return self._infer_output_signature(inputs, args, kwargs, input_masks)
    849 

/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in _infer_output_signature(self, inputs, args, kwargs, input_masks)
    887           inputs = self._maybe_cast_inputs(inputs)
--> 888           outputs = call_fn(inputs, *args, **kwargs)
    889 

/usr/local/lib/python3.7/dist-packages/keras/layers/core.py in _call_wrapper(*args, **kwargs)
   1349     def _call_wrapper(*args, **kwargs):
-> 1350       return self._call_wrapper(*args, **kwargs)
   1351     self.call = tf.__internal__.decorator.make_decorator(function, _call_wrapper)

/usr/local/lib/python3.7/dist-packages/keras/layers/core.py in _call_wrapper(self, *args, **kwargs)
   1381       kwargs.pop('name', None)
-> 1382       result = self.function(*args, **kwargs)
   1383     self._check_variables(created_variables, tape.watched_variables())

/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
    205     try:
--> 206       return target(*args, **kwargs)
    207     except (TypeError, ValueError):

TypeError: _add_dispatch() missing 1 required positional argument: 'y'

The above exception was the direct cause of the following exception:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-3-fe10d8214bfb> in <module>()
      1 base_model = mobilenet_v3.MobileNetV3Large(include_top=False, weights=None)
----> 2 base_model.compute_output_shape(input_shape=[224, 224, 3])

/usr/local/lib/python3.7/dist-packages/keras/engine/functional.py in compute_output_shape(self, input_shape)
    468           layer_input_shapes = tf_utils.convert_shapes(
    469               layer_input_shapes, to_tuples=True)
--> 470           layer_output_shapes = layer.compute_output_shape(layer_input_shapes)
    471           # Convert back to TensorShapes.
    472           layer_output_shapes = tf_utils.convert_shapes(

/usr/local/lib/python3.7/dist-packages/keras/engine/base_layer.py in compute_output_shape(self, input_shape)
    787               'layer\'s output. Please implement the '
    788               '`compute_output_shape` method on your layer (%s).' %
--> 789               self.__class__.__name__) from e
    790       return tf.nest.map_structure(lambda t: t.shape, outputs)
    791     raise NotImplementedError(

NotImplementedError: We could not automatically infer the static shape of the layer's output. Please implement the `compute_output_shape` method on your layer (TFOpLambda).
gowthamkpr commented 2 years ago

@shkarupa-alex There is a PR for this https://github.com/keras-team/keras/pull/15529 which is not yet merged. PTAL. Thanks!

google-ml-butler[bot] commented 2 years ago

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] commented 2 years ago

Closing as stale. Please reopen if you'd like to work on this further.

google-ml-butler[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] commented 2 years ago

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] commented 2 years ago

Closing as stale. Please reopen if you'd like to work on this further.

google-ml-butler[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No