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
694949ed
"git@developer.sourcefind.cn:OpenDAS/vision.git" did not exist on "e0e9538044906b3ac144e422d620f00e96d7d8b5"
Unverified
Commit
694949ed
authored
Nov 08, 2021
by
Nicolas Hug
Committed by
GitHub
Nov 08, 2021
Browse files
Open Fix .flo file decoding (#4870)
parent
6d9a42c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
+16
-6
test/test_datasets.py
test/test_datasets.py
+15
-5
torchvision/datasets/_optical_flow.py
torchvision/datasets/_optical_flow.py
+1
-1
No files found.
test/test_datasets.py
View file @
694949ed
...
@@ -1914,11 +1914,13 @@ class SintelTestCase(datasets_utils.ImageDatasetTestCase):
...
@@ -1914,11 +1914,13 @@ class SintelTestCase(datasets_utils.ImageDatasetTestCase):
def
test_flow
(
self
):
def
test_flow
(
self
):
# Make sure flow exists for train split, and make sure there are as many flow values as (pairs of) images
# Make sure flow exists for train split, and make sure there are as many flow values as (pairs of) images
h
,
w
=
self
.
FLOW_H
,
self
.
FLOW_W
expected_flow
=
np
.
arange
(
2
*
h
*
w
).
reshape
(
h
,
w
,
2
).
transpose
(
2
,
0
,
1
)
with
self
.
create_dataset
(
split
=
"train"
)
as
(
dataset
,
_
):
with
self
.
create_dataset
(
split
=
"train"
)
as
(
dataset
,
_
):
assert
dataset
.
_flow_list
and
len
(
dataset
.
_flow_list
)
==
len
(
dataset
.
_image_list
)
assert
dataset
.
_flow_list
and
len
(
dataset
.
_flow_list
)
==
len
(
dataset
.
_image_list
)
for
_
,
_
,
flow
in
dataset
:
for
_
,
_
,
flow
in
dataset
:
assert
flow
.
shape
==
(
2
,
self
.
FLOW_H
,
self
.
FLOW_W
)
assert
flow
.
shape
==
(
2
,
h
,
w
)
np
.
testing
.
assert_allclose
(
flow
,
np
.
arange
(
flow
.
size
).
reshape
(
flow
.
shape
)
)
np
.
testing
.
assert_allclose
(
flow
,
expected_flow
)
# Make sure flow is always None for test split
# Make sure flow is always None for test split
with
self
.
create_dataset
(
split
=
"test"
)
as
(
dataset
,
_
):
with
self
.
create_dataset
(
split
=
"test"
)
as
(
dataset
,
_
):
...
@@ -2041,11 +2043,14 @@ class FlyingChairsTestCase(datasets_utils.ImageDatasetTestCase):
...
@@ -2041,11 +2043,14 @@ class FlyingChairsTestCase(datasets_utils.ImageDatasetTestCase):
def
test_flow
(
self
,
config
):
def
test_flow
(
self
,
config
):
# Make sure flow always exists, and make sure there are as many flow values as (pairs of) images
# Make sure flow always exists, and make sure there are as many flow values as (pairs of) images
# Also make sure the flow is properly decoded
# Also make sure the flow is properly decoded
h
,
w
=
self
.
FLOW_H
,
self
.
FLOW_W
expected_flow
=
np
.
arange
(
2
*
h
*
w
).
reshape
(
h
,
w
,
2
).
transpose
(
2
,
0
,
1
)
with
self
.
create_dataset
(
config
=
config
)
as
(
dataset
,
_
):
with
self
.
create_dataset
(
config
=
config
)
as
(
dataset
,
_
):
assert
dataset
.
_flow_list
and
len
(
dataset
.
_flow_list
)
==
len
(
dataset
.
_image_list
)
assert
dataset
.
_flow_list
and
len
(
dataset
.
_flow_list
)
==
len
(
dataset
.
_image_list
)
for
_
,
_
,
flow
in
dataset
:
for
_
,
_
,
flow
in
dataset
:
assert
flow
.
shape
==
(
2
,
self
.
FLOW_H
,
self
.
FLOW_W
)
assert
flow
.
shape
==
(
2
,
h
,
w
)
np
.
testing
.
assert_allclose
(
flow
,
np
.
arange
(
flow
.
size
).
reshape
(
flow
.
shape
)
)
np
.
testing
.
assert_allclose
(
flow
,
expected_flow
)
class
FlyingThings3DTestCase
(
datasets_utils
.
ImageDatasetTestCase
):
class
FlyingThings3DTestCase
(
datasets_utils
.
ImageDatasetTestCase
):
...
@@ -2095,11 +2100,16 @@ class FlyingThings3DTestCase(datasets_utils.ImageDatasetTestCase):
...
@@ -2095,11 +2100,16 @@ class FlyingThings3DTestCase(datasets_utils.ImageDatasetTestCase):
@
datasets_utils
.
test_all_configs
@
datasets_utils
.
test_all_configs
def
test_flow
(
self
,
config
):
def
test_flow
(
self
,
config
):
h
,
w
=
self
.
FLOW_H
,
self
.
FLOW_W
expected_flow
=
np
.
arange
(
3
*
h
*
w
).
reshape
(
h
,
w
,
3
).
transpose
(
2
,
0
,
1
)
expected_flow
=
np
.
flip
(
expected_flow
,
axis
=
1
)
expected_flow
=
expected_flow
[:
2
,
:,
:]
with
self
.
create_dataset
(
config
=
config
)
as
(
dataset
,
_
):
with
self
.
create_dataset
(
config
=
config
)
as
(
dataset
,
_
):
assert
dataset
.
_flow_list
and
len
(
dataset
.
_flow_list
)
==
len
(
dataset
.
_image_list
)
assert
dataset
.
_flow_list
and
len
(
dataset
.
_flow_list
)
==
len
(
dataset
.
_image_list
)
for
_
,
_
,
flow
in
dataset
:
for
_
,
_
,
flow
in
dataset
:
assert
flow
.
shape
==
(
2
,
self
.
FLOW_H
,
self
.
FLOW_W
)
assert
flow
.
shape
==
(
2
,
self
.
FLOW_H
,
self
.
FLOW_W
)
# We don't check the values because the reshaping and flipping makes it hard to figure out
np
.
testing
.
assert_allclose
(
flow
,
expected_flow
)
def
test_bad_input
(
self
):
def
test_bad_input
(
self
):
with
pytest
.
raises
(
ValueError
,
match
=
"Unknown value 'bad' for argument split"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Unknown value 'bad' for argument split"
):
...
...
torchvision/datasets/_optical_flow.py
View file @
694949ed
...
@@ -376,7 +376,7 @@ def _read_flo(file_name):
...
@@ -376,7 +376,7 @@ def _read_flo(file_name):
w
=
int
(
np
.
fromfile
(
f
,
"<i4"
,
count
=
1
))
w
=
int
(
np
.
fromfile
(
f
,
"<i4"
,
count
=
1
))
h
=
int
(
np
.
fromfile
(
f
,
"<i4"
,
count
=
1
))
h
=
int
(
np
.
fromfile
(
f
,
"<i4"
,
count
=
1
))
data
=
np
.
fromfile
(
f
,
"<f4"
,
count
=
2
*
w
*
h
)
data
=
np
.
fromfile
(
f
,
"<f4"
,
count
=
2
*
w
*
h
)
return
data
.
reshape
(
2
,
h
,
w
)
return
data
.
reshape
(
h
,
w
,
2
).
transpose
(
2
,
0
,
1
)
def
_read_16bits_png_with_flow_and_valid_mask
(
file_name
):
def
_read_16bits_png_with_flow_and_valid_mask
(
file_name
):
...
...
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