forked from open-mmlab/mmflow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_demo.py
43 lines (35 loc) · 1.4 KB
/
image_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
from argparse import ArgumentParser
import mmcv
from mmflow.apis import inference_model, init_model
from mmflow.datasets import visualize_flow, write_flow
def parse_args():
parser = ArgumentParser()
parser.add_argument('img1', help='Image1 file')
parser.add_argument('img2', help='Image2 file')
parser.add_argument('config', help='Config file')
parser.add_argument('checkpoint', help='Checkpoint file')
parser.add_argument(
'out_dir', help='Path of directory to save flow map and flow file')
parser.add_argument(
'--out_prefix',
help='The prefix for the output results '
'including flow file and visualized flow map',
default='flow')
parser.add_argument(
'--device', default='cuda:0', help='Device used for inference')
args = parser.parse_args()
return args
def main(args):
# build the model from a config file and a checkpoint file
model = init_model(args.config, args.checkpoint, device=args.device)
# test a single image
result = inference_model(model, args.img1, args.img2)
# save the results
mmcv.mkdir_or_exist(args.out_dir)
visualize_flow(result, osp.join(args.out_dir, f'{args.out_prefix}.png'))
write_flow(result, osp.join(args.out_dir, f'{args.out_prefix}.flo'))
if __name__ == '__main__':
args = parse_args()
main(args)