Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
337fa343
Unverified
Commit
337fa343
authored
May 28, 2024
by
haarisr
Committed by
GitHub
May 28, 2024
Browse files
Allow K=1 in `draw_keypoints` (#8439)
Co-authored-by:
Nicolas Hug
<
contact@nicolas-hug.com
>
parent
61d97f41
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
test/test_utils.py
test/test_utils.py
+7
-0
torchvision/utils.py
torchvision/utils.py
+4
-4
No files found.
test/test_utils.py
View file @
337fa343
...
...
@@ -355,6 +355,13 @@ def test_draw_keypoints_vanilla():
assert_equal
(
img
,
img_cp
)
def
test_draw_keypoins_K_equals_one
():
# Non-regression test for https://github.com/pytorch/vision/pull/8439
img
=
torch
.
full
((
3
,
100
,
100
),
0
,
dtype
=
torch
.
uint8
)
keypoints
=
torch
.
tensor
([[[
10
,
10
]]],
dtype
=
torch
.
float
)
utils
.
draw_keypoints
(
img
,
keypoints
)
@
pytest
.
mark
.
parametrize
(
"colors"
,
[
"red"
,
"#FF00FF"
,
(
1
,
34
,
122
)])
def
test_draw_keypoints_colored
(
colors
):
# Keypoints is declared on top as global variable
...
...
torchvision/utils.py
View file @
337fa343
...
...
@@ -392,10 +392,10 @@ def draw_keypoints(
# validate visibility
if
visibility
is
None
:
# set default
visibility
=
torch
.
ones
(
keypoints
.
shape
[:
-
1
],
dtype
=
torch
.
bool
)
# If the last dimension is 1, e.g., after calling split([2, 1], dim=-1) on the output of a keypoint-prediction
# model, make sure visibility has
shape (num_instances, K).
# Iff K = 1, this has unwanted behavior, but K=1 does not really make sense in the first pla
ce.
visibility
=
visibility
.
squeeze
(
-
1
)
if
visibility
.
ndim
==
3
:
# If visibility was passed as pred.split([2, 1], dim=-1), it will be of
shape (num_instances, K
, 1
).
# We make sure it is of shape (num_instances, K). This isn't documented, we're just being ni
ce.
visibility
=
visibility
.
squeeze
(
-
1
)
if
visibility
.
ndim
!=
2
:
raise
ValueError
(
f
"visibility must be of shape (num_instances, K). Got ndim=
{
visibility
.
ndim
}
"
)
if
visibility
.
shape
!=
keypoints
.
shape
[:
-
1
]:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment