pytorch / pytorch/vision

TVTensor-KeyPoints with support for keypoint visibility for training Keypoint R-CNN

Open
#9,281 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🚀 The feature

@Alexandre-SCHOEPP @NicolasHug @AntoineSimoulin

Thank you for releasing the tv_tensor keypoints functionality. I use it in my university teaching, where students build a custom keypoint dataloader for training Keypoint R-CNN.

The tv_tensor utilities correctly handle the geometric transformations, but unfortunately they do not yet support the visibility flag, which is required for training Keypoint R-CNN.

Ultimately, this leads to redundant and inefficient code when building custom dataloaders. See the snippet below:

with open(annotation_path) as f:
    data = json.load(f)
shapes = data["shapes"]

keypoints = []
for shape in shapes:
    cx, cy = shape["points"][0]
    keypoints.append([cx, cy])
keypoints = torch.tensor(keypoints, dtype=torch.float32)
keypoints = keypoints.view(-1, 1, 2)

target = {}
target["keypoints"] = tv_tensors.KeyPoints(keypoints, canvas_size=F.get_size(img))

if self.transforms is not None:
    img, target = self.transforms(img, target)

## add visibility flag - redundant code
rows = target['keypoints'].shape[0]
visibility = torch.full(((rows, 1, 1)), 2.0, device=target['keypoints'].device, dtype=target['keypoints'].dtype)
target['keypoints'] = torch.cat([target['keypoints'], visibility], dim=2)
Motivation, pitch

It would be much more efficient if I could include the visibility flag directly in the keypoints list and then wrap it with the tv_tensors.KeyPoints class. However, this is currently not possible due to the input tensor shape.

A useful new feature would be to apply the transformations only to the first two values (x, y) while leaving the third value (visibility) unchanged.

I’m curious to hear your thoughts on this potential feature. Thank you in advance.

Alternatives

No response

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading torchvision/tv_tensors/_keypoints.py and the referenced keypoint handling in torchvision/models/detection/keypoint_rcnn.py. Trace how keypoints are transformed and check the existing tv_tensor tests before deciding how visibility should be represented. Done means visibility can be supplied with keypoints, geometric transforms affect only x and y, and Keypoint R-CNN training remains compatible.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision, machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.