Skip to content

Cannot open object detection model using tf.keras.models.load #9087

@ChowderII

Description

@ChowderII

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am using the latest TensorFlow Model Garden release and TensorFlow 2.
  • I am reporting the issue to the correct repository. (Model Garden official or research directory)
  • I checked to make sure that this issue has not already been filed.

1. The entire URL of the file you are using

http://download.tensorflow.org/models/object_detection/tf2/20200711/ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz

2. Describe the bug

tf.keras.models.load fails to open the model with error:

Traceback (most recent call last):
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-5-a1fec4d829cb>", line 1, in <module>
    loaded_model = tf.keras.models.load_model('resources/ssd_mobilenetv2/saved_model')
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 150, in load_model
    return saved_model_load.load(filepath, compile)
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\saving\saved_model\load.py", line 89, in load
    model = tf_load.load_internal(path, loader_cls=KerasObjectLoader)
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\saved_model\load.py", line 552, in load_internal
    export_dir)
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\saving\saved_model\load.py", line 118, in __init__
    super(KerasObjectLoader, self).__init__(*args, **kwargs)
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\saved_model\load.py", line 121, in __init__
    self._load_all()
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\saved_model\load.py", line 239, in _load_all
    node, setter = self._recreate(proto)
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\saved_model\load.py", line 322, in _recreate
    return factory[kind]()
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\saved_model\load.py", line 309, in <lambda>
    "user_object": lambda: self._recreate_user_object(proto.user_object),
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\saved_model\load.py", line 328, in _recreate_user_object
    return self._recreate_base_user_object(proto)
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\saving\saved_model\load.py", line 216, in _recreate_base_user_object
    return revived_cls._init_from_metadata(metadata)  # pylint: disable=protected-access
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\saving\saved_model\load.py", line 297, in _init_from_metadata
    revived_obj = cls(**init_args)
  File "C:\Users\brackman\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow_core\python\keras\engine\input_layer.py", line 86, in __init__
    batch_size = batch_input_shape[0]
KeyError: 0

3. Steps to reproduce

  1. Download the model from the above link.
  2. Run this:
import tensorflow as tf
loaded_model = tf.keras.models.load_model('resources/ssd_mobilenetv2/saved_model')
# keep in mind my path is probably different than yours

4. Expected behavior

I expect to have a Keras instance of the model.

5. Additional context

I am quite new to this and I don't quite know what can be useful to you. Let me know if there are additional information I can provide to help you.

I am fairly certain I am not using that correctly. If it helps you understand why I am trying to do this, I am trying to generate an .hdf5 model for another purpose.

6. System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
  • Mobile device name if the issue happens on a mobile device: N/A
  • TensorFlow installed from (source or binary): binary (conda)
  • TensorFlow version (use command below): 2.2.0
  • Python version: 3.7.7
  • Bazel version (if compiling from source): N/A
  • GCC/Compiler version (if compiling from source): N/A
  • CUDA version: release 10.1 V10.1.243,
  • cuDNN version: 7.6.5
  • GPU model and memory: GeForce GTX 1060 6GB

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions