-
Notifications
You must be signed in to change notification settings - Fork 75
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
Batched metrics - Continuation #357
Open
davor10105
wants to merge
23
commits into
understandable-machine-intelligence-lab:main
Choose a base branch
from
davor10105:batched-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Batched metrics - Continuation #357
davor10105
wants to merge
23
commits into
understandable-machine-intelligence-lab:main
from
davor10105:batched-metrics
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… into batched-metrics
Hi @davor10105, really amazing work!
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey @annahedstroem, as promised (albeit late again :< ) here's the PR including the rest of the batched metrics. The improvements can be found in the image below:
The remaining batched metrics did not yield significant speed-ups because their computations were relatively straightforward, leaving little room for further optimization. This was particularly true for the localization and complexity metrics. Regarding the randomization metrics, with the exception of the RandomLogit, I was unable to identify an effective approach to further reduce their runtime.
I also included changes to some of the metrics due to them not being implemented as described in their respective papers (results from the batched implementation are thus different from the current implementation's):
Non-Sensitivity - Now aligned correctly to the original paper here
Continuity - Similarly, aligned to it's definition here
Focus! - Bug fix - As I previously mentioned on Discord, it appears that the assumed dimensions of the mosaic in the current Quantus implementation are B x C x W x H. However, in reality, the order of the width and height is switched.
Consistency - Similarly, as mentioned in my comment on Discord, I have changed the implementation to align with the paper's definition of the metric.
Comment regarding Focus!
I thought that the x_batch dimensions correspond to B x C x H x W, but looking at the code, for example quadrant_top_right it seems that the assumed dimensions are B x C x W x H. However, when I run the metric using the sample data and scripts provided in Quantus, and visualize the original image and the corresponding top right quadrant, the bottom left quadrant gets cropped instead, which aligns with the assumption that the dimensions are B x C x H x W. Is this an error in quadrant cropping in the current implementation or am I missing something here?Comment regarding Consistency
According to its definition, the Consistency metric "measures the expected local consistency, i.e., the probability that the prediction label for a given data point coincides with the prediction labels of other data points that share the same explanation." Given this, I would expect the metric to select instances within a batch that share the same explanation (where the "explanation label" is determined via the discretization function in Quantus) and then evaluate the proportion of matching model predictions among those instances.However, when reviewing the current implementation in Quantus, I'm struggling to understand why the consistency check is performed by comparing the explanation with its label, rather than comparing the explanation labels directly. Could you clarify this for me?
Below is a code snippet from the current implementation in Quantus:
pred_a = y_pred_classes[i]
same_a = np.argwhere(a == a_label).flatten()
diff_a = same_a[same_a != i]
pred_same_a = y_pred_classes[diff_a]
if len(same_a) == 0:
return 0
return np.sum(pred_same_a == pred_a) / len(diff_a)
And this is the way I thought the metric should work (batched):
batch_size = y_pred_classes.shape[0]
pred_classes_equality = y_pred_classes[None] == y_pred_classes[:, None]
pred_classes_equality *= (1 - np.eye(batch_size)).astype(bool)
a_labels_equality = a_label_batch[None] == a_label_batch[:, None]
a_labels_equality *= (1 - np.eye(batch_size)).astype(bool)
return (pred_classes_equality * a_labels_equality).sum(axis=-1) / (a_labels_equality.sum(axis=-1) + 1e-9)
Thank you for the help!
As always, let me know if you have any questions!