Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
3db9af2b
Commit
3db9af2b
authored
Jul 02, 2019
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flownet inference for a seq of images
parent
ca096908
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
21 deletions
+28
-21
examples/OpticalFlow/README.md
examples/OpticalFlow/README.md
+4
-1
examples/OpticalFlow/flownet2.py
examples/OpticalFlow/flownet2.py
+24
-20
No files found.
examples/OpticalFlow/README.md
View file @
3db9af2b
...
@@ -37,10 +37,13 @@ wget http://models.tensorpack.com/OpticalFlow/flownet2-c.npz
...
@@ -37,10 +37,13 @@ wget http://models.tensorpack.com/OpticalFlow/flownet2-c.npz
```
bash
```
bash
python flownet2.py
\
python flownet2.py
\
--
left
left.png
--right
right.png
\
--
images
frame0.png frame1.png frame2.png
--load
flownet2.npz
--model
flownet2
--load
flownet2.npz
--model
flownet2
```
```
This command will show predictions for all the consecutive pairs one by one.
Press any key to visualize the next prediction.
3.
Evaluate AEE (Average Endpoing Error) on Sintel dataset:
3.
Evaluate AEE (Average Endpoing Error) on Sintel dataset:
```
```
...
...
examples/OpticalFlow/flownet2.py
View file @
3db9af2b
...
@@ -14,15 +14,13 @@ import flownet_models as models
...
@@ -14,15 +14,13 @@ import flownet_models as models
from
helper
import
Flow
from
helper
import
Flow
def
apply
(
model
,
model_path
,
left
,
right
,
ground_truth
=
None
):
def
apply
(
model
,
model_path
,
images
,
ground_truth
=
None
):
left
=
cv2
.
imread
(
left
)
left
=
cv2
.
imread
(
images
[
0
])
right
=
cv2
.
imread
(
right
)
h
,
w
=
left
.
shape
[:
2
]
h
,
w
=
left
.
shape
[:
2
]
newh
=
(
h
//
64
)
*
64
newh
=
(
h
//
64
)
*
64
neww
=
(
w
//
64
)
*
64
neww
=
(
w
//
64
)
*
64
aug
=
imgaug
.
CenterCrop
((
newh
,
neww
))
aug
=
imgaug
.
CenterCrop
((
newh
,
neww
))
left
,
right
=
aug
.
augment
(
left
),
aug
.
augment
(
righ
t
)
left
=
aug
.
augment
(
lef
t
)
predict_func
=
OfflinePredictor
(
PredictConfig
(
predict_func
=
OfflinePredictor
(
PredictConfig
(
model
=
model
(
height
=
newh
,
width
=
neww
),
model
=
model
(
height
=
newh
,
width
=
neww
),
...
@@ -30,20 +28,25 @@ def apply(model, model_path, left, right, ground_truth=None):
...
@@ -30,20 +28,25 @@ def apply(model, model_path, left, right, ground_truth=None):
input_names
=
[
'left'
,
'right'
],
input_names
=
[
'left'
,
'right'
],
output_names
=
[
'prediction'
]))
output_names
=
[
'prediction'
]))
left_input
,
right_input
=
[
x
.
astype
(
'float32'
)
.
transpose
(
2
,
0
,
1
)[
None
,
...
]
for
right
in
images
[
1
:]:
for
x
in
[
left
,
right
]]
right
=
aug
.
augment
(
cv2
.
imread
(
right
))
output
=
predict_func
(
left_input
,
right_input
)[
0
]
.
transpose
(
0
,
2
,
3
,
1
)
flow
=
Flow
()
left_input
,
right_input
=
[
x
.
astype
(
'float32'
)
.
transpose
(
2
,
0
,
1
)[
None
,
...
]
for
x
in
[
left
,
right
]]
output
=
predict_func
(
left_input
,
right_input
)[
0
]
.
transpose
(
0
,
2
,
3
,
1
)
flow
=
Flow
()
img
=
flow
.
visualize
(
output
[
0
])
patches
=
[
left
,
right
,
img
*
255.
]
if
ground_truth
is
not
None
:
patches
.
append
(
flow
.
visualize
(
Flow
.
read
(
ground_truth
))
*
255.
)
img
=
viz
.
stack_patches
(
patches
,
2
,
2
)
img
=
flow
.
visualize
(
output
[
0
])
cv2
.
imshow
(
'flow output'
,
img
)
patches
=
[
left
,
right
,
img
*
255.
]
cv2
.
imwrite
(
'flow_prediction.png'
,
img
)
if
ground_truth
is
not
None
:
cv2
.
waitKey
(
0
)
patches
.
append
(
flow
.
visualize
(
Flow
.
read
(
ground_truth
))
*
255.
)
img
=
viz
.
stack_patches
(
patches
,
2
,
2
)
cv2
.
imshow
(
'flow output'
,
img
)
left
=
right
cv2
.
imwrite
(
'flow_prediction.png'
,
img
)
cv2
.
waitKey
(
0
)
class
SintelData
(
DataFlow
):
class
SintelData
(
DataFlow
):
...
@@ -118,8 +121,8 @@ if __name__ == '__main__':
...
@@ -118,8 +121,8 @@ if __name__ == '__main__':
parser
.
add_argument
(
'--load'
,
help
=
'path to the model'
,
required
=
True
)
parser
.
add_argument
(
'--load'
,
help
=
'path to the model'
,
required
=
True
)
parser
.
add_argument
(
'--model'
,
help
=
'model'
,
parser
.
add_argument
(
'--model'
,
help
=
'model'
,
choices
=
[
'flownet2'
,
'flownet2-s'
,
'flownet2-c'
],
required
=
True
)
choices
=
[
'flownet2'
,
'flownet2-s'
,
'flownet2-c'
],
required
=
True
)
parser
.
add_argument
(
'--
left'
,
help
=
'input'
)
parser
.
add_argument
(
'--
images'
,
nargs
=
"+"
,
parser
.
add_argument
(
'--right'
,
help
=
'input
'
)
help
=
'a list of equally-sized images. FlowNet will be applied to all consecutive pairs
'
)
parser
.
add_argument
(
'--gt'
,
help
=
'path to ground truth flow'
)
parser
.
add_argument
(
'--gt'
,
help
=
'path to ground truth flow'
)
parser
.
add_argument
(
'--sintel_path'
,
help
=
'path to sintel dataset'
)
parser
.
add_argument
(
'--sintel_path'
,
help
=
'path to sintel dataset'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -131,4 +134,5 @@ if __name__ == '__main__':
...
@@ -131,4 +134,5 @@ if __name__ == '__main__':
if
args
.
sintel_path
:
if
args
.
sintel_path
:
inference
(
model
,
args
.
load
,
args
.
sintel_path
)
inference
(
model
,
args
.
load
,
args
.
sintel_path
)
else
:
else
:
apply
(
model
,
args
.
load
,
args
.
left
,
args
.
right
,
args
.
gt
)
assert
len
(
args
.
images
)
>=
2
apply
(
model
,
args
.
load
,
args
.
images
,
args
.
gt
)
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