-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.py
62 lines (46 loc) · 2.89 KB
/
options.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
import os
from codeproject_ai_sdk import ModuleOptions
class Settings:
def __init__(self, RESOLUTION, STD_MODEL_NAME, STD_SEG_MODEL_NAME):
self.RESOLUTION = RESOLUTION
self.STD_MODEL_NAME = STD_MODEL_NAME
self.STD_SEG_MODEL_NAME = STD_SEG_MODEL_NAME
class Options:
def __init__(self):
# -------------------------------------------------------------------------
# Setup constants
# see https://github.com/ultralytics/yolov5 for resolution data
self.MODEL_SETTINGS = {
"tiny": Settings(STD_MODEL_NAME = "yolov8n", STD_SEG_MODEL_NAME = "yolov8n-seg", RESOLUTION = 640),
"small": Settings(STD_MODEL_NAME = "yolov8s", STD_SEG_MODEL_NAME = "yolov8s-seg", RESOLUTION = 640),
"medium": Settings(STD_MODEL_NAME = "yolov8m", STD_SEG_MODEL_NAME = "yolov8m-seg", RESOLUTION = 640),
"large": Settings(STD_MODEL_NAME = "yolov8l", STD_SEG_MODEL_NAME = "yolov8l-seg", RESOLUTION = 640),
"huge": Settings(STD_MODEL_NAME = "yolov8x", STD_SEG_MODEL_NAME = "yolov8x-seg", RESOLUTION = 640)
}
# -------------------------------------------------------------------------
# Setup values
self._show_env_variables = True
self.app_dir = os.path.normpath(ModuleOptions.getEnvVariable("APPDIR", os.getcwd()))
self.models_dir = os.path.normpath(ModuleOptions.getEnvVariable("MODELS_DIR", f"{self.app_dir}/assets"))
self.custom_models_dir = os.path.normpath(ModuleOptions.getEnvVariable("CUSTOM_MODELS_DIR", f"{self.app_dir}/custom-models"))
self.sleep_time = 0.01
self.model_size = ModuleOptions.getEnvVariable("MODEL_SIZE", "Medium") # tiny, small, medium, large //, x-large
self.use_CUDA = ModuleOptions.getEnvVariable("USE_CUDA", "True") # True / False
self.use_MPS = True # only if available...
self.use_DirectML = True # only if available...
# Normalise input
self.model_size = self.model_size.lower()
self.use_CUDA = ModuleOptions.enable_GPU and self.use_CUDA.lower() == "true"
if self.model_size not in [ "tiny", "small", "medium", "large", "huge" ]:
self.model_size = "medium"
# Get settings
settings = self.MODEL_SETTINGS[self.model_size]
self.resolution_pixels = settings.RESOLUTION
self.std_model_name = settings.STD_MODEL_NAME
self.std_seg_model_name = settings.STD_SEG_MODEL_NAME
# -------------------------------------------------------------------------
# dump the important variables
if self._show_env_variables:
print(f"Debug: APPDIR: {self.app_dir}")
print(f"Debug: MODEL_SIZE: {self.model_size}")
print(f"Debug: MODELS_DIR: {self.models_dir}")