加载SAM3模型
(self)
| 227 | self._cache_lock = threading.Lock() |
| 228 | |
| 229 | def load(self): |
| 230 | """加载SAM3模型""" |
| 231 | if self._is_loaded: |
| 232 | return |
| 233 | |
| 234 | print(f"[SAM3Model] 加载模型中... (设备: {self.device})") |
| 235 | |
| 236 | from sam3.model_builder import build_sam3_image_model |
| 237 | from sam3.model.sam3_image_processor import Sam3Processor |
| 238 | |
| 239 | self._model = build_sam3_image_model( |
| 240 | bpe_path=self.bpe_path, |
| 241 | checkpoint_path=self.checkpoint_path, |
| 242 | load_from_HF=False, |
| 243 | device=self.device |
| 244 | ) |
| 245 | self._processor = Sam3Processor(self._model) |
| 246 | self._is_loaded = True |
| 247 | |
| 248 | print("[SAM3Model] 模型加载完成!") |
| 249 | |
| 250 | def predict(self, image_path: str, prompts: List[str], |
| 251 | score_threshold: float = 0.5, |
no outgoing calls
no test coverage detected