-
Notifications
You must be signed in to change notification settings - Fork 4
/
detect.py
executable file
·92 lines (88 loc) · 2.52 KB
/
detect.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import argparse
import platform
if platform.system() == 'Linux': # RaspberryPi
DEFAULT_HFLIP = True
DEFAULT_VFLIP = True
elif platform.system() == 'Darwin': # MacOS X
DEFAULT_HFLIP = False
DEFAULT_VFLIP = False
else:
raise NotImplementedError()
from src.config import Config
from src.detector import Detector
def main() -> None:
parser = argparse.ArgumentParser(
description="detect object from various media"
)
parser.add_argument(
'--media', type=str, default=None,
help=(
'filename of image/video'
' (if not set, use streaming video from camera)'
)
)
parser.add_argument(
'--height', type=int, default=720,
help='camera image height'
)
parser.add_argument(
'--width', type=int, default=1280,
help='camera image width'
)
parser.add_argument(
'--hflip',
action='store_false' if DEFAULT_HFLIP else 'store_true',
help='flip horizontally'
)
parser.add_argument(
'--vflip',
action='store_false' if DEFAULT_VFLIP else 'store_true',
help='flip vertically'
)
parser.add_argument(
'--model', type=str, default='ssd',
choices=[
'ssd', 'face',
'yolov3-tiny', 'yolov3', 'yolov3-spp',
'yolov4-tiny', 'yolov4',
'yolov5s', 'yolov5m', 'yolov5l', 'yolov5x'
],
help='object detection model'
)
parser.add_argument(
'--quant', type=str, default='fp32',
choices=['fp32', 'fp16', 'int8', 'tpu'],
help='quantization mode (or use EdgeTPU)'
)
parser.add_argument(
'--target', type=str, default='all',
help='the target type of detecting object (default: all)'
)
parser.add_argument(
'--iou-threshold', type=float, default=0.45,
help='the IoU threshold of NMS'
)
parser.add_argument(
'--conf-threshold', type=float, default=0.5,
help='the confidence score threshold of NMS'
)
parser.add_argument(
'--fontsize', type=int, default=20,
help='fontsize to display'
)
parser.add_argument(
'--fastforward', type=int, default=1,
help=(
'frame interval for object detection'
' (default: 1 = detect every frame)'
)
)
args = parser.parse_args()
config = Config(**vars(args))
detector = Detector(config=config)
detector.run()
return
if __name__ == '__main__':
main()