-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
"ValueError: The layer sequential has never been called and thus has no defined output." when the model's been build and called #20116
Comments
Hi @Senantq, could you try calling model directly via model(...) rather than model.call? Additionally I see that |
Hi @nkovela1 and thank you for your help. |
Isn't this the same issue as fixed here? You may try using keras-nightly |
I have just installed keras-nightly 3.5.0.dev2024090403 in a new conda environment, and it does'nt solve the problem unfortunately |
model = keras.Sequential([
Input(shape=(10, 10, 3)),
Conv2D(filters=32, kernel_size=3),
])
model_2 = Model([model.inputs], [model.output]) # <--change errors in a similar way.
Specifically, |
Hello ghsanti and thank you for answer. I must admit that it is still not totally clear to me. Particularly, I don't see why
worked with keras 2 (installed via tensorflow==2.10) and not with the newer versions. Have I missed something during the change to keras 3? I don't see it listed as one of the new major releases features at #18467 Plus, it feels like it breaks a of not that old codes such as saliency methods or transfer learning codes. |
model = keras.Sequential([ Input(shape=(4, 4, 3)), Flatten(), Dense(units=5)])
model(keras.Input((4, 4, 3)))
model_2 = keras.Model([model.inputs], [model.output])
i= Input(shape=(4, 4, 3))
x= Flatten()(i)
x= Dense(units=5)(x)
model1 = keras.Model(i, x)
model2 = keras.Model([model1.inputs], [model1.output]) Sequential needs the extra call to build the layers. Other related threads:
Someone comments about the same contradiction here
Here is a comment suggesting something similar. |
I agree that the error message should be at least a bit more explicit if possible. In any case, thank for the time spent. |
Hi @Senantq, Are you still able to reproduce this issue ? |
I am currently using tensorflow 2.17 with keras 3.4.1 under Ubuntu 24.04 LTS. I have also reproduced the issue with tf-nightly 2.18.0.dev20240731 (keras nightly 3.4.1.dev2024073103).
I encountered the issue when i downloaded a model I have ran on a cluster under tf 2.17/keras 3.4.1. I then tried to obtain some saliency maps on my computer after re-building the model without redifining all its layers from scratch.
See the following google drive for a reprex with the code, model and a data sample: https://drive.google.com/drive/folders/15J_ghWXWbs8EmSVXedH6sJRvJcPUSTIW?usp=sharing
But it raises the following traceback:
There is two workarounds where the value error is not raised:
1°) When using grad_model = keras.models.Model(
[model.inputs],
[model.get_layer(last_conv_layer_name).output,
model.get_layer(Name_of_last_deep_layer).output]) but it results in none gradients in the rest of my code
2°) When redifining completely the model from scratch and loading only the weights, i.e., when using:
model.load_weights(...) -> this one doesn't raises any error
Thanks a lot!
The text was updated successfully, but these errors were encountered: