Open ChowderII opened 4 years ago
@ChowderII
I have tried in colab with TF nightly version (2.4.0-dev20200811
) and i am seeing different error message.
TypeError: 'module' object is not callable
Please, find the gist here.Thanks!
Even if your error is different, it still implies there is something wrong with the load function right? (I don't know if the tag awaiting response is for me or the tensorflow gods)
I don't think we can always expect the customized subclass models be able to load with keras API. Instead, could you first try the savedmodel API: https://www.tensorflow.org/api_docs/python/tf/saved_model/load?
I did try to load it that way, it gives me an AutoTrackable object that I can't seem to interact with the way I want. I want to save the as .h5 for another application but I get the same error message as my first post when I try to save it that way. In the README of object detection, they state that their model for TF2 is built using keras, why can't we load it using keras too?
@ravikyram
It seems this user is trying to do what I am trying to do as well. But we cannot perform tf.keras.models.load_model
it crashes every time.
I'm very sorry to multi post but is there anything I can do to help you help me? Let me know if my problem is not clear or needs clarification. Thank you!
I have a similar issue with a different object detection model (efficientdet/d0).
To reproduce:
My Environment is
import tensorflow as tf
effdet0_path = "efficientdet_d0_coco17_tpu-32/saved_model"
keras_model = tf.keras.models.load_model(effdet0_path, compile=False)
Error:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-12-de1beb37d1c6> in <module>
----> 1 keras_model = tf.keras.models.load_model(effdet0_path, compile=False)
~/anaconda/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py in load_model(filepath, custom_objects, compile, options)
185 if isinstance(filepath, six.string_types):
186 loader_impl.parse_saved_model(filepath)
--> 187 return saved_model_load.load(filepath, compile, options)
188
189 raise IOError(
~/anaconda/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in load(path, compile, options)
119
120 model = tf_load.load_internal(
--> 121 path, options=options, loader_cls=KerasObjectLoader)
122
123 # pylint: disable=protected-access
~/anaconda/lib/python3.6/site-packages/tensorflow/python/saved_model/load.py in load_internal(export_dir, tags, options, loader_cls)
631 try:
632 loader = loader_cls(object_graph_proto, saved_model_proto, export_dir,
--> 633 ckpt_options)
634 except errors.NotFoundError as err:
635 raise FileNotFoundError(
~/anaconda/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in __init__(self, *args, **kwargs)
192 self._models_to_reconstruct = []
193
--> 194 super(KerasObjectLoader, self).__init__(*args, **kwargs)
195
196 # Now that the node object has been fully loaded, and the checkpoint has
~/anaconda/lib/python3.6/site-packages/tensorflow/python/saved_model/load.py in __init__(self, object_graph_proto, saved_model_proto, export_dir, ckpt_options)
128 self._concrete_functions[name] = _WrapperFunction(concrete_function)
129
--> 130 self._load_all()
131 self._restore_checkpoint()
132
~/anaconda/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in _load_all(self)
219
220 # Finish setting up layers and models. See function docstring for more info.
--> 221 self._finalize_objects()
222
223 @property
~/anaconda/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in _finalize_objects(self)
524 layers_revived_from_saved_model.append(node)
525
--> 526 _finalize_saved_model_layers(layers_revived_from_saved_model)
527 _finalize_config_layers(layers_revived_from_config)
528
~/anaconda/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in _finalize_saved_model_layers(layers)
704 call_fn = _get_keras_attr(layer).call_and_return_conditional_losses
705 if call_fn.input_signature is None:
--> 706 inputs = infer_inputs_from_restored_call_function(call_fn)
707 else:
708 inputs = call_fn.input_signature[0]
~/anaconda/lib/python3.6/site-packages/tensorflow/python/keras/saving/saved_model/load.py in infer_inputs_from_restored_call_function(fn)
980 return tensor_spec.TensorSpec(defun.common_shape(x.shape, y.shape),
981 x.dtype, x.name)
--> 982 spec = fn.concrete_functions[0].structured_input_signature[0][0]
983 for concrete in fn.concrete_functions[1:]:
984 spec2 = concrete.structured_input_signature[0][0]
IndexError: list index out of range
@ChowderII have you solved this issue? I also want to load the OD models with keras API.
@ChowderII have you solved this issue? I also want to load the OD models with keras API.
I have not, no one is helping. It seems to be a problem with tensorflow itself. We need to wait until the assignees have time to look at this issue.
Prerequisites
Please answer the following questions for yourself before submitting an issue.
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:
3. Steps to reproduce
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