Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make detectionmodel classes more explicit in automodel #485

Merged
merged 3 commits into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions sahi/auto_model.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from typing import Dict, Optional

from sahi.utils.file import import_model_class
from sahi.model import Detectron2DetectionModel, MmdetDetectionModel, Yolov5DetectionModel

MODEL_TYPE_TO_MODEL_CLASS_NAME = {
"mmdet": "MmdetDetectionModel",
"yolov5": "Yolov5DetectionModel",
"detectron2": "Detectron2DetectionModel",
"torchvision": "TorchVisionDetectionModel",
"mmdet": MmdetDetectionModel,
"yolov5": Yolov5DetectionModel,
"detectron2": Detectron2DetectionModel,
}


Expand Down Expand Up @@ -55,8 +54,7 @@ def from_local(
ImportError: If given {model_type} framework is not installed
"""

class_name = MODEL_TYPE_TO_MODEL_CLASS_NAME[model_type]
DetectionModel = import_model_class(class_name)
DetectionModel = MODEL_TYPE_TO_MODEL_CLASS_NAME[model_type]

return DetectionModel(
model_path=model_path,
Expand Down Expand Up @@ -120,8 +118,7 @@ def from_layer(
else:
raise Exception(f"Unsupported model: {type(layer_model)}. Only YOLOv5 models are supported.")

class_name = MODEL_TYPE_TO_MODEL_CLASS_NAME[model_type]
DetectionModel = import_model_class(class_name)
DetectionModel = MODEL_TYPE_TO_MODEL_CLASS_NAME[model_type]
return DetectionModel(
model=layer_model,
device=device,
Expand Down