tensorflow: "IndexError: list index out of range" when load EfficientDet SavedModel with tf.keras
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
- TensorFlow installed from (source or binary): binary
- TensorFlow version (use command below): 2.3.0
- Python version: 3.6
- Bazel version (if compiling from source):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version: No
- GPU model and memory: No
You can collect some of this information using our environment capture script You can also obtain the TensorFlow version with:
- TF 1.0:
python -c "import tensorflow as tf; print(tf.GIT_VERSION, tf.VERSION)" - TF 2.0:
python -c "import tensorflow as tf; print(tf.version.GIT_VERSION, tf.version.VERSION)"
Describe the current behavior
I try to load SavedModel efficientDetD0 with load_model of keras:
model = tf.keras.models.load_model("saved_model")' 'model.summary()
And following error occur:
Traceback (most recent call last): File “E:/Detection/test_infer_model.py”, line 129, in <module> model = tf.keras.models.load_model(“saved_model”) File “C:\Users\Luxury\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\saving\save.py”, line 187, in load_model return saved_model_load.load(filepath, compile, options) File “C:\Users\Luxury\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\saving\saved_model\load.py”, line 121, in load path, options=options, loader_cls=KerasObjectLoader) File “C:\Users\Luxury\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\saved_model\load.py”, line 633, in load_internal ckpt_options) File “C:\Users\Luxury\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\saving\saved_model\load.py”, line 194, in init super(KerasObjectLoader, self).init(*args, **kwargs) File “C:\Users\Luxury\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\saved_model\load.py”, line 130, in init self._load_all() File “C:\Users\Luxury\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\saving\saved_model\load.py”, line 221, in _load_all self._finalize_objects() File “C:\Users\Luxury\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\saving\saved_model\load.py”, line 526, in _finalize_objects _finalize_saved_model_layers(layers_revived_from_saved_model) File “C:\Users\Luxury\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\saving\saved_model\load.py”, line 706, in _finalize_saved_model_layers inputs = infer_inputs_from_restored_call_function(call_fn) File “C:\Users\Luxury\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\saving\saved_model\load.py”, line 982, in infer_inputs_from_restored_call_function spec = fn.concrete_functions[0].structured_input_signature[0][0] IndexError: list index out of range **Standalone code to reproduce the issue ** link colab: https://colab.research.google.com/drive/1fR8nu3INEWVUJJhex3Dline10296vxri?usp=sharing and model: https://drive.google.com/file/d/18D8NQp9zP4UW06jeG_75YQWyB531CWUj/view?usp=sharing I lost 2 days for searching on internet, stackoverflow even this repo’s issue but no result, please help !
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (5 by maintainers)
There’s a workaround works for me that no need to change your tf version:
tf version: 2.4.0, but I think others would be ok.
My model settings: Model_type: keras subclassed model Save_way: used model.save() to save Load_way: used tf.keras.models.load_model() to load.
MY Error raised in: tensorflow\python\keras\saving\saved_model\load.py line_1067 (or around)
I changed the original code:
to:
What I met was a error induced by the fn.concrete_functions which lets the code run twice, I haven’t dig into python and tensorflow so I don’t know how could it be like this, but the first time the above part has a length of 4 (in my case), while at the second time it has a length of 0. So here maybe where the question is.
I used
for test, it turns out to be:
4, list, 0, list
roughly, but just like this. (If anyone know what’s this is, I’d appreciate it if you tell me sth about it : )
Wish I could help you guys to solve your problem.
I am also getting the same error with models:
The config files are the same the ones in: models/research/object_detection/configs/tf2/
I first train with: models/research/object_detection/model_main_tf2.py
And then I export with: models/research/object_detection/exporter_main_v2.py
But then when I try to load the exported model I get the error:
System Information:
Code:
I can load and make predictions with
However I wish to load the saved model so that I can edit it and then export it with coreML.
Also fails with another model:
TF 2.3.1