Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some error in export to onnx #49

Open
Halafz7 opened this issue Mar 10, 2024 · 5 comments
Open

Some error in export to onnx #49

Halafz7 opened this issue Mar 10, 2024 · 5 comments
Labels
question Further information is requested

Comments

@Halafz7
Copy link

Halafz7 commented Mar 10, 2024

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 Halafz7 added the question Further information is requested label Mar 10, 2024
Copy link

👋 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 glenn.jocher@ultralytics.com.

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.

@sefaburakokcu
Copy link
Owner

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

@Halafz7
Copy link
Author

Halafz7 commented Mar 10, 2024

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

@sefaburakokcu
Copy link
Owner

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?

@Halafz7
Copy link
Author

Halafz7 commented Mar 11, 2024

Won't the classes switch automatically during training?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants