How is the yolo_x_layout model loaded?
#2
by
shivanshdhar
- opened
Typical YOLO models are loaded like so:
from ultralytics import YOLO
model = YOLO("yolox_l.pt")
However, in the case of this model I'm getting the following error:
File /usr/local/anaconda3/envs/llm_exploration/lib/python3.10/site-packages/ultralytics/models/yolo/model.py:28, in YOLO.__init__(self, model, task, verbose)
25 self.__dict__ = new_instance.__dict__
26 else:
27 # Continue with default YOLO initialization
---> 28 super().__init__(model=model, task=task, verbose=verbose)
File /usr/local/anaconda3/envs/llm_exploration/lib/python3.10/site-packages/ultralytics/engine/model.py:141, in Model.__init__(self, model, task, verbose)
139 self._new(model, task=task, verbose=verbose)
140 else:
--> 141 self._load(model, task=task)
File /usr/local/anaconda3/envs/llm_exploration/lib/python3.10/site-packages/ultralytics/engine/model.py:230, in Model._load(self, weights, task)
227 weights = checks.check_model_file_from_stem(weights) # add suffix, i.e. yolov8n -> yolov8n.pt
229 if Path(weights).suffix == ".pt":
--> 230 self.model, self.ckpt = attempt_load_one_weight(weights)
231 self.task = self.model.args["task"]
232 self.overrides = self.model.args = self._reset_ckpt_args(self.model.args)
File /usr/local/anaconda3/envs/llm_exploration/lib/python3.10/site-packages/ultralytics/nn/tasks.py:807, in attempt_load_one_weight(weight, device, inplace, fuse)
805 def attempt_load_one_weight(weight, device=None, inplace=True, fuse=False):
806 """Loads a single model weights."""
--> 807 ckpt, weight = torch_safe_load(weight) # load ckpt
808 args = {**DEFAULT_CFG_DICT, **(ckpt.get("train_args", {}))} # combine model and default args, preferring model args
809 model = (ckpt.get("ema") or ckpt["model"]).to(device).float() # FP32 model
File /usr/local/anaconda3/envs/llm_exploration/lib/python3.10/site-packages/ultralytics/nn/tasks.py:761, in torch_safe_load(weight)
755 if not isinstance(ckpt, dict):
756 # File is likely a YOLO instance saved with i.e. torch.save(model, "saved_model.pt")
757 LOGGER.warning(
758 f"WARNING ⚠️ The file '{weight}' appears to be improperly saved or formatted. "
759 f"For optimal results, use model.save('filename.pt') to correctly save YOLO models."
760 )
--> 761 ckpt = {"model": ckpt.model}
763 return ckpt, file
File /usr/local/anaconda3/envs/llm_exploration/lib/python3.10/site-packages/torch/jit/_script.py:823, in RecursiveScriptModule.__getattr__(self, attr)
820 self.__dict__[attr] = script_method
821 return script_method
--> 823 return super().__getattr__(attr)
File /usr/local/anaconda3/envs/llm_exploration/lib/python3.10/site-packages/torch/jit/_script.py:530, in ScriptModule.__getattr__(self, attr)
528 def __getattr__(self, attr):
529 if "_actual_script_module" not in self.__dict__:
--> 530 return super().__getattr__(attr)
531 return getattr(self._actual_script_module, attr)
File /usr/local/anaconda3/envs/llm_exploration/lib/python3.10/site-packages/torch/nn/modules/module.py:1688, in Module.__getattr__(self, name)
1686 if name in modules:
1687 return modules[name]
-> 1688 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'RecursiveScriptModule' object has no attribute 'model'
Any idea how to get around this?
You should use yolox
framework instead of ultralytics
. Or load by onnxruntime for .onnx file.