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

avoid failure of plot_feature_outlier_image #774

Merged
merged 5 commits into from
Apr 24, 2023

Conversation

signupatgmx
Copy link
Contributor

@signupatgmx signupatgmx commented Apr 19, 2023

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.

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.
@jklaise jklaise requested a review from mauicv April 20, 2023 08:34
Copy link
Collaborator

@mauicv mauicv left a 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

@signupatgmx
Copy link
Contributor Author

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.
Kind regards.

@codecov
Copy link

codecov bot commented Apr 24, 2023

Codecov Report

Merging #774 (d98f9af) into master (3992180) will decrease coverage by 0.05%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
alibi_detect/utils/visualize.py 0.00% <0.00%> (ø)

... and 3 files with indirect coverage changes

@@ -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)
Copy link
Contributor

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?

Copy link
Collaborator

@mauicv mauicv Apr 24, 2023

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!

Copy link
Contributor

@ascillitoe ascillitoe left a comment

Choose a reason for hiding this comment

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

LGTM!

@mauicv mauicv merged commit fa8f8b6 into SeldonIO:master Apr 24, 2023
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.

3 participants