-
Notifications
You must be signed in to change notification settings - Fork 234
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
[Semantic Segmentation] - Add SegFormer Architecture, Weight Conversion Script and Presets #1883
base: master
Are you sure you want to change the base?
Conversation
) | ||
|
||
segformer_backbone = keras_hub.models.SegFormerBackbone(backbone=encoder) | ||
segformer = keras_hub.models.SegFormerImageSegmenter(backbone=segformer_backbone, num_classes=4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be updated to SegFormerImageSegmenter.from_preset()
once the config.json
files are uploaded to Kaggle
Is this PR ready for review? |
@divyashreepathihalli In essence - yes, but there's some noise when running predictions using the converted weights (example image below of huggingface outputs vs our outputs). Looking into the numerics again, but the rest of the PR is ready for review :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing!! the PR looks great. Just a few comments.
@@ -0,0 +1,99 @@ | |||
# Licensed under the Apache License, Version 2.0 (the "License"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove copyright banner
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove copyright
""" | ||
|
||
backbone_cls = SegFormerBackbone | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also add the preprocessor flow : follow SAM for example.
this will involve adding an image converter, task preprocessor and then passing the preprocessor here to the task model.
@@ -0,0 +1,34 @@ | |||
# Licensed under the Apache License, Version 2.0 (the "License"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove copyright banner
@@ -0,0 +1,191 @@ | |||
# Licensed under the Apache License, Version 2.0 (the "License"); | |||
# you may not use this file except in compliance with the License. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove copyright banner
|
||
""" | ||
|
||
backbone_cls = MiTBackbone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
@@ -0,0 +1,83 @@ | |||
# Licensed under the Apache License, Version 2.0 (the "License"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove copyright on all files. I will stop commenting this
self.backbone = backbone | ||
self.preprocessor = preprocessor | ||
self.dropout = keras.layers.Dropout(0.1) | ||
self.output_segmentation = keras.layers.Conv2D( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we call this the output_segmentation_head
image_converter_cls = SegFormerImageConverter | ||
|
||
@preprocessing_function | ||
def call(self, x, y=None, sample_weight=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about transformations to y - which would be masks in the training set. If the images are resized/transformed, so should the masks
This PR adds:
Basic Usage
End-to-end example with preprocessor:
Training Pipeline Example
A few examples in the notebook below:
https://colab.research.google.com/drive/1EBNg6nPKx_KzyRuQQtHZ_PG_Nsf2pAg2#scrollTo=V9Ub4NHKCx9e
After a few minutes of training from scratch (both encoder and segmenter):