Skip to content

Remove non-functional Transforms from presets #4952

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 2 commits into from
Nov 17, 2021

Conversation

datumbox
Copy link
Contributor

@datumbox datumbox commented Nov 17, 2021

Fixes partially #4652

cc @datumbox @vfdev-5 @bjuncek

@facebook-github-bot
Copy link

facebook-github-bot commented Nov 17, 2021

💊 CI failures summary and remediations

As of commit 322cf9e (more details on the Dr. CI page):


None of the CI failures appear to be your fault 💚



🚧 1 fixed upstream failure:

These were probably caused by upstream breakages that were already fixed.

Please rebase on the viable/strict branch (expand for instructions)

If your commit is older than viable/strict, run these commands:

git fetch https://github.com/pytorch/pytorch viable/strict
git rebase FETCH_HEAD

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.

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.

Few clarifications to assist review:

@@ -62,7 +62,7 @@ def _video_resnet(
class R3D_18Weights(Weights):
Kinetics400_RefV1 = WeightEntry(
url="https://download.pytorch.org/models/r3d_18-b3b3357e.pth",
transforms=partial(Kinect400Eval, resize_size=(128, 171), crop_size=(112, 112)),
transforms=partial(Kinect400Eval, crop_size=(112, 112), resize_size=(128, 171)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing order to match the other presets.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just for appearance, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, just for styling. :)

if not isinstance(img, Tensor):
img = F.pil_to_tensor(img)
img = F.convert_image_dtype(img, torch.float)
return self._normalize(img)
img = F.normalize(img, mean=self._mean, std=self._std)
return img
Copy link
Contributor Author

Choose a reason for hiding this comment

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

replacing with the functional equivalents.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's equivalent. Confirmed by checking the accuracy of models before and after.

vid = F.resize(vid, self._size, interpolation=self._interpolation)
vid = F.center_crop(vid, self._crop_size)
vid = F.convert_image_dtype(vid, torch.float)
vid = F.normalize(vid, mean=self._mean, std=self._std)
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 reordered the operations. This is more "usual/canonical" order of ops. I'm running tests to confirm the accuracy remains the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The accuracy before and after the change remains the same. The above change is safe.

Copy link
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

Two questions inline, otherwise LGTM. Thanks Vasilis!

@@ -62,7 +62,7 @@ def _video_resnet(
class R3D_18Weights(Weights):
Kinetics400_RefV1 = WeightEntry(
url="https://download.pytorch.org/models/r3d_18-b3b3357e.pth",
transforms=partial(Kinect400Eval, resize_size=(128, 171), crop_size=(112, 112)),
transforms=partial(Kinect400Eval, crop_size=(112, 112), resize_size=(128, 171)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is just for appearance, right?

crop_size: Tuple[int, int],
resize_size: Tuple[int, int],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unrelated to this PR, but why do we use Tuple[int, int] here for the sizes, but plain int's for ImageNetEval?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good point. This is how the original recipes have been implemented, so I need to do this here too. If you see the resize operates differently if you specify both dimensions vs only 1. Prior merging we should consider adding unions etc here and cleaning up further.

@datumbox datumbox merged commit 775129b into pytorch:main Nov 17, 2021
@datumbox datumbox deleted the prototype/functional_presets branch November 17, 2021 14:14
@datumbox datumbox linked an issue Nov 17, 2021 that may be closed by this pull request
5 tasks
facebook-github-bot pushed a commit that referenced this pull request Nov 30, 2021
Reviewed By: NicolasHug

Differential Revision: D32694317

fbshipit-source-id: d4a1fe20d54ef4edad46c3dbc4daff2f229bcb10
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: Cleanups and Refactoring
3 participants