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

Fix SegFormer Presets #2222

Merged
merged 4 commits into from
Dec 7, 2023
Merged

Fix SegFormer Presets #2222

merged 4 commits into from
Dec 7, 2023

Conversation

nkovela1
Copy link
Contributor

@nkovela1 nkovela1 commented Dec 7, 2023

This PR enables proper functionality for SegFormer presets and adds basic tests.

The following behavior is created here:
SegFormer.from_preset("segformer_b0") -> missing required argument num_clases
SegFormer.from_preset("segformer_b0", num_classes=2) -> ok
SegFormer.from_preset("mit_b0", num_classes=2) -> the exact same

@divyashreepathihalli
Copy link
Collaborator

Thank you for the PR Neel!

}
if preset in aliases:
preset = aliases[preset]
backbone = MiTBackbone.from_preset(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just chain to super here? And add the mit_b preset to backbone_presets?

To hit this branch

metadata = cls.presets[preset]
# Check if preset is backbone-only model
if preset in cls.backbone_presets:
backbone_cls = keras.saving.get_registered_object(
metadata["class_name"]
)
backbone = backbone_cls.from_preset(preset, load_weights)
return cls(backbone, **kwargs)

That would have the advantage of being totally uniform with how other tasks to this, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, slight modifications needed to be made to the task logic here in order to pass input_shape to the backbone's from_preset method. I've managed to make the uniform flow work, thanks!

We may need to revisit this at some point.

Copy link
Member

@mattdangerw mattdangerw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@nkovela1 nkovela1 merged commit 0439c68 into keras-team:master Dec 7, 2023
6 of 9 checks passed
yuvraj-wale pushed a commit to yuvraj-wale/keras-cv that referenced this pull request Feb 8, 2024
* Fix segformer presets

* Add extra SegFormer tests

* Change  flow, add backbone presets to SegFormer presets

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

Successfully merging this pull request may close these issues.

None yet

3 participants