Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
17d50e8
feat: Added int conversion and unwrapping
Aug 29, 2024
285c465
test: added tests for post_process_keypoint_detection of SuperPointIm…
sbucaille Aug 30, 2024
2efe61b
docs: changed docs to include post_process_keypoint_detection method …
sbucaille Aug 30, 2024
a77b870
test: changed test to not depend on SuperPointModel forward
sbucaille Aug 30, 2024
2ab79cd
test: added missing require_torch decorator
sbucaille Aug 30, 2024
419ae5d
docs: changed pyplot parameters for the keypoints to be more visible …
sbucaille Aug 30, 2024
39b32a2
tests: changed import torch location to make test_flax and test_tf
sbucaille Aug 30, 2024
144e09a
Revert "tests: changed import torch location to make test_flax and te…
sbucaille Aug 30, 2024
21dbdfc
tests: fixed import
sbucaille Aug 30, 2024
389b154
chore: applied suggestions from code review
sbucaille Sep 1, 2024
b7d672e
tests: fixed import
sbucaille Sep 1, 2024
f5d7311
tests: fixed import (bis)
sbucaille Sep 1, 2024
d89d385
tests: fixed import (ter)
sbucaille Sep 1, 2024
f9e1141
feat: added choice of type for target_size and changed tests accordingly
sbucaille Sep 1, 2024
32a2e96
docs: updated code snippet to reflect the addition of target size typ…
sbucaille Sep 1, 2024
560194e
tests: fixed imports (...)
Sep 2, 2024
2d28aba
tests: fixed imports (...)
Sep 2, 2024
bd23baa
style: formatting file
Sep 2, 2024
5bb0baf
docs: fixed typo from image[0] to image.size[0]
sbucaille Sep 2, 2024
ed28314
docs: added output image and fixed some tests
sbucaille Sep 5, 2024
192448d
Update docs/source/en/model_doc/superpoint.md
sbucaille Oct 2, 2024
e89af7f
fix: included SuperPointKeypointDescriptionOutput in TYPE_CHECKING if…
sbucaille Oct 2, 2024
4e77a4f
docs: changed SuperPoint's docs to print output instead of just acces…
sbucaille Oct 2, 2024
e9b642a
style: applied make style
sbucaille Oct 2, 2024
e085861
docs: added missing output type and precision in docstring of post_pr…
sbucaille Oct 3, 2024
9127545
perf: deleted loop to perform keypoint conversion in one statement
sbucaille Oct 3, 2024
1ffa465
fix: moved keypoint conversion at the end of model forward
sbucaille Oct 3, 2024
b0d25a3
docs: changed SuperPointInterestPointDecoder to SuperPointKeypointDec…
sbucaille Oct 3, 2024
1fb5705
fix: changed type hint
sbucaille Oct 3, 2024
13cb7e5
refactor: removed unnecessary brackets
sbucaille Oct 4, 2024
eb6a5aa
revert: SuperPointKeypointDecoder to SuperPointInterestPointDecoder
sbucaille Oct 4, 2024
4c34d75
Update docs/source/en/model_doc/superpoint.md
sbucaille Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np

from ... import is_vision_available
from ... import is_torch_available, is_vision_available
from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import resize, to_channel_dimension_format
from ...image_utils import (
Expand All @@ -32,6 +32,9 @@
from ...utils import TensorType, logging, requires_backends


if is_torch_available():
import torch

if is_vision_available():
import PIL

Expand Down Expand Up @@ -270,3 +273,28 @@ def preprocess(
data = {"pixel_values": images}

return BatchFeature(data=data, tensor_type=return_tensors)

def post_process_keypoint_detection(self, outputs, target_sizes, unwrap_batch_dim=True):
Comment thread
qubvel marked this conversation as resolved.
Outdated
Comment thread
qubvel marked this conversation as resolved.
Outdated
if len(outputs.mask) != len(target_sizes):
raise ValueError("Make sure that you pass in as many target sizes as the batch dimension of the logits")
if target_sizes.shape[1] != 2:
raise ValueError("Each element of target_sizes must contain the size (h, w) of each image of the batch")

for keypoints, target_size in zip(outputs.keypoints, target_sizes):
keypoints[:, 0] = keypoints[:, 0] * target_size[1]
keypoints[:, 1] = keypoints[:, 1] * target_size[0]

# Convert masked_keypoints to int
masked_keypoints = outputs.keypoints.to(torch.int32)

outputs.keypoints = masked_keypoints
Comment thread
qubvel marked this conversation as resolved.
Outdated

results = []
for i, image_mask in enumerate(outputs.mask):
indices = torch.nonzero(image_mask).squeeze(1)
keypoints = outputs.keypoints[i][indices]
scores = outputs.scores[i][indices]
descriptors = outputs.descriptors[i][indices]
results.append({"keypoints": keypoints, "scores": scores, "descriptors": descriptors})
Comment thread
qubvel marked this conversation as resolved.
Outdated

return results
3 changes: 3 additions & 0 deletions src/transformers/models/superpoint/modeling_superpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ def _extract_keypoints(self, scores: torch.Tensor) -> Tuple[torch.Tensor, torch.
# Convert (y, x) to (x, y)
keypoints = torch.flip(keypoints, [1]).float()
Comment thread
qubvel marked this conversation as resolved.

# Convert to relative coordinates
keypoints = keypoints / torch.tensor([width, height], device=keypoints.device)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Technically a breaking change - but as this is more of a fix, I think it's OK


return keypoints, scores


Expand Down