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

allow user to define residual settings #965

Merged
merged 4 commits into from Jun 7, 2019

Conversation

matthewygf
Copy link
Contributor

This PR adds support to allow user define inverted_residual_setting.

It will use default setting if user did not specified setting, use specified otherwise.

@codecov-io
Copy link

codecov-io commented May 28, 2019

Codecov Report

Merging #965 into master will decrease coverage by 0.01%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #965      +/-   ##
==========================================
- Coverage   60.03%   60.01%   -0.02%     
==========================================
  Files          64       64              
  Lines        5054     5057       +3     
  Branches      754      756       +2     
==========================================
+ Hits         3034     3035       +1     
- Misses       1817     1818       +1     
- Partials      203      204       +1
Impacted Files Coverage Δ
torchvision/models/mobilenet.py 89.7% <60%> (-2.61%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2b3a1b6...7219352. Read the comment docs.

Copy link
Member

@fmassa fmassa 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!

I've made a few comments.
Also, the linter is failing, could you fix it?

@@ -117,7 +111,21 @@ def mobilenet_v2(pretrained=False, progress=True, **kwargs):
pretrained (bool): If True, returns a model pre-trained on ImageNet
progress (bool): If True, displays a progress bar of the download to stderr
"""
model = MobileNetV2(**kwargs)
default_setting = [
Copy link
Member

Choose a reason for hiding this comment

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

Would it be simpler to do

if inverted_residual_setting is None:
    inverted_residual_setting = ...

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion i have changed it that way

@@ -50,21 +50,15 @@ def forward(self, x):


class MobileNetV2(nn.Module):
def __init__(self, num_classes=1000, width_mult=1.0):
def __init__(self, inverted_residual_setting, num_classes=1000, width_mult=1.0):
Copy link
Member

Choose a reason for hiding this comment

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

This is a backwards incompatible change, because users might have been passing MobileNetV2(100), and this will now fail.

But moving it to the end will make it need to have a default value, which implies we will need to add a default value here as well with

if inverted_residual_setting is None:
    inverted_residual_setting = ...

I think we should try to keep backwards-compatibility, to avoid breakages on the user land.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, i have changed it to be default param

@@ -108,7 +102,7 @@ def forward(self, x):
return x


def mobilenet_v2(pretrained=False, progress=True, **kwargs):
def mobilenet_v2(pretrained=False, progress=True, inverted_residual_setting=None, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Can you add another test passing a different configuration, with fewer lines in the inverted_residual_setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a test in test_models

Copy link
Member

@fmassa fmassa 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!

@fmassa fmassa merged commit 060c10f into pytorch:master Jun 7, 2019
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