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
57e6e302
Unverified
Commit
57e6e302
authored
Nov 10, 2021
by
vfdev
Committed by
GitHub
Nov 10, 2021
Browse files
Revert "decode_* returns contiguous tensors (#4898)" (#4901)
This reverts commit
85b78580
.
parent
30669a57
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
10 deletions
+6
-10
test/test_image.py
test/test_image.py
+0
-4
torchvision/csrc/io/image/cpu/decode_jpeg.cpp
torchvision/csrc/io/image/cpu/decode_jpeg.cpp
+1
-1
torchvision/csrc/io/image/cpu/decode_png.cpp
torchvision/csrc/io/image/cpu/decode_png.cpp
+1
-1
torchvision/io/image.py
torchvision/io/image.py
+4
-4
No files found.
test/test_image.py
View file @
57e6e302
...
...
@@ -94,8 +94,6 @@ def test_decode_jpeg(img_path, pil_mode, mode):
data
=
read_file
(
img_path
)
img_ljpeg
=
decode_image
(
data
,
mode
=
mode
)
assert
img_ljpeg
.
is_contiguous
()
# Permit a small variation on pixel values to account for implementation
# differences between Pillow and LibJPEG.
abs_mean_diff
=
(
img_ljpeg
.
type
(
torch
.
float32
)
-
img_pil
).
abs
().
mean
().
item
()
...
...
@@ -175,8 +173,6 @@ def test_decode_png(img_path, pil_mode, mode):
data
=
read_file
(
img_path
)
img_lpng
=
decode_image
(
data
,
mode
=
mode
)
assert
img_lpng
.
is_contiguous
()
tol
=
0
if
pil_mode
is
None
else
1
if
PILLOW_VERSION
>=
(
8
,
3
)
and
pil_mode
==
"LA"
:
...
...
torchvision/csrc/io/image/cpu/decode_jpeg.cpp
View file @
57e6e302
...
...
@@ -148,7 +148,7 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
jpeg_finish_decompress
(
&
cinfo
);
jpeg_destroy_decompress
(
&
cinfo
);
return
tensor
.
permute
({
2
,
0
,
1
})
.
contiguous
()
;
return
tensor
.
permute
({
2
,
0
,
1
});
}
#endif
...
...
torchvision/csrc/io/image/cpu/decode_png.cpp
View file @
57e6e302
...
...
@@ -224,7 +224,7 @@ torch::Tensor decode_png(
}
}
png_destroy_read_struct
(
&
png_ptr
,
&
info_ptr
,
nullptr
);
return
tensor
.
permute
({
2
,
0
,
1
})
.
contiguous
()
;
return
tensor
.
permute
({
2
,
0
,
1
});
}
#endif
...
...
torchvision/io/image.py
View file @
57e6e302
...
...
@@ -59,7 +59,7 @@ def write_file(filename: str, data: torch.Tensor) -> None:
def
decode_png
(
input
:
torch
.
Tensor
,
mode
:
ImageReadMode
=
ImageReadMode
.
UNCHANGED
)
->
torch
.
Tensor
:
"""
Decodes a PNG image into a 3 dimensional RGB or grayscale
contiguous
Tensor.
Decodes a PNG image into a 3 dimensional RGB or grayscale Tensor.
Optionally converts the image to the desired format.
The values of the output tensor are uint8 in [0, 255].
...
...
@@ -117,7 +117,7 @@ def decode_jpeg(
input
:
torch
.
Tensor
,
mode
:
ImageReadMode
=
ImageReadMode
.
UNCHANGED
,
device
:
str
=
"cpu"
)
->
torch
.
Tensor
:
"""
Decodes a JPEG image into a 3 dimensional RGB or grayscale
contiguous
Tensor.
Decodes a JPEG image into a 3 dimensional RGB or grayscale Tensor.
Optionally converts the image to the desired format.
The values of the output tensor are uint8 between 0 and 255.
...
...
@@ -185,7 +185,7 @@ def write_jpeg(input: torch.Tensor, filename: str, quality: int = 75):
def
decode_image
(
input
:
torch
.
Tensor
,
mode
:
ImageReadMode
=
ImageReadMode
.
UNCHANGED
)
->
torch
.
Tensor
:
"""
Detects whether an image is a JPEG or PNG and performs the appropriate
operation to decode the image into a 3 dimensional RGB or grayscale
contiguous
Tensor.
operation to decode the image into a 3 dimensional RGB or grayscale Tensor.
Optionally converts the image to the desired format.
The values of the output tensor are uint8 in [0, 255].
...
...
@@ -207,7 +207,7 @@ def decode_image(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN
def
read_image
(
path
:
str
,
mode
:
ImageReadMode
=
ImageReadMode
.
UNCHANGED
)
->
torch
.
Tensor
:
"""
Reads a JPEG or PNG image into a 3 dimensional RGB or grayscale
contiguous
Tensor.
Reads a JPEG or PNG image into a 3 dimensional RGB or grayscale Tensor.
Optionally converts the image to the desired format.
The values of the output tensor are uint8 in [0, 255].
...
...
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