Skip to content

Commit

Permalink
[YOLOv8] Fixing the sparsezoo pathway (#1517)
Browse files Browse the repository at this point in the history
* initial commit

* further fixes

* Update model loading for zoo stubs. Zoo stubs can contain ultralytics-style pre-trained models (base). Cannot assume they are always in sparseml format

* tested pathways

---------

Co-authored-by: Alexandre Marques <alexandre@neuralmagic.com>
  • Loading branch information
dbogunowicz and anmarques committed Apr 12, 2023
1 parent 2265c77 commit 674d50e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/sparseml/yolov8/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,11 @@ def __init__(self, model="yolov8n.yaml", type="v8") -> None:

if model_str.startswith("zoo:"):
model = download_framework_model_by_recipe_type(
Model(model_str), model_suffix=".pt"
Model(model_str), model_suffix="pt"
)
self.is_sparseml_checkpoint = True
elif model_str.endswith(".pt"):

if model_str.endswith(".pt"):
if os.path.exists(model_str):
ckpt = torch.load(model_str)
self.is_sparseml_checkpoint = (
Expand Down Expand Up @@ -586,7 +587,12 @@ def _load(self, weights: str):
self.PredictorClass,
) = self._assign_ops_from_task(self.task)

self.model = self.ModelClass(dict(self.ckpt["model_yaml"]))
if "yaml" in self.ckpt:
self.model = self.ModelClass(dict(self.ckpt["yaml"]))
elif "model_yaml" in self.ckpt:
self.model = self.ModelClass(dict(self.ckpt["model_yaml"]))
else:
self.model = self.ModelClass(dict(self.ckpt["model"].yaml))
if "recipe" in self.ckpt:
manager = ScheduledModifierManager.from_yaml(self.ckpt["recipe"])
epoch = self.ckpt.get("epoch", -1)
Expand Down

0 comments on commit 674d50e

Please sign in to comment.