Skip to content

Conversation

@ekagra-ranjan
Copy link
Contributor

This PR addresses #1027 by:

  1. adding checks on boxes, masks, keypoints and labels attributes of target passed to detection models.
  2. updating docs

@codecov-io
Copy link

codecov-io commented Jul 4, 2019

Codecov Report

Merging #1091 into master will decrease coverage by 0.12%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1091      +/-   ##
==========================================
- Coverage   64.65%   64.53%   -0.13%     
==========================================
  Files          68       68              
  Lines        5410     5417       +7     
  Branches      830      834       +4     
==========================================
- Hits         3498     3496       -2     
- Misses       1662     1669       +7     
- Partials      250      252       +2
Impacted Files Coverage Δ
torchvision/models/detection/faster_rcnn.py 74.39% <ø> (ø) ⬆️
torchvision/models/detection/mask_rcnn.py 81.35% <ø> (ø) ⬆️
torchvision/models/detection/keypoint_rcnn.py 81.81% <ø> (ø) ⬆️
torchvision/models/detection/roi_heads.py 55.93% <0%> (-0.97%) ⬇️
torchvision/transforms/transforms.py 80.94% <0%> (-0.56%) ⬇️
torchvision/models/densenet.py 86.79% <0%> (ø) ⬆️
torchvision/models/mnasnet.py 82.71% <0%> (ø) ⬆️

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 d762537...3fb2a9e. 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 a lot for the PR!

I have a question regarding how to support fp16 training in the future. Let me know what you think

"""
if targets is not None:
for t in targets:
assert t["boxes"].dtype == torch.float32, 'target boxes must of float type'
Copy link
Member

Choose a reason for hiding this comment

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

Those checks might not work if we want to perform fp16 training in the future.
Maybe might be better to use something like t["boxes"].dtype.is_floating_point?

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, you are right! Will change it.

assert t["boxes"].dtype == torch.float32, 'target boxes must of float type'
assert t["labels"].dtype == torch.int64, 'target labels must of int64 type'
if self.has_mask:
assert t["masks"].dtype == torch.uint8, 'target masks must of uint8 type'
Copy link
Member

Choose a reason for hiding this comment

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

Do the masks need to be uint8? I thought that the code worked as well for other types, as the only place where it is used in the model we perform a cast to float?

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 was following the tutorial, where the dtype of mask was specified uint8. Should I remove that check?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think having the masks being uint8 is a hard-restriction, so yes, maybe remove this check for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

During training, the model expects both the input tensors, as well as a targets (list of dictionary),
containing:
- boxes (Tensor[N, 4]): the ground-truth boxes in [x0, y0, x1, y1] format, with values
- boxes (FloatTensor[N, 4]): the ground-truth boxes in [x0, y0, x1, y1] format, with values
Copy link
Member

Choose a reason for hiding this comment

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

Those are great changes, thanks!

But I'm a bit concerned that this looks like the legacy interface of torch.FloatTensor, etc.
I wonder if there is a better way of representing this? For example, in numpy, everything is a ndarray, but with different types.

Thoughts?

Copy link
Contributor Author

@ekagra-ranjan ekagra-ranjan Jul 9, 2019

Choose a reason for hiding this comment

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

Would the descriptions like boxes(Tensor[N, 4], dtype=torch.float) or boxes(FloatTensor(N, 4)) be better?

(Tensor[N, 4], dtype=torch.float) is not a valid syntax but conveys the requirement whereas FloatTensor(N, 4) would actually create a float tensor with dim = (N, 4).

Copy link
Member

Choose a reason for hiding this comment

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

Let's just keep this as is for now. But I'd like to remove the FloatTensor, changes, and only keep Int64Tensor instead, because boxes is not required to be Float

@ekagra-ranjan
Copy link
Contributor Author

Sorry for the delayed response. Please have a look at my response @fmassa .

@ekagra-ranjan
Copy link
Contributor Author

@fmassa Made the changes!

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!

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.

3 participants