ultralytics 8.1.8 new model.save('filename.pt') method (#7886)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Glenn Jocher 2024-01-30 01:06:14 +01:00 committed by GitHub
parent 7ac65dc33b
commit 8c158823e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 370 additions and 86 deletions

View file

@ -631,7 +631,7 @@ def torch_safe_load(weight):
"ultralytics.yolo.data": "ultralytics.data",
}
): # for legacy 8.0 Classify and Pose models
return torch.load(file, map_location="cpu"), file # load
ckpt = torch.load(file, map_location="cpu")
except ModuleNotFoundError as e: # e.name is missing module name
if e.name == "models":
@ -651,8 +651,17 @@ def torch_safe_load(weight):
f"run a command with an official YOLOv8 model, i.e. 'yolo predict model=yolov8n.pt'"
)
check_requirements(e.name) # install missing module
ckpt = torch.load(file, map_location="cpu")
return torch.load(file, map_location="cpu"), file # load
if not isinstance(ckpt, dict):
# File is likely a YOLO instance saved with i.e. torch.save(model, "saved_model.pt")
LOGGER.warning(
f"WARNING ⚠️ The file '{weight}' appears to be improperly saved or formatted. "
f"For optimal results, use model.save('filename.pt') to correctly save YOLO models."
)
ckpt = {"model": ckpt.model}
return ckpt, file # load
def attempt_load_weights(weights, device=None, inplace=True, fuse=False):