New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TF1 Keras Model Errors on Loading using TF2 - IndexError: list index out of range #43561
Comments
I don't see your model definition but please double check our compatibility checklist: |
Thanks for your suggestion. It's a Keras Model, and I don't believe the compatibility checklist includes my issue. The model definition is here, and here's the code for training. |
I think you can try to upgrade your code: Also in the model definition you was using |
Thank you for your quick reply. I know the code needs to upgrade since it was the code for TF1, but what I'm asking is that can I just reuse in TF2 the model model_6_combined_2_DA.h5 trained in TF1? When I was trying to load the model in TF2.3.1 with the following code: from tensorflow.keras.models import load_model
model = load_model("model_6_combined_2_DA.h5")
print(model.summary()) An error was thrown: ~/.local/lib/python3.7/site-packages/tensorflow/python/keras/engine/functional.py in _should_skip_first_node(layer)
1031 return (isinstance(layer, Functional) and
1032 # Filter out Sequential models without an input shape.
-> 1033 isinstance(layer._layers[0], input_layer_module.InputLayer))
1034
1035
IndexError: list index out of range Other details can be found in the description part above. |
You can try to use Keras instead of |
Well, I have tried to use ~/.local/lib/python3.7/site-packages/tensorflow/python/keras/backend.py in function(inputs, outputs, updates, name, **kwargs)
3931 if updates:
3932 raise ValueError('`updates` argument is not supported during '
-> 3933 'eager execution. You passed: %s' % (updates,))
3934 from tensorflow.python.keras import models # pylint: disable=g-import-not-at-top
3935 from tensorflow.python.keras.utils import tf_utils # pylint: disable=g-import-not-at-top
ValueError: `updates` argument is not supported during eager execution. You passed: [<tf.Variable 'UnreadVariable' shape=() dtype=int64, numpy=0>, <tf.Variable 'UnreadVariable' shape=(3, 3, 3, 32) dtype=float32, numpy=
array([[[[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0.],
...... The gist is here: https://colab.research.google.com/drive/1OovMHVrMBsIwcwn2PUcgbEXHUfPLMdyM?usp=sharing Any suggestions? |
I am able to fix this issue when replace the code into following: def _should_skip_first_node(layer):
"""Returns True if the first layer node should not be saved or loaded."""
# Networks that are constructed with an Input layer/shape start with a
# pre-existing node linking their input to output. This node is excluded from
# the network config.
if layer._layers:
return (isinstance(layer, Functional) and
# Filter out Sequential models without an input shape.
isinstance(layer._layers[0], input_layer_module.InputLayer))
else:
return isinstance(layer, Functional) Can you suggest if there's some side effects? if no, I will make a pull request. Here is the gist:https://colab.research.google.com/drive/1jmp77GoIdZ8wy-hplmvq4MqgMRkSePsK?usp=sharing |
As it is not a bug I suggest you to close this and post you example in https://stackoverflow.com/questions/tagged/tensorflow |
System information
Describe the current behavior
When When trying to load the sequential model here using
tf.keras.models.load_model
in TF 2.3.1, an error is thrown at the following location:The model is believed to be trained using keras and under TF1.9, and the structure of the model can be found here, and here's the code for training.
Here you can find the full stack trace and running code under TF 2.3.1: https://colab.research.google.com/drive/1Lfo0O7D0cM8EtR0h6noqCoWqoqf8bzAD?usp=sharing
Then I downgraded to TF 2.2 and 2.1 with the same code above, it threw the error just as #35934 .
Then I downgraded to TF 2.0, the code was executing indefinitely. Finally I had to manually stop it:
Here you can find the full stack trace when I stopped the code under TF 2.0: https://colab.research.google.com/drive/1fCR-ci05NuYhQ8M9O2lRVG0F0YzI9Ggo?usp=sharing
Then I had no choice but to use TF 1.15.4 and Keras 2.3.1, and finally it worked out fine, inputs, outputs, summary etc. are all parsed correctly, as well as being able to run data through the model: https://colab.research.google.com/drive/1XaRMeiT1SefS6Q10wsa0y9rEercyFlCR?usp=sharing
Describe the expected behavior
I hope the Bug can be resolved so that TF2 can enhance the support for old models.
The text was updated successfully, but these errors were encountered: