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: atrous_rates for deeplabv3_mobilenet_v3_large (fixes #7956) #8019

Merged
merged 2 commits into from
Oct 11, 2023

Conversation

nvs-abhilash
Copy link
Contributor

@nvs-abhilash nvs-abhilash commented Oct 5, 2023

This PR addresses the issue reffered in #7956

The PR proposes the following changes to address the issues:

  • Parameterize atrous_rates for deeplabv3 in DeepLabHead.
  • Send (6, 12, 18) atrous_rates for mobilenet backbone

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 5, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/8019

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 14 Unrelated Failures

As of commit c65397d with merge base 7e2050f (image):

NEW FAILURE - The following job has failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot
Copy link

Hi @nvs-abhilash!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link
Member

@NicolasHug NicolasHug 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 @nvs-abhilash .

I made a few comments below regarding preserving backward compatibility.

@fmassa , do you remember why the values [12, 24, 36] were used for the atrous rates in #820, instead of [6, 12, 18]?

@@ -220,7 +220,7 @@ def _deeplabv3_mobilenetv3(
backbone = IntermediateLayerGetter(backbone, return_layers=return_layers)

aux_classifier = FCNHead(aux_inplanes, num_classes) if aux else None
classifier = DeepLabHead(out_inplanes, num_classes)
classifier = DeepLabHead(out_inplanes, num_classes, atrous_rates=(6, 12, 18))
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately this would be BC-breaking. We'll have to preserve the values that are currently used here (relying on the default).

Suggested change
classifier = DeepLabHead(out_inplanes, num_classes, atrous_rates=(6, 12, 18))
classifier = DeepLabHead(out_inplanes, num_classes)

@@ -83,7 +83,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:


class ASPP(nn.Module):
def __init__(self, in_channels: int, atrous_rates: List[int], out_channels: int = 256) -> None:
def __init__(self, in_channels: int, atrous_rates: Tuple[int, int, int], out_channels: int = 256) -> None:
Copy link
Member

@NicolasHug NicolasHug Oct 9, 2023

Choose a reason for hiding this comment

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

From my understanding, using List[int] instead of a fixed 3-tuple was intended (details in #2136).

Suggested change
def __init__(self, in_channels: int, atrous_rates: Tuple[int, int, int], out_channels: int = 256) -> None:
def __init__(self, in_channels: int, atrous_rates: List[int], out_channels: int = 256) -> None:

@@ -46,9 +46,9 @@ class DeepLabV3(_SimpleSegmentationModel):


class DeepLabHead(nn.Sequential):
def __init__(self, in_channels: int, num_classes: int) -> None:
def __init__(self, in_channels: int, num_classes: int, atrous_rates: Tuple[int, int, int] = (12, 24, 36)) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def __init__(self, in_channels: int, num_classes: int, atrous_rates: Tuple[int, int, int] = (12, 24, 36)) -> None:
def __init__(self, in_channels: int, num_classes: int, atrous_rates: List[int] = [12, 24, 36]) -> None:

@fmassa
Copy link
Member

fmassa commented Oct 9, 2023

Hi,

Thanks for the PR!

The dilation rates could have been an oversight when porting the DeepLab head into MobileNetV3.
That being said, using a larger dilation factor in the backbone (as done in the ResNet variants) makes the model much slower to run, so maybe the configuration done here (with the larger dilation in the head) actually yields better accuracies for a smaller computation budget (but this would need to be verified).

Changing the defaults will change the outputs produced by the models, so I agree with @NicolasHug to keep the same defaults as before.

@nvs-abhilash
Copy link
Contributor Author

Thanks, @NicolasHug and @fmassa for reviewing my code.

Post your comments, the only change that seems to make sense is just to parameterise the atrous_rates parameter. I've updated the commit incorporating the same.

Also, what can be the path to solve #7956 ?

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @nvs-abhilash , LGTM with one last comment below

@@ -46,9 +46,9 @@ class DeepLabV3(_SimpleSegmentationModel):


class DeepLabHead(nn.Sequential):
def __init__(self, in_channels: int, num_classes: int) -> None:
def __init__(self, in_channels: int, num_classes: int, atrous_rates: List[int] = [12, 24, 36]) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

We should avoid setting mutables as default values in general as there's a risk that we will change that value inplace, and subsequent calls would be using the wrong default.

Suggested change
def __init__(self, in_channels: int, num_classes: int, atrous_rates: List[int] = [12, 24, 36]) -> None:
def __init__(self, in_channels: int, num_classes: int, atrous_rates: Sequence[int] = (12, 24, 36)) -> None:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, makes sense. I thought the same, therefore had made it tuple before. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR.

@NicolasHug
Copy link
Member

Also, what can be the path to solve #7956 ?

Would documenting the atrous rates being used be enough?

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks a lot @nvs-abhilash

@NicolasHug NicolasHug merged commit 70a8e05 into pytorch:main Oct 11, 2023
34 of 49 checks passed
@github-actions
Copy link

Hey @NicolasHug!

You merged this PR, but no labels were added. The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

facebook-github-bot pushed a commit that referenced this pull request Nov 3, 2023
) (#8019)

Summary: Co-authored-by: Nicolas Hug <nh.nicolas.hug@gmail.com>

Reviewed By: vmoens

Differential Revision: D50789082

fbshipit-source-id: 02bbe21ba09522b2db1552c6a677b89ff4247392
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants