Skip to content

Commit 969c14e

Browse files
committed
fix: unpickling-error-pytorch-2.6
1 parent 50c7b71 commit 969c14e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

modules/subcore.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,20 @@ def torch_wrapper(*args, **kwargs):
312312

313313
torch.load = torch_wrapper
314314

315-
316315
def load_yolo(model_path: str):
317-
return YOLO(model_path)
318-
316+
try:
317+
# Try the new PyTorch 2.6+ safe loading approach first
318+
with torch.serialization.safe_globals([DetectionModel]):
319+
return YOLO(model_path)
320+
except (AttributeError, TypeError):
321+
# Fallback for older PyTorch versions that don't have safe_globals
322+
# or if safe_globals doesn't accept the DetectionModel class
323+
try:
324+
return YOLO(model_path)
325+
except Exception as e:
326+
# If both methods fail, log the error and re-raise
327+
logging.error(f"[Impact Pack/Subpack] Failed to load YOLO model from {model_path}: {e}")
328+
raise
319329

320330
def inference_bbox(
321331
model,

0 commit comments

Comments
 (0)