-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathdetect_target_factory.py
59 lines (51 loc) · 1.59 KB
/
detect_target_factory.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
"""
Factory pattern for constructing detect target class at runtime.
"""
import enum
from . import base_detect_target
from . import detect_target_brightspot
from . import detect_target_contour
from . import detect_target_ultralytics
from ..common.modules.logger import logger
class DetectTargetOption(enum.Enum):
"""
ML for machine inference.
"""
ML_ULTRALYTICS = 0
CV_BRIGHTSPOT = 1
CV_CONTOUR = 2
def create_detect_target(
save_name: str,
show_annotations: bool,
detect_target_option: DetectTargetOption,
config: (
detect_target_brightspot.DetectTargetBrightspotConfig
| detect_target_ultralytics.DetectTargetUltralyticsConfig
),
local_logger: logger.Logger,
) -> tuple[bool, base_detect_target.BaseDetectTarget | None]:
"""
Construct detect target class at runtime.
"""
match detect_target_option:
case DetectTargetOption.ML_ULTRALYTICS:
return True, detect_target_ultralytics.DetectTargetUltralytics(
config,
local_logger,
show_annotations,
save_name,
)
case DetectTargetOption.CV_BRIGHTSPOT:
return True, detect_target_brightspot.DetectTargetBrightspot(
config,
local_logger,
show_annotations,
save_name,
)
case DetectTargetOption.CV_CONTOUR:
return True, detect_target_contour.DetectTargetContour(
local_logger,
show_annotations,
save_name,
)
return False, None