quantized-yolov5 icon indicating copy to clipboard operation
quantized-yolov5 copied to clipboard

Some error in export to onnx

Open Halafz7 opened this issue 11 months ago • 5 comments

So I tried to train yolov5m-quant.yaml with coco128.yaml. When it's done, i want to export it but error come like this

Traceback (most recent call last): File "/content/quantized-yolov5/models/experimental.py", line 97, in attempt_load ema = ckpt['ema' if ckpt.get('ema') else 'model'].float() KeyError: 'model'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/content/quantized-yolov5/export.py", line 418, in main(opt) File "/content/quantized-yolov5/export.py", line 406, in main run(**vars(opt)) File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, **kwargs) File "/content/quantized-yolov5/export.py", line 317, in run model = attempt_load(weights, map_location=device, inplace=True, fuse=True) # load FP32 model File "/content/quantized-yolov5/models/experimental.py", line 105, in attempt_load ema.load_state_dict(ckpt) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 2152, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for Model: Missing key(s) in state_dict: "model.13.m.0.quant_identity.act_quant.fused_activation_quant_proxy.tensor_quant.scaling_impl.value", "model.13.m.1.quant_identity.act_quant.fused_activation_quant_proxy.tensor_quant.scaling_impl.value", "model.17.m.0.quant_identity.act_quant.fused_activation_quant_proxy.tensor_quant.scaling_impl.value", "model.17.m.1.quant_identity.act_quant.fused_activation_quant_proxy.tensor_quant.scaling_impl.value", "model.20.m.0.quant_identity.act_quant.fused_activation_quant_proxy.tensor_quant.scaling_impl.value", "model.20.m.1.quant_identity.act_quant.fused_activation_quant_proxy.tensor_quant.scaling_impl.value", "model.23.m.0.quant_identity.act_quant.fused_activation_quant_proxy.tensor_quant.scaling_impl.value", "model.23.m.1.quant_identity.act_quant.fused_activation_quant_proxy.tensor_quant.scaling_impl.value". size mismatch for model.24.m.0.weight: copying a param with shape torch.Size([255, 192, 1, 1]) from checkpoint, the shape in current model is torch.Size([18, 192, 1, 1]). size mismatch for model.24.m.1.weight: copying a param with shape torch.Size([255, 384, 1, 1]) from checkpoint, the shape in current model is torch.Size([18, 384, 1, 1]). size mismatch for model.24.m.2.weight: copying a param with shape torch.Size([255, 768, 1, 1]) from checkpoint, the shape in current model is torch.Size([18, 768, 1, 1]).

Do you have some advice or suggestion about this error? Thankyou

Halafz7 avatar Mar 10 '24 15:03 Halafz7

👋 Hello @Halafz7, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at [email protected].

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

github-actions[bot] avatar Mar 10 '24 15:03 github-actions[bot]

Hi @Halafz7, Thank you for your interest. Can you share your command for exporting the model?

sefaburakokcu avatar Mar 10 '24 15:03 sefaburakokcu

Sure, i ran it on Colab and saved the weights on my Gdrive

! python export.py --data coco128.yaml --weights /content/gdrive/MyDrive/models/CheckpointsYOLO/YOLOv5/yolov5medium/weights/last.pt --nodetect

Halafz7 avatar Mar 10 '24 16:03 Halafz7

As the error states, you are trying to load weights from 80 classes into a model with only one class. However, your export arguments seem correct.

I think that attempt_load could not found your model.yaml. Can you replace last.pt with best.pt in your arguments?

sefaburakokcu avatar Mar 10 '24 18:03 sefaburakokcu

Won't the classes switch automatically during training?

I did replaced the weight with best.pt but still got the same error

Halafz7 avatar Mar 11 '24 03:03 Halafz7