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

Add --backend and --use-v2 support for segmentation references #7743

Merged
merged 8 commits into from
Jul 27, 2023

Conversation

NicolasHug
Copy link
Member

No description provided.

@pytorch-bot
Copy link

pytorch-bot bot commented Jul 13, 2023

@NicolasHug NicolasHug marked this pull request as ready for review July 17, 2023 15:32
@NicolasHug NicolasHug requested a review from pmeier July 17, 2023 15:32
references/segmentation/coco_utils.py Show resolved Hide resolved
Comment on lines +49 to +50
# We need a custom pad transform here, since the padding we want to perform here is fundamentally
# different from the padding in `RandomCrop` if `pad_if_needed=True`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we at some point drop v1, we should re-evaluate if the custom scheme actually has an effect on the performance or if we can just RandomCrop. Until then, I agree we should keep the implementation as close as possible.


if use_v2:
dtype = {
(datapoints.Image if backend == "datapoint" else torch.Tensor): torch.float,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will convert the dtype, but not the value range. We need to also have a ConvertDtype or its alias ConvertImageDtype here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch thank you

transforms += [T.RandomResize(min_size=base_size, max_size=base_size)]

if backend == "pil":
# Note: we could just convert to pure tensors even in v2?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Depends on our decision in #7340. I would drop the comment here, because we'll easily forget about it.

Comment on lines +270 to +272
# elif "SLURM_PROCID" in os.environ:
# args.rank = int(os.environ["SLURM_PROCID"])
# args.gpu = args.rank % torch.cuda.device_count()
Copy link
Collaborator

Choose a reason for hiding this comment

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

?

Suggested change
# elif "SLURM_PROCID" in os.environ:
# args.rank = int(os.environ["SLURM_PROCID"])
# args.gpu = args.rank % torch.cuda.device_count()
elif "SLURM_PROCID" in os.environ:
args.rank = int(os.environ["SLURM_PROCID"])
args.gpu = args.rank % torch.cuda.device_count()

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just to be able to run those scripts without invoking torchrun from the cluster (it's a bit of a mess). I'll remove it before merging

import v2_extras
from torchvision.datasets import wrap_dataset_for_transforms_v2

transforms = Compose([v2_extras.CocoDetectionToSegmentation(), transforms])
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can pass CAT_LIST as arg to CocoDetectionToSegmentation to construct COCO_TO_VOC_LABEL_MAP instead of duplicating the data

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would argue that this list is fixed and will never change. Thus, there is no point in passing it as a parameter. Meaning, if anything, I would change FilterAndRemapCocoCategories to also hardcode this.

No strong opinion, but I would not change anything here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree this is unlikely to change. And as mention in the comment above, we could refactor both code-paths and unify some stuff, but I feel like it's best not to: we can keep the v2 path clean without being polluted with the mess accumulated over the years in the v1 path.

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.

LGTM if starting a run doesn't fail. Thanks Nicolas!

references/segmentation/coco_utils.py Outdated Show resolved Hide resolved
references/segmentation/v2_extras.py Outdated Show resolved Hide resolved
references/segmentation/train.py Outdated Show resolved Hide resolved
import v2_extras
from torchvision.datasets import wrap_dataset_for_transforms_v2

transforms = Compose([v2_extras.CocoDetectionToSegmentation(), transforms])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would argue that this list is fixed and will never change. Thus, there is no point in passing it as a parameter. Meaning, if anything, I would change FilterAndRemapCocoCategories to also hardcode this.

No strong opinion, but I would not change anything here.

@NicolasHug NicolasHug merged commit b9b7cfc into pytorch:main Jul 27, 2023
48 of 60 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 Aug 25, 2023
…es (#7743)

Reviewed By: matteobettini

Differential Revision: D48642316

fbshipit-source-id: 7510049cae962545d263c824791567358d659d6d
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