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

Fix onnx export by rewriting GaussianBlur #476

Merged
merged 7 commits into from
Aug 4, 2022
Merged

Fix onnx export by rewriting GaussianBlur #476

merged 7 commits into from
Aug 4, 2022

Conversation

ORippler
Copy link
Contributor

@ORippler ORippler commented Aug 2, 2022

Description

  • Provide a summary of the modification as well as the issue that has been resolved. List any dependencies that this modification necessitates.
  • In PyTorch 1.12, export to onnx fails due failing shape-inference of torch.nn.functional.interpolate, refer Export to onnx fails for some models with Pytorch 1.12 #472.
  • Failing exports can be fixed by reimplementing GaussianBlur2d to no longer rely on input shapes for calculation of the kernel size. As a caveat, now the number of channels need to be specified during init

Changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which refactors the code base)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the pre-commit style and check guidelines of this project.
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

@ORippler
Copy link
Contributor Author

ORippler commented Aug 2, 2022

I changed the AnomalyMapGenerator to inherit from nn.Module, should this also be done for all other instances of AnomalyMapGenerator for consistency? Was there a reason I am unaware of for not making all other AnomalyMapGenerator classes instances of nn.Module initially?

@samet-akcay
Copy link
Contributor

I changed the AnomalyMapGenerator to inherit from nn.Module, should this also be done for all other instances of AnomalyMapGenerator for consistency? Was there a reason I am unaware of for not making all other AnomalyMapGenerator classes instances of nn.Module initially?

As far as I'm aware there was no reason. It would be a good idea to inherit nn.Module for every AnomalyMapGenerator for consistency. It could perhaps be another pr since the scope of this pr is gaussian blur

Copy link
Contributor

@djdameln djdameln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this! I'll approve the PR once we settle on the appropriate location to store the new GaussianBlur class.

Copy link
Collaborator

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for identifying and fixing this! I am fine with the changes but I'd wait for the consensus from others regarding the location of blur.py before merging.

@ORippler
Copy link
Contributor Author

ORippler commented Aug 4, 2022

Thanks for identifying and fixing this! I am fine with the changes but I'd wait for the consensus from others regarding the location of blur.py before merging.

Moved it to anomalib/models/components/filters, feel free to merge after tests pass

@samet-akcay samet-akcay merged commit e19428f into openvinotoolkit:main Aug 4, 2022
@ORippler ORippler deleted the fix_onnx_export branch August 4, 2022 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export to onnx fails for some models with Pytorch 1.12
4 participants