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

Fix RISE algorithm for explain function #1263

Merged
merged 2 commits into from
Feb 8, 2024

Conversation

wonjuleee
Copy link
Contributor

@wonjuleee wonjuleee commented Feb 6, 2024

Summary

How to test

Checklist

  • I have added unit tests to cover my changes.​
  • I have added integration tests to cover my changes.​
  • I have added the description of my changes into CHANGELOG.​
  • I have updated the documentation accordingly

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below).
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT

@wonjuleee wonjuleee requested review from a team as code owners February 6, 2024 14:03
@wonjuleee wonjuleee requested review from itrushkin and removed request for a team February 6, 2024 14:03
Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (784e039) 80.54% compared to head (690b6b2) 80.61%.
Report is 1 commits behind head on develop.

Files Patch % Lines
src/datumaro/components/algorithms/rise.py 92.15% 2 Missing and 2 partials ⚠️
.../openvino_plugin/samples/googlenet-v4-tf_interp.py 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1263      +/-   ##
===========================================
+ Coverage    80.54%   80.61%   +0.06%     
===========================================
  Files          271      271              
  Lines        30438    30382      -56     
  Branches      5930     5909      -21     
===========================================
- Hits         24517    24491      -26     
+ Misses        4532     4507      -25     
+ Partials      1389     1384       -5     
Flag Coverage Δ
ubuntu-20.04_Python-3.8 80.59% <92.68%> (+0.06%) ⬆️
windows-2022_Python-3.8 80.57% <92.68%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@sooahleex sooahleex left a comment

Choose a reason for hiding this comment

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

Looks good to me. I left some minor comments.

Comment on lines +41 to +44
normalized_saliency = np.empty_like(saliency)
for idx, sal in enumerate(saliency):
normalized_saliency[idx, ...] = (sal - np.min(sal)) / (np.max(sal) - np.min(sal))
return normalized_saliency
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
normalized_saliency = np.empty_like(saliency)
for idx, sal in enumerate(saliency):
normalized_saliency[idx, ...] = (sal - np.min(sal)) / (np.max(sal) - np.min(sal))
return normalized_saliency
return (saliency - np.min(saliency)) / (np.max(saliency) - np.min(saliency))

I think this could be replaced like this through vectorized operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you for the feedback, but the original code is to normalize each saliency map per class_idx, while your suggestion is to normalize each saliency map from global max and min. So I expect the results will be different.

Comment on lines +34 to +36
logit = pred.get(self.LOGIT_KEY)
if logit is None:
raise DatumaroError(f'"{self.LOGIT_KEY}" key should exist in the model prediction.')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logit = pred.get(self.LOGIT_KEY)
if logit is None:
raise DatumaroError(f'"{self.LOGIT_KEY}" key should exist in the model prediction.')
logit = pred.get(self.LOGIT_KEY, [])
if not logit:
raise DatumaroError(f'"{self.LOGIT_KEY}" key should exist in the model prediction.')

It seems better to use default values for safer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you. let me update this later.

Comment on lines 38 to 40
feature_vector = pred.get(self.FEAT_KEY)
if feature_vector is None:
raise DatumaroError(f'"{self.FEAT_KEY}" key should exist in the model prediction.')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
feature_vector = pred.get(self.FEAT_KEY)
if feature_vector is None:
raise DatumaroError(f'"{self.FEAT_KEY}" key should exist in the model prediction.')
feature_vector = pred.get(self.FEAT_KEY, [])
if not feature_vector:
raise DatumaroError(f'"{self.FEAT_KEY}" key should exist in the model prediction.')

@wonjuleee wonjuleee merged commit 817b44e into openvinotoolkit:develop Feb 8, 2024
5 checks passed
@yunchu yunchu added this to the 2.0.0 milestone Mar 28, 2024
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