forked from Scalsol/mega.pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
74 lines (68 loc) · 1.9 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import glob
import os
import argparse
from mega_core.config import cfg
from predictor import VIDDemo
parser = argparse.ArgumentParser(description="PyTorch Object Detection Visualization")
parser.add_argument(
"method",
choices=["base", "dff", "fgfa", "rdn", "mega"],
default="base",
type=str,
help="which method to use",
)
parser.add_argument(
"config",
default="configs/vid_R_101_C4_1x.yaml",
metavar="FILE",
help="path to config file",
)
parser.add_argument(
"checkpoint",
default="R_101.pth",
help="The path to the checkpoint for test.",
)
parser.add_argument(
"--visualize-path",
default="datasets/ILSVRC2015/Data/VID/val/ILSVRC2015_val_00003001",
# default="datasets/ILSVRC2015/Data/VID/snippets/val/ILSVRC2015_val_00003001.mp4",
help="the folder or a video to visualize.",
)
parser.add_argument(
"--suffix",
default=".JPEG",
help="the suffix of the images in the image folder.",
)
parser.add_argument(
"--output-folder",
default="demo/visualization/base",
help="where to store the visulization result.",
)
parser.add_argument(
"--video",
action="store_true",
help="if True, input a video for visualization.",
)
parser.add_argument(
"--output-video",
action="store_true",
help="if True, output a video.",
)
args = parser.parse_args()
cfg.merge_from_file("configs/BASE_RCNN_1gpu.yaml")
cfg.merge_from_file(args.config)
cfg.merge_from_list(["MODEL.WEIGHT", args.checkpoint])
vid_demo = VIDDemo(
cfg,
method=args.method,
confidence_threshold=0.7,
output_folder=args.output_folder
)
if not args.video:
visualization_results = vid_demo.run_on_image_folder(args.visualize_path, suffix=args.suffix)
else:
visualization_results = vid_demo.run_on_video(args.visualize_path)
if not args.output_video:
vid_demo.generate_images(visualization_results)
else:
vid_demo.generate_video(visualization_results)