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

Unable to make two instances of the MobileNetV3 within the same model #19689

Closed
DLumi opened this issue May 8, 2024 · 2 comments · Fixed by #19695
Closed

Unable to make two instances of the MobileNetV3 within the same model #19689

DLumi opened this issue May 8, 2024 · 2 comments · Fixed by #19695

Comments

@DLumi
Copy link

DLumi commented May 8, 2024

I'm trying to use two distinct instances of mobilenet as sub-modules of one bigger model.

This is the error I receive.
ValueError: The name "MobilenetV3small" is used 2 times in the model. All operation names should be unique.

For some weird reason, Keras does not handle name uniqueness automatically, nor does it give you the option to specify model name.
I've tested it on MobileNetV3Small specifically, but I guess it's the case for all other models within the applications API.

See the code in a colab notebook below:

https://colab.research.google.com/drive/11R7m0yULUPhlN52ligdsPK18Mh6vKUCq?usp=sharing

P.S. I've tried to interface with _name attribute for each layer of the model, but it gets even worse from there, as it renders you unable to save the model throwing even more errors at you.

@sachinprasadhs sachinprasadhs added keras-team-review-pending Pending review by a Keras team member. type:Bug labels May 8, 2024
@divyashreepathihalli divyashreepathihalli removed the keras-team-review-pending Pending review by a Keras team member. label May 9, 2024
@sachinprasadhs sachinprasadhs added the stat:awaiting keras-eng Awaiting response from Keras engineer label May 9, 2024
@jeffcarp
Copy link
Collaborator

jeffcarp commented May 9, 2024

Thanks for the repro! Here's a smaller one:

x = keras.Input((None, None, 3))
out1 = keras.layers.Flatten(name='a')(x)
out2 = keras.layers.Flatten(name='a')(x)
keras.Model(inputs=x, outputs=[out1, out2])

I think when the layer or model name is hard-coded in a functional model (like it is here for MobileNetV3), it won't be auto-deduplicated. I think the fix here is to remove the hard-coded name.

jeffcarp pushed a commit to jeffcarp/keras that referenced this issue May 9, 2024
Fixes keras-team#19689

Opted to add a `model_name` arg to fix the issue since it's a similar
pattern in other `keras.applications` models. An alternative way is
to use `keras.src.utils.naming.uniquify` internally.
jeffcarp pushed a commit to jeffcarp/keras that referenced this issue May 9, 2024
Fixes keras-team#19689

Opted to add a `model_name` arg to fix the issue since it's a similar
pattern in other `keras.applications` models. An alternative way is
to use `keras.src.utils.naming.uniquify` internally.
@sachinprasadhs sachinprasadhs added stat:awaiting response from contributor and removed stat:awaiting keras-eng Awaiting response from Keras engineer labels May 9, 2024
jeffcarp pushed a commit to jeffcarp/keras that referenced this issue May 11, 2024
jeffcarp pushed a commit to jeffcarp/keras that referenced this issue May 11, 2024
fchollet pushed a commit that referenced this issue May 12, 2024
…19695)

Fixes #19689

Co-authored-by: Jeff Carpenter <jeffcarp@google.com>
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

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

Successfully merging a pull request may close this issue.

4 participants