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

Add Torch Inferencer and Update Openvino and Gradio Inferencers. #453

Merged
merged 18 commits into from
Jul 29, 2022

Conversation

samet-akcay
Copy link
Contributor

Description

  • Add Torch Inferencer.

  • Return all the predictions from inferencer.predict(image). This way, the user will be able to access to any info they need.

  • Fixes # 294

Changes

  • Bug fix (non-breaking change which fixes an issue)
  • 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

@samet-akcay samet-akcay mentioned this pull request Jul 25, 2022
11 tasks
anomalib/data/utils/image.py Show resolved Hide resolved
tools/inference/torch_inference.py Outdated Show resolved Hide resolved
tools/inference/torch_inference.py Outdated Show resolved Hide resolved
anomalib/data/utils/image.py Show resolved Hide resolved
anomalib/data/utils/image.py Show resolved Hide resolved
@@ -141,9 +149,30 @@ def post_process(
anomaly_map = predictions.squeeze()
pred_score = anomaly_map.reshape(-1).max()

# Common practice in anomaly detection is to assign anomalous
# label to the prediction if the prediction score is greater
# than the image threshold.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we warn users if thresholds are not present in meta_data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would bring up another discussion. Do you think we should check if they are in meta_data?

For example,

if "image_threshold" in meta_data:
    pred_label = pred_score >= meta_data["image_threshold"]

We cannot calculate the pred-label if we don't have this. The question is whether we should have this if statement here, and for the rest of the computation?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the default threshold is 0.5 so if we don't have image_threshold in meta_data then we can throw a warning and reduce the if statement to pred_label = pred_score >= meta_data.get("image_threshold", 0.5)

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as we throw a warning it should be fine. Because the users need to be made aware that there is a problem with the metadata file.

anomalib/data/inference.py Outdated Show resolved Hide resolved
tools/inference/torch_inference.py Show resolved Hide resolved
pred_mask = cv2.resize(pred_mask, (image_width, image_height))

return {
"anomaly_map": anomaly_map,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this work for task type of classification?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it returns none, which ImageResults handles ok.

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! All my comments have been addressed

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!

@samet-akcay samet-akcay merged commit d16a145 into development Jul 29, 2022
@samet-akcay samet-akcay deleted the feature/sa/add-torch-inferencer branch July 29, 2022 15:17
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.

None yet

3 participants