FIx downstream impact by the replacement of torch.load in ultralytics package (#13623)
* Update torch_load * Auto-format by https://ultralytics.com/actions --------- Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
1 parent
79c4c31d16
commit
2540fd4c1c
9 files changed
+20
-12
No files matched your search
+2
-1
@@ -9,6 +9,7 @@ from pathlib import Path
|
||||
|
||||
import torch
|
||||
import yaml
|
||||
from ultralytics.utils.patches import torch_load
|
||||
|
||||
FILE = Path(__file__).resolve()
|
||||
ROOT = FILE.parents[2] # YOLOv5 root directory
|
||||
@@ -18,7 +19,7 @@ if str(ROOT) not in sys.path:
|
||||
port = 0 # --master_port
|
||||
path = Path("").resolve()
|
||||
for last in path.rglob("*/**/last.pt"):
|
||||
ckpt = torch.load(last)
|
||||
ckpt = torch_load(last)
|
||||
if ckpt["optimizer"] is None:
|
||||
continue
|
||||
|
||||
|
||||
+2
-1
@@ -44,6 +44,7 @@ except (ImportError, AssertionError):
|
||||
import ultralytics
|
||||
|
||||
from ultralytics.utils.checks import check_requirements
|
||||
from ultralytics.utils.patches import torch_load
|
||||
|
||||
from utils import TryExcept, emojis
|
||||
from utils.downloads import curl_download, gsutil_getsize
|
||||
@@ -1127,7 +1128,7 @@ def strip_optimizer(f="best.pt", s=""):
|
||||
|
||||
Example: from utils.general import *; strip_optimizer()
|
||||
"""
|
||||
x = torch.load(f, map_location=torch.device("cpu"))
|
||||
x = torch_load(f, map_location=torch.device("cpu"))
|
||||
if x.get("ema"):
|
||||
x["model"] = x["ema"] # replace model with ema
|
||||
for k in "optimizer", "best_fitness", "ema", "updates": # keys
|
||||
|
||||
Reference in new issue
Block a user