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

Move export functionality to AnomalyModule as class methods #1803

Merged

Conversation

thinhngo-x
Copy link
Contributor

@thinhngo-x thinhngo-x commented Mar 1, 2024

📝 Description

✨ Changes

Select what type of change your PR is:

  • 🐞 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)
  • 📚 Documentation update
  • 🔒 Security update

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📋 I have summarized my changes in the CHANGELOG and followed the guidelines for my type of change (skip for minor changes, documentation updates, and test enhancements).
  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).

For more information about code review checklists, see the Code Review Checklist.

@thinhngo-x thinhngo-x marked this pull request as ready for review March 1, 2024 18:46
@thinhngo-x
Copy link
Contributor Author

Hi @samet-akcay, should I fix the Signoff-by-line to get reviewed or do I just need to wait? Thanks.

@samet-akcay
Copy link
Contributor

Hi @samet-akcay, should I fix the Signoff-by-line to get reviewed or do I just need to wait? Thanks.

@thinhngo-x, We'll try to review asap when we get a chance! Thanks for creating this PR and your patience!

Signed-off-by: Duc Thinh Ngo <[email protected]>
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@adrianboguszewski
Copy link
Contributor

@samet-akcay could we prioritize this PR? It looks like it will change OV export once again, so I want to be sure I'm working on the latest version.

@samet-akcay samet-akcay added this to the v1.1.0 milestone Mar 22, 2024
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! Just a minor comment

@thinhngo-x
Copy link
Contributor Author

Thank you all for your comments. I'll try to resolve them one by one very soon.

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.

Looks good to me. Just one minor comment

ov_args = {} if ov_args is None else ov_args
ov_args.update({"example_input": torch.zeros((1, 3, 1, 1)).to(self.device)})
if convert_model is not None and serialize is not None:
model = convert_model(inference_model, **ov_args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work for every model? In the past we had some issues with torch jit which prevented us from using convert_model directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great question. Please ensure all models working previously are still working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out. Indeed the test has failed with some models. I'll investigate this further. If it is too complicated, I might leave it for another PR to solve.

for key, value in metadata.items():
if isinstance(value, torch.Tensor):
metadata[key] = value.numpy().tolist()
class ExportMixin:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this class should be placed under anomalib.models.components.base

Copy link
Contributor Author

@thinhngo-x thinhngo-x Apr 12, 2024

Choose a reason for hiding this comment

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

so far, most of the classes in anomalib.models.components.base are independent base modules to build models. AnomalyModule inherits ExportMixin and ExportMixin is itself not a module to be used elsewhere. I think it should be better to leave it in anomalib.deploy.export. That's my two cents.

raise ModuleNotFoundError
return ov_model_path

def get_metadata(
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is public while the other metadata-related methods are private. Is this intentional and if so what's the reason?


Args:
model (AnomalyModule): Anomaly model which contains metadata related to normalization.
def _get_model_metadata(self) -> dict[str, torch.Tensor]:
Copy link
Contributor

Choose a reason for hiding this comment

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

looking at the metada-related methods here, I'm having some trouble seeing how the responsibilities are divided between get_metadata and _get_model_metadata. Is it really necessary to have both these method or could we merge them into a single method? Also, I feel _write_metadata_to_json is a utility function (like _create_export_root) and could be moved outside of the class.

@thinhngo-x thinhngo-x marked this pull request as draft April 12, 2024 18:12
@ashwinvaidya17 ashwinvaidya17 changed the base branch from main to feature/refactor_export May 14, 2024 11:59
@ashwinvaidya17 ashwinvaidya17 merged commit 4facc63 into openvinotoolkit:feature/refactor_export May 14, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: CI failed at pytest 🔨 Move export functionality to base anomaly module
5 participants