(self)
| 41 | |
| 42 | class DetectionModels: |
| 43 | def __init__(self) -> None: |
| 44 | # Preloading: Loading Models takes ~9 seconds |
| 45 | set_num_threads(5) |
| 46 | self.executor = ThreadPoolExecutor(max_workers=5) |
| 47 | self.loading_futures: List[Future[Callable[..., None]]] = [] |
| 48 | |
| 49 | try: |
| 50 | self.loading_futures.append(self.executor.submit(self._load_yolo_detector)) |
| 51 | self.loading_futures.append(self.executor.submit(self._load_vit_model)) |
| 52 | self.loading_futures.append(self.executor.submit(self._load_vit_processor)) |
| 53 | self.loading_futures.append(self.executor.submit(self._load_seg_model)) |
| 54 | self.loading_futures.append(self.executor.submit(self._load_seg_processor)) |
| 55 | except Exception as e: |
| 56 | if sys.version_info.minor >= 9: |
| 57 | self.executor.shutdown(wait=True, cancel_futures=True) |
| 58 | else: |
| 59 | self.executor.shutdown(wait=True) |
| 60 | raise e |
| 61 | |
| 62 | def _load_yolo_detector(self): |
| 63 | from ultralytics import YOLO |
nothing calls this directly
no outgoing calls
no test coverage detected