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
a73285aa
Unverified
Commit
a73285aa
authored
Mar 09, 2023
by
Nikita Shulga
Committed by
GitHub
Mar 09, 2023
Browse files
Add device check to `io.decode_image` (#7406)
Co-authored-by:
Nicolas Hug
<
nh.nicolas.hug@gmail.com
>
parent
4a7def80
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
0 deletions
+9
-0
test/test_image.py
test/test_image.py
+7
-0
torchvision/csrc/io/image/cpu/decode_image.cpp
torchvision/csrc/io/image/cpu/decode_image.cpp
+2
-0
No files found.
test/test_image.py
View file @
a73285aa
...
...
@@ -368,6 +368,13 @@ def test_decode_jpeg_cuda(mode, img_path, scripted):
# Some difference expected between jpeg implementations
assert
(
img
.
float
()
-
img_nvjpeg
.
cpu
().
float
()).
abs
().
mean
()
<
2
@
needs_cuda
def
test_decode_image_cuda_raises
():
data
=
torch
.
randint
(
0
,
127
,
size
=
(
255
,),
device
=
"cuda"
,
dtype
=
torch
.
uint8
)
exception_raised
=
True
with
pytest
.
raises
(
RuntimeError
):
decode_image
(
data
)
@
needs_cuda
@
pytest
.
mark
.
parametrize
(
"cuda_device"
,
(
"cuda"
,
"cuda:0"
,
torch
.
device
(
"cuda"
)))
...
...
torchvision/csrc/io/image/cpu/decode_image.cpp
View file @
a73285aa
...
...
@@ -7,6 +7,8 @@ namespace vision {
namespace
image
{
torch
::
Tensor
decode_image
(
const
torch
::
Tensor
&
data
,
ImageReadMode
mode
)
{
// Check that tensor is a CPU tensor
TORCH_CHECK
(
data
.
device
()
==
torch
::
kCPU
,
"Expected a CPU tensor"
);
// Check that the input tensor dtype is uint8
TORCH_CHECK
(
data
.
dtype
()
==
torch
::
kU8
,
"Expected a torch.uint8 tensor"
);
// Check that the input tensor is 1-dimensional
...
...
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