-
Notifications
You must be signed in to change notification settings - Fork 2
/
yolo-annotate.py
executable file
·156 lines (139 loc) · 3.95 KB
/
yolo-annotate.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/python3
import argparse
import logging
import os
import sys
import engine.annote as annote
from Detectors import CreateDetector, GetDetectorLabels, ListDetectors
from Detectors.common.Detector import Detector
from engine.annoter import Annoter
from helpers.files import FixPath, GetFileLocation
from MainWindow import MainWindowGui
def main():
"""Main code method."""
# Arguments and config
parser = argparse.ArgumentParser()
parser.add_argument(
"-i",
"--input",
type=str,
required=False,
help="Input path",
)
parser.add_argument("-c", "--config", type=str, required=False, help="Config path")
parser.add_argument(
"-det",
"--detector",
type=int,
nargs="?",
const=0,
default=0,
required=False,
help="Detector type - default 0",
)
parser.add_argument(
"-detc",
"--detectorConfidence",
type=float,
nargs="?",
const=0.4,
default=0.4,
required=False,
help="Detector default confidence",
)
parser.add_argument(
"-detnms",
"--detectorNms",
type=float,
nargs="?",
const=0.45,
default=0.45,
required=False,
help="Detector default NMS threshold",
)
parser.add_argument(
"-nd",
"--noDetector",
action="store_true",
required=False,
help="Disable detector pre processing of files.",
)
parser.add_argument(
"-oe",
"--onlyFilesWithErrors",
action="store_true",
required=False,
help="Process only files with errors.",
)
parser.add_argument(
"-f",
"--forceDetector",
action="store_true",
required=False,
help="Force detector for every file.",
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
required=False,
help="Show verbose finded and processed data",
)
args = parser.parse_args()
# Check - detector
noDetector = False
if args.noDetector is not None:
noDetector = args.noDetector
# Check - detector
forceDetector = False
if args.forceDetector is not None:
forceDetector = args.forceDetector
# Enabled logging
if __debug__ is True:
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
else:
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
logging.debug("Logging enabled!")
# Config .toml : Check
# if ConfigToml()["detector"] is None:
# logging.fatal("Invalid config file!")
# return
# Detector
detector: Detector = None
# Check : Detectors not found
detectors_found = ListDetectors()
if len(detectors_found) == 0:
logging.warning(
"No detectors found! Create subdirectory in Detectors/ with detector cfg, names, data to add detector."
)
noDetector = True
# Check : Detectors exists
elif noDetector is False:
scriptPath = os.path.dirname(os.path.realpath(__file__))
detector = CreateDetector(args.detector, path=scriptPath)
if detector is None:
logging.error("Wrong detector!")
return
detector.Init()
annote.Init(detector.GetClassNames())
# CUDA not installed
else:
noDetector = True
annote.Init(GetDetectorLabels(args.detector))
# Check - input argument
if (args.input is not None) and (len(args.input) > 0):
args.input = FixPath(GetFileLocation(args.input))
# Create annoter
annoter = Annoter(
filepath=args.input,
detector=detector,
noDetector=noDetector,
forceDetector=forceDetector,
detectorConfidence=args.detectorConfidence,
detectorNms=args.detectorNms,
)
# Start QtGui
gui = MainWindowGui(args, detector, annoter)
sys.exit(gui.Run())
if __name__ == "__main__":
main()