-
Notifications
You must be signed in to change notification settings - Fork 221
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
avoid failure of plot_feature_outlier_image #774
Conversation
I call the function this way: plot_feature_outlier_image(preds, # output of an prediction ds, # my set of images X_recon=recon, # reconstructed set of images max_instances=5, # max nb of instances to display n_channels=3, # number of channels of the images figsize=(20,10), outliers_only=True) # only show outlier predictions. this function fails when no outlier is detected and parameter set to True In case there is no outlieres detected and the parameter outliers_only is set to True, then the function fails, because it calls plt.subplots(nrows=0, ....). 0 rows throws the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @signupatgmx,
Thank you very much for opening this PR! I think the change makes sense, one minor ask would be to add a warning if the outliers_only and n_instances == 0
condition is met. If the function returns without warning the user then it's not entirely clear what happened. Lmk if you are happy to do this otherwise I'm happy to pick it up!
Thanks regardless
Hallo @mauicv, as I'm not customized with your coding standards, I'd suggest you add a suitable warning output. I'm glad to have found your great library. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #774 +/- ##
==========================================
- Coverage 81.03% 80.98% -0.05%
==========================================
Files 146 146
Lines 9721 9720 -1
==========================================
- Hits 7877 7872 -5
- Misses 1844 1848 +4
|
alibi_detect/utils/visualize.py
Outdated
@@ -77,6 +78,11 @@ def plot_feature_outlier_image(od_preds: Dict, | |||
instance_ids = list(range(len(od_preds['data']['is_outlier']))) | |||
n_instances = min(max_instances, len(instance_ids)) | |||
instance_ids = instance_ids[:n_instances] | |||
|
|||
if outliers_only and n_instances == 0: | |||
warnings.warn('No outliers found!', UserWarning, stacklevel=3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mauicv is the warning swallowed without stacklevel=3
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've removed it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I call the function this way:
In case there is no outlieres detected and the parameter outliers_only is set to True, then the function fails, because it calls plt.subplots(nrows=0, ....). 0 rows throws the error.