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
4715e2e5
Unverified
Commit
4715e2e5
authored
Nov 05, 2021
by
Nicolas Hug
Committed by
GitHub
Nov 05, 2021
Browse files
Support big endian for .flo file decoding (#4868)
Co-authored-by:
Francisco Massa
<
fvsmassa@gmail.com
>
parent
ef471ed4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
test/datasets_utils.py
test/datasets_utils.py
+8
-1
torchvision/datasets/_optical_flow.py
torchvision/datasets/_optical_flow.py
+7
-6
No files found.
test/datasets_utils.py
View file @
4715e2e5
...
...
@@ -929,7 +929,14 @@ def make_fake_pfm_file(h, w, file_name):
def
make_fake_flo_file
(
h
,
w
,
file_name
):
"""Creates a fake flow file in .flo format."""
# Everything needs to be in little Endian according to
# https://vision.middlebury.edu/flow/code/flow-code/README.txt
values
=
list
(
range
(
2
*
h
*
w
))
content
=
b
"PIEH"
+
struct
.
pack
(
"i"
,
w
)
+
struct
.
pack
(
"i"
,
h
)
+
struct
.
pack
(
"f"
*
len
(
values
),
*
values
)
content
=
(
struct
.
pack
(
"<4c"
,
*
(
c
.
encode
()
for
c
in
"PIEH"
))
+
struct
.
pack
(
"<i"
,
w
)
+
struct
.
pack
(
"<i"
,
h
)
+
struct
.
pack
(
"<"
+
"f"
*
len
(
values
),
*
values
)
)
with
open
(
file_name
,
"wb"
)
as
f
:
f
.
write
(
content
)
torchvision/datasets/_optical_flow.py
View file @
4715e2e5
...
...
@@ -366,15 +366,16 @@ def _read_flo(file_name):
"""Read .flo file in Middlebury format"""
# Code adapted from:
# http://stackoverflow.com/questions/28013200/reading-middlebury-flow-files-with-python-bytes-array-numpy
# WARNING: this will work on little-endian architectures (eg Intel x86) only!
# Everything needs to be in little Endian according to
# https://vision.middlebury.edu/flow/code/flow-code/README.txt
with
open
(
file_name
,
"rb"
)
as
f
:
magic
=
np
.
fromfile
(
f
,
np
.
float32
,
count
=
1
)
if
202021.25
!=
magic
:
magic
=
np
.
fromfile
(
f
,
"c"
,
count
=
4
).
tobytes
(
)
if
magic
!=
b
"PIEH"
:
raise
ValueError
(
"Magic number incorrect. Invalid .flo file"
)
w
=
int
(
np
.
fromfile
(
f
,
np
.
int32
,
count
=
1
))
h
=
int
(
np
.
fromfile
(
f
,
np
.
int32
,
count
=
1
))
data
=
np
.
fromfile
(
f
,
np
.
float32
,
count
=
2
*
w
*
h
)
w
=
int
(
np
.
fromfile
(
f
,
"<i4"
,
count
=
1
))
h
=
int
(
np
.
fromfile
(
f
,
"<i4"
,
count
=
1
))
data
=
np
.
fromfile
(
f
,
"<f4"
,
count
=
2
*
w
*
h
)
return
data
.
reshape
(
2
,
h
,
w
)
...
...
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