Deci-AI / super-gradients

Easily train or fine-tune SOTA computer vision models with one open source training library. The home of Yolo-NAS.
https://www.supergradients.com
Apache License 2.0
4.54k stars 496 forks source link

AttributeError: 'YoloNAS_S' object has no attribute 'model' #1893

Closed jrsebastian closed 5 months ago

jrsebastian commented 7 months ago

💡 Your Question

Hi! When i tried to eval yolov_nas_s.pt, i met some errors, can anybody help me?

$yolo val model=yolo_nas_s.pt data=coco8.yaml

The console stream is logged into /data/shijiarong/sg_logs/console.log
[2024-03-07 14:47:33] INFO - crash_tips_setup.py - Crash tips is enabled. You can set your environment variable to CRASH_HANDLER=FALSE to disable it
[2024-03-07 14:47:33] WARNING - __init__.py - Failed to import pytorch_quantization
[2024-03-07 14:47:35] WARNING - calibrator.py - Failed to import pytorch_quantization
[2024-03-07 14:47:35] WARNING - export.py - Failed to import pytorch_quantization
[2024-03-07 14:47:35] WARNING - selective_quantization_utils.py - Failed to import pytorch_quantization
WARNING ⚠️ The file 'yolo_nas_s.pt' appears to be improperly saved or formatted. For optimal results, use model.save('filename.pt') to correctly save YOLO models.
Traceback (most recent call last):
  File "/data/shijiarong/.local/bin/yolo", line 8, in <module>
    sys.exit(entrypoint())
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/cfg/__init__.py", line 541, in entrypoint
    model = YOLO(model, task=task)
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/models/yolo/model.py", line 23, in __init__
    super().__init__(model=model, task=task, verbose=verbose)
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/engine/model.py", line 142, in __init__
    self._load(model, task=task)
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/engine/model.py", line 229, in _load
    self.model, self.ckpt = attempt_load_one_weight(weights)
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/nn/tasks.py", line 782, in attempt_load_one_weight
    ckpt, weight = torch_safe_load(weight)  # load ckpt
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/nn/tasks.py", line 736, in torch_safe_load
    ckpt = {"model": ckpt.model}
  File "/data/shijiarong/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1688, in __getattr__
    raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'YoloNAS_S' object has no attribute 'model'

And I get another model form https://sghub.deci.ai/models/yolo_nas_s_coco.pth , also failed in ultralytics

$ yolo val model=yolo_nas_s_coco.pt data=coco8.yaml

Traceback (most recent call last):
  File "/data/shijiarong/.local/bin/yolo", line 8, in <module>
    sys.exit(entrypoint())
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/cfg/__init__.py", line 541, in entrypoint
    model = YOLO(model, task=task)
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/models/yolo/model.py", line 23, in __init__
    super().__init__(model=model, task=task, verbose=verbose)
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/engine/model.py", line 142, in __init__
    self._load(model, task=task)
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/engine/model.py", line 229, in _load
    self.model, self.ckpt = attempt_load_one_weight(weights)
  File "/data/shijiarong/.local/lib/python3.9/site-packages/ultralytics/nn/tasks.py", line 790, in attempt_load_one_weight
    model = (ckpt.get("ema") or ckpt["model"]).to(device).float()  # FP32 model
KeyError: 'model'

Can someone gave me some advice? Thanks in advance

Additional

super_gradients 3.6.0 ultralytics 8.1.17 torch 2.2.1 torchvision 0.17.1 python 3.9.18

Versions

No response

BloodAxe commented 7 months ago

I'm not sure why you are trying to put YoloNAS to ultralitics. Why? As the error message is trying to tell that probably you are doing something wrong: The file 'yolo_nas_s.pt' appears to be improperly saved or formatted.

jrsebastian commented 7 months ago

I'm not sure why you are trying to put YoloNAS to ultralitics. Why? As the error message is trying to tell that probably you are doing something wrong: The file 'yolo_nas_s.pt' appears to be improperly saved or formatted.

@BloodAxe Thank you. I use YoloNAS in ultralitics because i don't konw how to eval a model in super-gradients, don you have any advices? Actually I want to eval/predict/infer a YoloNAS pre-trained model. Thanks

jrsebastian commented 7 months ago

@BloodAxe Could you give me some advice on testing mAP of 'yolo_nas_s.pt’? Can super-gradients do this ?

BloodAxe commented 5 months ago

Yes we can: https://github.com/Deci-AI/super-gradients/blob/bcb0b9f68b5a645c1a705bf63785a70d0a822a5e/src/super_gradients/evaluate_checkpoint.py https://github.com/Deci-AI/super-gradients/blob/bcb0b9f68b5a645c1a705bf63785a70d0a822a5e/src/super_gradients/evaluate_from_recipe.py