Skip to content

Commit 3cf6c75

Browse files
committed
adds support for yolov12 model upload
1 parent e0d53e8 commit 3cf6c75

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

roboflow/util/model_processor.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,29 @@
1010

1111

1212
def process(model_type: str, model_path: str, filename: str) -> str:
13+
if model_type.startswith("yolo11"):
14+
model_type = model_type.replace("yolo11", "yolov11")
15+
16+
if model_type.startswith("yolo12"):
17+
model_type = model_type.replace("yolo12", "yolov12")
18+
1319
processor = _get_processor_function(model_type)
1420
return processor(model_type, model_path, filename)
1521

1622

1723
def _get_processor_function(model_type: str) -> Callable:
18-
if model_type.startswith("yolo11"):
19-
model_type = model_type.replace("yolo11", "yolov11")
20-
2124
supported_models = [
2225
"yolov5",
2326
"yolov7-seg",
2427
"yolov8",
2528
"yolov9",
29+
"yolov10",
30+
"yolov11",
31+
"yolov12",
2632
"yolonas",
2733
"paligemma",
2834
"paligemma2",
29-
"yolov10",
3035
"florence-2",
31-
"yolov11",
3236
]
3337

3438
if not any(supported_model in model_type for supported_model in supported_models):
@@ -109,6 +113,18 @@ def _process_yolo(model_type: str, model_path: str, filename: str) -> str:
109113

110114
print_warn_for_wrong_dependencies_versions([("ultralytics", ">=", "8.3.0")], ask_to_continue=True)
111115

116+
elif "yolov12" in model_type:
117+
try:
118+
import torch
119+
import ultralytics
120+
except ImportError:
121+
raise RuntimeError(
122+
"The ultralytics python package is required to deploy yolov12"
123+
" models. Please install it with `pip install ultralytics`"
124+
)
125+
126+
print_warn_for_wrong_dependencies_versions([("ultralytics", ">=", "8.3.78")], ask_to_continue=True)
127+
112128
model = torch.load(os.path.join(model_path, filename))
113129

114130
if isinstance(model["model"].names, list):
@@ -120,9 +136,9 @@ def _process_yolo(model_type: str, model_path: str, filename: str) -> str:
120136
class_names.sort(key=lambda x: x[0])
121137
class_names = [x[1] for x in class_names]
122138

123-
if "yolov8" in model_type or "yolov10" in model_type or "yolov11" in model_type:
139+
if "yolov8" in model_type or "yolov10" in model_type or "yolov11" in model_type or "yolov12" in model_type:
124140
# try except for backwards compatibility with older versions of ultralytics
125-
if "-cls" in model_type or model_type.startswith("yolov10") or model_type.startswith("yolov11"):
141+
if "-cls" in model_type or model_type.startswith("yolov10") or model_type.startswith("yolov11") or model_type.startswith("yolov12"):
126142
nc = model["model"].yaml["nc"]
127143
args = model["train_args"]
128144
else:

0 commit comments

Comments
 (0)