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

Error on converting a custom yolov5s to yolort #141

Closed
erfaneshratifar opened this issue Jul 15, 2021 · 4 comments · Fixed by #167
Closed

Error on converting a custom yolov5s to yolort #141

erfaneshratifar opened this issue Jul 15, 2021 · 4 comments · Fixed by #167
Labels
bug / fix Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@erfaneshratifar
Copy link

I'm getting this error when converting a customized yolov5 to yolort:

Traceback (most recent call last):
  File "convert_ultralytics_to_yolort.py", line 31, in <module>
    num_classes=80)
  File "/yolov5/yolort/utils/update_module_state.py", line 74, in update_module_state_from_ultralytics
    module_state_updater.updating(model)
  File "/yolov5/yolort/utils/update_module_state.py", line 111, in updating
    self.attach_parameters_block(state_dict, name, None))
  File "/yolov5/yolort/utils/update_module_state.py", line 147, in attach_parameters_block
    return rgetattr(state_dict[ind], keys[1:])
  File "/yolov5/yolort/utils/update_module_state.py", line 162, in rgetattr
    return reduce(_getattr, [obj] + attr)
  File "/yolov5/yolort/utils/update_module_state.py", line 161, in _getattr
    return getattr(obj, attr, *args)
  File "/virtualenv/v1/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1131, in __getattr__
    type(self).__name__, name))
AttributeError: 'Conv' object has no attribute 'bn'
@erfaneshratifar erfaneshratifar added the bug / fix Something isn't working label Jul 15, 2021
@zhiqwang
Copy link
Owner

zhiqwang commented Jul 15, 2021

Hi @erfaneshratifar ,

Thanks for reporting this problem. Currently we recommend using https://github.com/zhiqwang/yolov5-rt-stack/blob/master/notebooks/how-to-align-with-ultralytics-yolov5.ipynb to export the yolort model, did you try this first?

If this notebook can't resolve this problem, do you mind sending us your customized yolov5 model and a test image via Cloud Drive or Email, so that we could reproduce this bug?

@Jelly123456
Copy link

@erfaneshratifar which version of yolov5 you use?

For me, I faced the same problem when I use V5.0 of yolov5.
But when I switch to tag V4.0 of yolov5 and I could convert the customized yolo successfully.

I think this repo currently only supports V4.0 of yolov5.

@zhiqwang Do you have a plan to extend the support to V5.0 of yolov5?

@zhiqwang
Copy link
Owner

zhiqwang commented Jul 15, 2021

Hi @Jelly123456 ,

Thanks for pointing out the problem here.

The main structure of v4.0 and v5.0 in YOLOv5 looks very similar, I guess there are some minor changes in their interface. We will adjust the current export interface to adapt to the v5.0 release (or master) of YOLOv5 at the end of this month.

And any contributions are welcome here!

Pitch:

@zhiqwang
Copy link
Owner

zhiqwang commented Sep 21, 2021

Hi all here,

We introduce a new interface to resolve this issue in #167, and now we recommend that you load the checkpoint trained with ultralytics/yolov5 in the following way:

from yolort.models import yolov5s

# the following 'yolov5s.pt' is downloaded from https://github.com/ultralytics/yolov5/releases/download/v4.0/yolov5s.pt
ckpt_path_from_ultralytics = 'yolov5s.pt'
model = yolov5s(score_thresh=0.25)
model.load_from_yolov5(ckpt_path_from_ultralytics)

model.eval()
img_path = 'test/assets/bus.jpg'
results = model.predict(img_path)

And as such we are closing this issue, and fell free to file a new issue if you are having any questions in using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants