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

Getting error torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'inplace' #2

Open
samygarg opened this issue May 5, 2021 · 3 comments
Labels
question Further information is requested

Comments

@samygarg
Copy link

samygarg commented May 5, 2021

Thank you very much for creating this repo.

I placed the default yolov5s.pt file in the root directory and ran the following command:

poetry run coreml-export --model-input-path yolov5s.pt

But getting this error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/samygarg/Documents/yolov5-coreml-tools/src/coreml_export/main.py", line 318, in main
    model(sampleInput)
  File "/Users/samygarg/Library/Caches/pypoetry/virtualenvs/coreml-tools-LHeNloI_-py3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/Users/samygarg/Documents/yolov5/models/yolo.py", line 117, in forward
    return self.forward_once(x, profile)  # single-scale inference, train
  File "/Users/samygarg/Documents/yolov5/models/yolo.py", line 148, in forward_once
    x = m(x)  # run
  File "/Users/samygarg/Library/Caches/pypoetry/virtualenvs/coreml-tools-LHeNloI_-py3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/Users/samygarg/Documents/yolov5/models/yolo.py", line 55, in forward
    if self.inplace:
  File "/Users/samygarg/Library/Caches/pypoetry/virtualenvs/coreml-tools-LHeNloI_-py3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 779, in __getattr__
    type(self).__name__, name))
torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'inplace'

Please let me know how I can get it to work.

@Leon0402 Leon0402 added the question Further information is requested label May 5, 2021
@Leon0402
Copy link
Contributor

Leon0402 commented May 5, 2021

Your welcome!

Could you please answer the following questions:

  • What version of yolov5s are you using? The pretrained model from the recent 5.0 release? -> I tested the code with version 2, 3 and 4
  • Are you also on the branch of yolov5 for that model?
  • Did you modify any of the dependencies in pyproject.toml?

From a first guess I would say you use an (out of the box) incompatible combination of yolov5, pytorch and coremltools. I might be able to include a fix for this if I know more details.

For a first test, I would recommend downloading the yolov5s version4 model and using it with the repo as is. This should work out of the box.

@samygarg
Copy link
Author

samygarg commented May 7, 2021

@Leon0402 Thank you very much your quick reply.

I switched to the glenn-jocher-patch-4 branch and used the pretrained v4 model and it seemed to work. Not sure why this is though.

Similarly, it works for other branches like the C6 branch.

When I run the same on the master branch, I get the earlier error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/samygarg/Documents/yolov5-coreml-tools/src/coreml_export/main.py", line 318, in main
    model(sampleInput)
  File "/Users/samygarg/Library/Caches/pypoetry/virtualenvs/coreml-tools-LHeNloI_-py3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/Users/samygarg/Documents/yolov5/models/yolo.py", line 117, in forward
    return self.forward_once(x, profile)  # single-scale inference, train
  File "/Users/samygarg/Documents/yolov5/models/yolo.py", line 148, in forward_once
    x = m(x)  # run
  File "/Users/samygarg/Library/Caches/pypoetry/virtualenvs/coreml-tools-LHeNloI_-py3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/Users/samygarg/Documents/yolov5/models/yolo.py", line 55, in forward
    if self.inplace:
  File "/Users/samygarg/Library/Caches/pypoetry/virtualenvs/coreml-tools-LHeNloI_-py3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 779, in __getattr__
    type(self).__name__, name))
torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'inplace'

@Leon0402
Copy link
Contributor

Leon0402 commented May 7, 2021

Where do you get the pretrained model from?

On the Bottom you can download the Yolov5s version Version 4
https://github.com/ultralytics/yolov5/releases/tag/v4.0

Then you need to check out the source code for exactly this model:
git switch tags/v4 -b putSomeBranchTagHere

Then you need to add a setup.py with the dependencies, so poetry installs all dependencies of yolov5 correctly.

Therefore: The pretrained model has to match the source code it was pretrained with!

If you use the model from https://github.com/ultralytics/yolov5/releases/tag/v5.0, then checkout the v5.0 tag.

As I said this should work with v2.0 , v3.0, v4.0 tag. There might be issues with the v5.0 tag, I haven't tried it yet. The reasons why the version used is so important is because yolo uses newer pytorch version and features, but coremltools (the library used for export) doesn't support the newer versions. So in order to use the v5 model I probably need to update the coremltools lib (if there is one) or even include a patch.
I included a patch for v4 version otherwise it wouldn't work at the moment.

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