Skip to content
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

Keras3 Submodel Creation Issue: Initial Layer Skipping Problem #2314

Closed
hamidriasat opened this issue Jan 23, 2024 · 4 comments
Closed

Keras3 Submodel Creation Issue: Initial Layer Skipping Problem #2314

hamidriasat opened this issue Jan 23, 2024 · 4 comments
Assignees
Labels

Comments

@hamidriasat
Copy link
Contributor

Goal:

The objective is to take the current model and extract a submodel by using only a portion of it, skipping some of the first layers and passing the input straight to a middle layer, and receiving the result from later layers.

Current Behavior:

Now, this was supported in Keras 2, but when using the same code in Keras3, it stops at the given output layer but does not skip the initial layers. Instead of starting from the specified/given layer, it starts from the first layer of the base model, which is not required.

Expected Behavior:

Rather of starting from the first layer of the base model, create a submodel from the given/specified layer. Imagine that you require a new model, one that does not require the initial layers of an already-existing model.
From here I found no way to achieve this.

Steps To Reproduce:

Colab link with further details to reproduce and understand problem.

Code Snippet:

import keras_cv
import keras

backbone = keras_cv.models.ResNet34Backbone()

submodel = keras.models.Model(
        inputs=backbone.get_layer("v2_stack_0_block1_1_conv").input,
        outputs=backbone.get_layer("v2_stack_0_block3_out").output
    )
submodel.summary()
@hamidriasat
Copy link
Contributor Author

@divyashreepathihalli @fchollet Kindly check this issue it will help me complete this pull request.

@divyashreepathihalli
Copy link
Collaborator

@hamidriasat what you are doing in the colab looks right and I got identical outputs for keras 2 and keras 3.

@hamidriasat
Copy link
Contributor Author

@divyashreepathihalli Thanks, Kindly Restart Session after executing 3rd last cell where we update Keras to version 3 (cell code below), then you will find a different submodel.

!pip install --upgrade keras-cv tensorflow
!pip install --upgrade keras
# After installation click on restart session button to load latest version of keras.

@fchollet fchollet self-assigned this Feb 1, 2024
@hamidriasat
Copy link
Contributor Author

Fixed.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants