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

[Semantic Segmentation] Add first segmentation weights (credit @tanzhenyu) #1059

Merged
merged 5 commits into from
Nov 29, 2022

Conversation

ianstenbit
Copy link
Contributor

This also updates our training history updater to handle segmentation logs, and updates the deeplab implementation to load weights (also updates docstrings for deeplab)

@ianstenbit ianstenbit requested a review from tanzhenyu November 28, 2022 20:02
@DavidLandup0
Copy link
Contributor

DavidLandup0 commented Nov 29, 2022

Do you think this might be slightly improved with #968?
A 30-epoch run did 58% in validation mean IoU. I'm doing a 100-epoch test right now with dice to see if we can hopefully hit 70%, based on @tanzhenyu's DeepLabV3 training script 🤔

In my previous experiences with different implementations, Dice does slightly worse than CE, but with our previous DLV3 run, it seemed like the loss was still high after training (0.9/1.0 as opposed to CE which had a significant decrease for a similar accuracy), so my intuition is that if the network is "aware" that it's still wrong, there might be untapped potential to boost the accuracy.

Copy link
Contributor

@tanzhenyu tanzhenyu left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@@ -56,13 +64,19 @@ def __init__(
classes,
include_rescaling,
backbone,
weights,
backbone_weights=None,
weights=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want to provide default voc weights?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should offer defaults in the weights.py (as I have done with the aliases), but probably not in the parameter.

If you're referring to defaulting to None, I do think that's the right approach because it allows for random weight initialization by default.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean default to voc, given keras.application models default to imagenet - https://www.tensorflow.org/api_docs/python/tf/keras/applications/resnet50/ResNet50

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. Currently, our backbones don't have default weights. I don't personally love the idea of default weights, but I haven't thought about it a lot. Maybe we should discuss this as a package-wide option in our KerasCV sync?

Regardless of whether we include default weights, I would think we should keep them consistent across our model offerings.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me -- we could make this change later

"weights file to be loaded, or a reference to pre-trained weights. "
f"Weights file not found at location: {weights}"
)
self.load_weights(weights)
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting...does this work? Today all our models are subclassed models, meaning the variables are not created at this point, I wonder if load_weights will error out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh yes I forgot that we have to call call on a subclass model before this will load.

So perhaps we want to actually override load_weights for these models to support our custom weights?
For now, I've removed the weights param from this PR, as we should probably discuss how we'll offer pre-trained non-backbone models.

IIRC KerasNLP has come up with a from_pretrained API that we might want to consider?

Copy link
Contributor

Choose a reason for hiding this comment

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

the from_pretrained doesn't help much on this case, because KerasNLP actually creates all the variables during init. I have an action item to make our models to be function subclass models though, after which adding weights would be easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sg -- for now would you like me to override load_weights?

Copy link
Contributor

Choose a reason for hiding this comment

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

it's ok not to override, I will make this complete before 0.4 anyway

@ianstenbit ianstenbit requested a review from tanzhenyu November 29, 2022 04:11
@ianstenbit
Copy link
Contributor Author

Do you think this might be slightly improved with #968?

I think that it's likely there is still lots of opportunity to improve our semantic segmentation training script. Right now, I'm focused on getting the infrastructure set up to offer segmentation weights, using Zhenyu's VOC weights as a starting point.

Copy link
Contributor

@tanzhenyu tanzhenyu left a comment

Choose a reason for hiding this comment

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

see comments inline.

@ianstenbit
Copy link
Contributor Author

see comments inline.

thanks!

@ianstenbit ianstenbit requested a review from tanzhenyu November 29, 2022 04:36
Copy link
Contributor

@tanzhenyu tanzhenyu left a comment

Choose a reason for hiding this comment

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

Thanks for the quick response!

@tanzhenyu
Copy link
Contributor

/gcbrun

@ianstenbit ianstenbit merged commit 327430a into keras-team:master Nov 29, 2022
@ianstenbit ianstenbit deleted the seg-weights branch November 29, 2022 15:26
ghost pushed a commit to y-vectorfield/keras-cv that referenced this pull request Nov 16, 2023
…enyu) (keras-team#1059)

* Add first segmentation weights (credit @tanzheny)

* Add training history

* Remove leftover

* Remove weights param

* Comments
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.

3 participants