From 8b84ade39b09687bb4aa3311444a48cda103ec91 Mon Sep 17 00:00:00 2001 From: Defne Dilbaz Date: Wed, 2 Apr 2025 16:37:09 -0400 Subject: [PATCH] Fix torch.load Weights only load failed. Changed torch.load(file, map_location=cpu) to ckpt = torch.load(file, map_location=cpu, weights_only=False). Resolves #523. Credit goes to @allansdefreitas. --- ultralytics/nn/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultralytics/nn/tasks.py b/ultralytics/nn/tasks.py index 268bd125..ba4e36ab 100644 --- a/ultralytics/nn/tasks.py +++ b/ultralytics/nn/tasks.py @@ -730,7 +730,7 @@ def torch_safe_load(weight): "ultralytics.yolo.data": "ultralytics.data", } ): # for legacy 8.0 Classify and Pose models - ckpt = torch.load(file, map_location="cpu") + ckpt = torch.load(file, map_location="cpu", weights_only=False) except ModuleNotFoundError as e: # e.name is missing module name if e.name == "models":