Skip to content

Update Reference scripts to support the prototype models #4837

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

Merged
merged 4 commits into from
Nov 3, 2021

Conversation

datumbox
Copy link
Contributor

@datumbox datumbox commented Nov 2, 2021

Fixes #4671

This PR adds a similar mechanism as in classification for segmentation and video. The target is to enable us to test the new model weights API (+ presets) and confirm it returns the same results as the old one. The co-existence of --pretrained and --weights is temporary and allows us to test that all models we introduce produce the expected results.

The approach is not perfect as it exposes the prototype stuff in the example reference scripts but the alternative would be to duplicate the reference scripts or keep a separate branch with their modifications which makes the work cumbersome. These will be cleaned up prior to adopting the new API, see #4652 and #4679.

cc @datumbox @bjuncek

@facebook-github-bot
Copy link

facebook-github-bot commented Nov 2, 2021

💊 CI failures summary and remediations

As of commit 55ddb93 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@datumbox datumbox changed the title [WIP] Update Reference scripts to support the prototype models Update Reference scripts to support the prototype models Nov 2, 2021
Copy link
Contributor Author

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

Some clarifications below:

else:
fn = PM.segmentation.__dict__[args.model]
weights = PM._api.get_weight(fn, args.weights)
return weights.transforms()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we are in train mode, we always initialize the SegmentationPresetTrain. For validation if the weights are not defined (aka not a prototype model) then use the old preprocessing method for evaluation. Else use the one attached to the weights.

model = torchvision.models.segmentation.__dict__[args.model](
num_classes=num_classes, aux_loss=args.aux_loss, pretrained=args.pretrained
)
if not args.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.

If the weights are not defined, we use the standard way. Else it's a prototype run which means we will use the prototype model mechanism.

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.

Approving to unblock

transform_test = presets.VideoClassificationPresetEval((128, 171), (112, 112))
else:
fn = PM.video.__dict__[args.model]
weights = PM._api.get_weight(fn, args.weights)
Copy link
Member

Choose a reason for hiding this comment

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

nit: using a private API here. We probably don't want to advertise private APIs in the references

Copy link
Contributor Author

@datumbox datumbox Nov 2, 2021

Choose a reason for hiding this comment

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

This is temporary and behind a feature switch (--weights). It's already recorded to clean up at #4652

Edit: I've edited the PR description to add some context. Also see #4734 for related discussion.

@@ -149,7 +155,12 @@ def main(args):
print("Loading validation data")
cache_path = _get_cache_path(valdir)

transform_test = presets.VideoClassificationPresetEval((128, 171), (112, 112))
if not args.weights:
Copy link
Member

Choose a reason for hiding this comment

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

nit: pretrained and weights are overlapping and can be confusing. This ideally should be cleaned up in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's exactly the plan. --pretrained will go away and --weights is going to be the right parameter. Right now we support both temporarily so that we can switch between the two completely different APIs. The --weights acts as a feature switch here.

if not args.weights:
transform_test = presets.VideoClassificationPresetEval((128, 171), (112, 112))
else:
fn = PM.video.__dict__[args.model]
Copy link
Member

Choose a reason for hiding this comment

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

are we providing some sort of registration API to get the models without having to resort to __dict__ manipulations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeap, that's the plan. There will be a proper registration mechanism, possibly something similar to what was discussed here. There are still pending discussions with other domains, so I didn't want to adopt something before those discussions take place.

@datumbox datumbox merged commit b1fc290 into pytorch:main Nov 3, 2021
@datumbox datumbox deleted the prototype/preprocessing_refs branch November 3, 2021 10:10
facebook-github-bot pushed a commit that referenced this pull request Nov 8, 2021
)

Summary:
* Adding prototype preprocessing on segmentation references.

* Adding prototype preprocessing on video references.

Reviewed By: kazhang

Differential Revision: D32216688

fbshipit-source-id: 219f9d8e3b34ecc5a30f9b93f9da0698631fd84e
cyyever pushed a commit to cyyever/vision that referenced this pull request Nov 16, 2021
* Adding prototype preprocessing on segmentation references.

* Adding prototype preprocessing on video references.
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.

Multi-pretrained weights: Add initial API and basic implementation
3 participants