Skip to content

Commit d608abf

Browse files
committed
Add load model ONLY
1 parent 01318af commit d608abf

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

evaluation_function/evaluation.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,54 @@ def evaluation_function(response: Any, answer: Any, params: Params) -> Result:
350350
items.append(("TRACEBACK", _tb_short()))
351351
_add_common_timing(items, t_handler0)
352352
return _result(False, items)
353+
# ----------------------------
354+
# D0) load model ONLY (no image required)
355+
# ----------------------------
356+
if diag == "load_model_only":
357+
try:
358+
_stage(items, "load_model_only_begin")
359+
360+
# ultralytics symbol
361+
_stage(items, "ultralytics_symbol_begin")
362+
YOLO, dt_ul = _timeit(lambda: ultralytics.YOLO)
363+
items.append(("t_ultralytics_symbol_s", f"{dt_ul:.4f}"))
364+
_stage(items, "ultralytics_symbol_done")
365+
366+
model_path = next((p for p in _candidate_model_paths() if os.path.exists(p)), None)
367+
if not model_path:
368+
items.append(("D_FAIL", "No model file found to load"))
369+
items.append(("D_candidates", " | ".join(_candidate_model_paths())))
370+
_add_common_timing(items, t_handler0)
371+
return _result(False, items)
372+
373+
items.append(("D_model_path", model_path))
374+
375+
# torch threads (helps slow/hang-like behaviour)
376+
try:
377+
_ = torch.__version__
378+
torch.set_num_threads(1)
379+
torch.set_num_interop_threads(1)
380+
items.append(("torch_threads", "set to 1"))
381+
except Exception:
382+
pass
383+
384+
# actual load
385+
_stage(items, "yolo_load_begin")
386+
_, dt_load = _timeit(lambda: YOLO(model_path))
387+
items.append(("t_model_load_s", f"{dt_load:.4f}"))
388+
_stage(items, "yolo_load_done")
353389

390+
items.append(("D_load", "model loaded ✅"))
391+
_stage(items, "load_model_only_done")
392+
393+
_add_common_timing(items, t_handler0)
394+
return _result(False, items)
395+
396+
except Exception:
397+
items.append(("D_FAIL", "see TRACEBACK"))
398+
items.append(("TRACEBACK", _tb_short()))
399+
_add_common_timing(items, t_handler0)
400+
return _result(False, items)
354401
# ----------------------------
355402
# D) load model only (no inference)
356403
# ----------------------------

0 commit comments

Comments
 (0)