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

WIP: 1d and non squared 2d input shapes #74

Conversation

dkrako
Copy link
Collaborator

@dkrako dkrako commented Mar 2, 2022

Add support for 1d and non-squared 2d input shapes

@dkrako
Copy link
Collaborator Author

dkrako commented Mar 2, 2022

I did some first work today for 1d-support, mainly working on helpers/utils.py and adding some lazy fixtures for later use.
The channel-methods from the utils module now support 1d and non-squared 2d input and are fully tested.

For better clarity I renamed the channel first methods as can be seen here:
5e6c0a8

  • get_channel_first -> infer_channel_first
  • get_channel_first_batch -> make_channel_first
  • get_channel_last_batch -> make_channel_last

I hope you don't mind the renaming.

dkrako added 22 commits March 2, 2022 19:59
…ould actually support any number of dimensions.
@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2022

Codecov Report

Merging #74 (a4e7cb2) into main (8170c25) will decrease coverage by 3.17%.
The diff coverage is 88.62%.

@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
- Coverage   97.36%   94.18%   -3.18%     
==========================================
  Files          16       16              
  Lines        2235     2458     +223     
==========================================
+ Hits         2176     2315     +139     
- Misses         59      143      +84     
Impacted Files Coverage Δ
quantus/metrics/faithfulness_metrics.py 95.42% <ø> (-3.65%) ⬇️
quantus/metrics/localisation_metrics.py 92.52% <80.37%> (-5.07%) ⬇️
quantus/metrics/axiomatic_metrics.py 93.29% <83.07%> (-4.52%) ⬇️
quantus/metrics/complexity_metrics.py 94.57% <83.33%> (-5.43%) ⬇️
quantus/metrics/randomisation_metrics.py 93.98% <84.21%> (-4.41%) ⬇️
quantus/helpers/tf_model.py 93.87% <87.50%> (+0.39%) ⬆️
quantus/helpers/pytorch_model.py 91.30% <88.88%> (-1.56%) ⬇️
quantus/metrics/robustness_metrics.py 93.31% <90.82%> (-2.68%) ⬇️
quantus/helpers/utils.py 96.66% <94.56%> (-1.04%) ⬇️
quantus/helpers/perturb_func.py 96.42% <95.94%> (-2.40%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8170c25...a4e7cb2. Read the comment docs.

@annahedstroem
Copy link
Member

This PR is comprehensive but 1d-support is not implemented for the following perturbation functions:

  • baseline_replacement_by_blur: uses conv2D_numpy, scipy.signal.convolve
  • rotation, translation_x_direction, translation_y_direction: these use cv2 which expect images as input

Also:

  • get_superpixels also doesn't support 1d, as skimage uses 2d only.
  • IterativeRemovalOfFeatures therefore won't work for 1d yet.

Copy link
Member

@annahedstroem annahedstroem left a comment

Choose a reason for hiding this comment

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

A summary of contribution:

  • Comprehensive changes that allow for more flexibility in input shapes for Quantus - 1D and flexible img_sizes where img width != height.
  • Additional pytests tests created for these purposes

1d-support is NOT implemented for the following functions/ metrics:

  • baseline_replacement_by_blur: uses conv2D_numpy, scipy.signal.convolve
  • rotation, translation_x_direction, translation_y_direction: these use cv2 which expect images as input
  • get_superpixels also doesn't support 1d, as skimage` uses 2d only.
  • IterativeRemovalOfFeatures therefore won't work for 1d yet.

Other notes:

  • We disregard for now the decrease in code coverage by approx ~3% as it relates to the depreciation warnings added to each of the metrics
  • Also an issue is created for making a tutorial to showcase this new functionality New tutorial: for how to use Quantus with 1D shapes #83 but does not necessarily have to be completed to merge this PR

OK - ACCEPTED.

@dkrako
Copy link
Collaborator Author

dkrako commented Mar 17, 2022

Done as discussed.

Copy link
Member

@annahedstroem annahedstroem left a comment

Choose a reason for hiding this comment

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

OK

@annahedstroem annahedstroem merged commit 015f717 into understandable-machine-intelligence-lab:main Mar 21, 2022
@dkrako dkrako deleted the feature/1d-and-non-squared-2d-input-shapes branch March 22, 2022 11:03
aaarrti pushed a commit that referenced this pull request Apr 9, 2023
…t-shapes

WIP: 1d and non squared 2d input shapes
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