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

Resize bug in inference #83

Closed
QQR1 opened this issue Jan 20, 2022 · 12 comments · Fixed by #135 or #140
Closed

Resize bug in inference #83

QQR1 opened this issue Jan 20, 2022 · 12 comments · Fixed by #135 or #140
Assignees
Labels
Bug Something isn't working

Comments

@QQR1
Copy link

QQR1 commented Jan 20, 2022

  • When input the width and height of the image are not equal, sizes of input arguments that do not match will occur

Line 152 in ./anomalib/deploy/inferencers/torch.py should be anomaly_map = cv2.resize(anomaly_map, (meta_data["image_shape"][1], meta_data["image_shape"][0]))

meta_data["image_shape"] is (image_width, image_height)
-# cv2.resize(img, (image_height,image_width ),interpolation=cv2.INTER_CUBIC)

@samet-akcay
Copy link
Contributor

Thanks @QQR1! Good catch!

@samet-akcay samet-akcay added the Bug Something isn't working label Jan 20, 2022
@raviv
Copy link

raviv commented Mar 7, 2022

@QQR1 Did you manage to train when width and height of the image are not equal?
I'm getting an error in anomaly_module.validation_epoch_end()

@samet-akcay
Copy link
Contributor

Hi @raviv , is it the same error reported by @QQR1 ?

@raviv
Copy link

raviv commented Mar 7, 2022

@samet-akcay No, I'm getting an error while training, not inference.
You can easily reproduce by setting image size in config.yaml to something like below and trying to train

  image_size:
    - 512
    - 256

This is the error trace:

  File "/home/raviv/dvlp/anomalib/anomalib/models/components/base/anomaly_module.py", line 151, in _compute_adaptive_threshold
    self.pixel_threshold.compute()
  File "/home/raviv/anaconda3/envs/anomalib_env/lib/python3.8/site-packages/torchmetrics/metric.py", line 380, in wrapped_func
    value = compute(*args, **kwargs)
  File "/home/raviv/dvlp/anomalib/anomalib/utils/metrics/adaptive_threshold.py", line 38, in compute
    precision, recall, thresholds = self.precision_recall_curve.compute()
  File "/home/raviv/anaconda3/envs/anomalib_env/lib/python3.8/site-packages/torchmetrics/metric.py", line 380, in wrapped_func
    value = compute(*args, **kwargs)
  File "/home/raviv/anaconda3/envs/anomalib_env/lib/python3.8/site-packages/torchmetrics/classification/precision_recall_curve.py", line 149, in compute
    return _precision_recall_curve_compute(preds, target, self.num_classes, self.pos_label)
  File "/home/raviv/anaconda3/envs/anomalib_env/lib/python3.8/site-packages/torchmetrics/functional/classification/precision_recall_curve.py", line 259, in _precision_recall_curve_compute
    return _precision_recall_curve_compute_single_class(preds, target, pos_label, sample_weights)
  File "/home/raviv/anaconda3/envs/anomalib_env/lib/python3.8/site-packages/torchmetrics/functional/classification/precision_recall_curve.py", line 139, in _precision_recall_curve_compute_single_class
    fps, tps, thresholds = _binary_clf_curve(
  File "/home/raviv/anaconda3/envs/anomalib_env/lib/python3.8/site-packages/torchmetrics/functional/classification/precision_recall_curve.py", line 39, in _binary_clf_curve
    target = target[desc_score_indices]
IndexError: index 978935 is out of bounds for dimension 0 with size 524288

Process finished with exit code 1

@samet-akcay
Copy link
Contributor

which algorithm is this? Patchcore?

@raviv
Copy link

raviv commented Mar 7, 2022

@samet-akcay PADIM

@samet-akcay
Copy link
Contributor

Thanks, we'll reproduce the issue, and give you an update here.

@djdameln djdameln self-assigned this Mar 7, 2022
@raviv
Copy link

raviv commented Mar 7, 2022

@djdameln Please verify with other algorithms as well. Thanks :)

@djdameln
Copy link
Contributor

djdameln commented Mar 8, 2022

@raviv #135 should solve the image_size problems for both training and inference for most models. Patchcore and GANomaly still do not allow changing the image size, but this will be addressed separately, see #136 and #40.

@raviv
Copy link

raviv commented Mar 9, 2022

@djdameln got latest dev branch and the fix @QQR1 suggested is not there.
Training works but inference fails on the original bug in this thread (resizing anonmaly map)

@djdameln djdameln mentioned this issue Mar 9, 2022
11 tasks
@djdameln
Copy link
Contributor

djdameln commented Mar 9, 2022

@raviv Sorry, I misinterpreted the original post and thought the problem was for non-square image_size parameter in the config.yaml. I implemented the fix suggested by @QQR1 in a new PR #140.

@samet-akcay
Copy link
Contributor

@raviv PR #140 has now been merged, and the issue should be fixed. Feel free to re-open it if you think there is still an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants