-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Unify input checks on detection models #2295
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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!
Tests are failing (probably due to torchscript limitations), could you have a look?
Let me know if you have questions.
Hello, I investigated the checks that are failing. There are three fails due to vision/test/test_models_detection_negative_samples.py Lines 14 to 30 in 2cfc360
Because the code I wrote checks that N must match for all items in targets, it is throwing an exception. I think that maybe @fmassa got confused and swapped the first and second dimensions, but I would like your opinion before making the change! |
@mmcenta the test is correct, see vision/references/detection/coco_utils.py Line 80 in 2cfc360
So keypoints should have the first dimension to be the number of keypoints (always 17 for the curent COCO model, but let's not hard-code it), and the number of objects in the second dimension. So just change the check to be in the second dimension of the keypoints. For the dtype, is it still an issue? as a workaround you can add a type annotation as an |
Actually, looking at this again, there might be a possible improvement in vision/references/detection/coco_utils.py Lines 76 to 80 in 2cfc360
Instead of only resizing if the number objects is non-zero, I think we could instead do something like keypoints = [obj["keypoints"] for obj in anno]
keypoints = torch.as_tensor(keypoints, dtype=torch.float32)
num_keypoints = keypoints.shape[0]
num_objects = boxes.shape[0]
keypoints = keypoints.view(num_keypoints, num_objects, 3) This way the code is more robust. Can you also make a separate PR for this? It would be slightly more robust I think. |
@fmassa Oh I see, sorry! I was basing my checks on the documentation which states that the shape of the keypoints vector is (N, K, 3). If you want I can open another PR to fix it. Yes, CircleCI is still complaining about the |
@mmcenta looking at it again, I was wrong :-) The shape of the keypoints is indeed |
@fmassa Ok I will commit the changes. Are you sure? What about the code in |
I think I have misread the implementation before because of a bad variable name ( |
Also, can you rebase your changes on top of latest master? There seems to be conflicts. |
@fmassa Sure, and sorry for all the commits, I need to figure out what CircleCI is complaining about before I can fix it. Before it was casting an Optional[str] to bool, now it is the I will keep doing this until everything is fixed and then squash the commits and rebase to the new master :P |
@fmassa I'm having trouble when comparing an Optional[int] to an int. The refining wasn't working in the same if statement, so I separated the None check in its own if statement, which also didn't work. Now I am refining via the assert and I still get errors. Do you have an idea of how we fix it? |
@mmcenta I think you need to do something like item = shape[i]
assert item is not None |
So there seems to be an issue with CI today #2316 But there are some conflicts on your branch that could be fixed already. |
@fmassa I think the checks that are failing now are not my fault (finally). Also sorry for the mess with the commit I think I messed up the rebase the first time around. |
Hi @mmcenta Sorry for the delay in getting back to you. Can you rebase your PR on top of master? |
Done! There are some failing checks but I don't think it is a consequence of this PR. |
Hi @mmcenta , thanks for your work so far! Would you be interested in continuing this PR? There are a few linting issues, and merging with master should hopefully fix the unrelated CI issues, which would help for reviews. Thanks! |
Follows up on #2207, unifies checks of the training targets in detection models, and adds checks for all fields (boxes and labels for all models, masks for MaskRCNN, and keypoints for KeypointRCNN).
I followed @fmassa's suggestion to move the validation inside the
roi_heads.py
file, which already contained a few checks. I merged the existing validation and added functionality.Note that this can still be improved: I do not check that the masks have the right width and height or that the number of keypoints matches what the model expects.
Importantly, this may be a breaking change because I am validating the
dtype
of the masks field (which is supposed to betorch.uint8
, according to the documentation), which was not done before.