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

Add image similarity high-level interface #107

Merged
merged 6 commits into from
Apr 5, 2022

Conversation

schencej
Copy link
Contributor

Highlights:

  • Added interface for computing image similarity saliency maps: GenerateImageSimilarityBlackboxSaliency
  • Added two implementations: PerturbationOcclusion (following pattern of other interfaces) and SBSMStack
  • Updated the SimilarityScoring saliency generation impl to return a [HxW] heatmap instead of [1xHxW]. This is consistent with the description of the interface that it implements.
  • Updated the similarity example notebook to use SBSMStack. I got rid of the application style used by the previous version because the new interface takes care of all the logic performed by the "app". The previous version also mentions that it shows the use of multiple API implementations, but it only uses one set of perturbation/scoring implementations. I got rid of these mentions.
  • Adopted consistent nomenclature for the input images. Now the image that saliency is computed for is called the "query image" and the other is the "reference image". "Query" sounds like the image that we are interested in, in my head, so this naming scheme makes sense to me. Open to changing this.

@codecov
Copy link

codecov bot commented Mar 30, 2022

Codecov Report

Merging #107 (1fe9f29) into master (c1ef9b7) will decrease coverage by 0.08%.
The diff coverage is 99.22%.

❗ Current head 1fe9f29 differs from pull request most recent head 5fe22fd. Consider uploading reports for the commit 5fe22fd to get more accurate results

@@            Coverage Diff             @@
##           master     #107      +/-   ##
==========================================
- Coverage   99.95%   99.87%   -0.09%     
==========================================
  Files          51       57       +6     
  Lines        2074     2327     +253     
==========================================
+ Hits         2073     2324     +251     
- Misses          1        3       +2     
Flag Coverage Δ
unittests 99.87% <99.22%> (-0.09%) ⬇️

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

Impacted Files Coverage Δ
...aitk_saliency/interfaces/gen_descriptor_sim_sal.py 100.00% <ø> (ø)
xaitk_saliency/exceptions.py 66.66% <60.00%> (-33.34%) ⬇️
.../gen_descriptor_sim_sal/test_similarity_scoring.py 100.00% <100.00%> (ø)
...pls/gen_image_similarity_blackbox_sal/test_sbsm.py 100.00% <100.00%> (ø)
...imilarity_blackbox_sal/test_sim_occlusion_based.py 100.00% <100.00%> (ø)
...terfaces/test_gen_image_similarity_blackbox_sal.py 100.00% <100.00%> (ø)
...impls/gen_descriptor_sim_sal/similarity_scoring.py 100.00% <100.00%> (ø)
...n_image_similarity_blackbox_sal/occlusion_based.py 100.00% <100.00%> (ø)
...cy/impls/gen_image_similarity_blackbox_sal/sbsm.py 100.00% <100.00%> (ø)
...cy/interfaces/gen_image_similarity_blackbox_sal.py 100.00% <100.00%> (ø)
... and 1 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 c1ef9b7...5fe22fd. Read the comment docs.

@schencej
Copy link
Contributor Author

schencej commented Apr 1, 2022

Rebased to new master and addressed comments in fixup commits.

Copy link
Member

@Purg Purg left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for getting this in.

Copy link
Member

@brianhhu brianhhu left a comment

Choose a reason for hiding this comment

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

Overall, LGTM. I made a few minor suggestions, and wanted to clarify whether we do actually want to remove the first dimension of the similarity-based saliency maps, as it makes it less consistent with our other saliency map outputs, which are generally of the form [N x H x W].

docs/release_notes/pending_release.rst Show resolved Hide resolved
This saliency implementation transforms proximity in feature space into
saliency heatmaps.
This should require a sequence of feature vectors of the query and reference
image, a number of feature vectors as predicted on perturbed version of the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
image, a number of feature vectors as predicted on perturbed version of the
image, a number of feature vectors as predicted on perturbed versions of the

:param ref_descr_2:
Second image reference float feature-vector, shape `[nFeats]`
:param ref_descr:
Reference iamge float feature-vector, shape `[nFeats]`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Reference iamge float feature-vector, shape `[nFeats]`
Reference image float feature-vector, shape `[nFeats]`

:param ref_descr:
Reference iamge float feature-vector, shape `[nFeats]`
:param query_descr:
Query image reference float feature-vector, shape `[nFeats]`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Query image reference float feature-vector, shape `[nFeats]`.
Query image float feature-vector, shape `[nFeats]`.


The perturbation masks used by the following implementation are
expected to be of type integer. Masks containing values of type
float are rounded to the nearest value and binarized
with value 1 replacing values greater than or equal to half of
the maximum value in mask after rounding while 0 replaces the rest.

The resulting saliency maps are relative to the query image.
Copy link
Member

Choose a reason for hiding this comment

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

I think the wording here is a bit ambiguous, I suggest adding the same text you used below for the interface:

Suggested change
The resulting saliency maps are relative to the query image.
The resulting saliency map is relative to the query image.
As such, it denotes regions in the query image that make it more or less
similar to the other image, called the reference image.

"show_sal_map(test_image2, test_image1, sal_map)\n",
"\n",
"# a -> a\n",
"sal_map = sal_generator(\n",
Copy link
Member

Choose a reason for hiding this comment

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

The saliency map ranges here for the last two image similarity saliency pairs are slightly different than in master, e.g. [0.0397, 1] vs. [0.0607, 1] and [0.044, 1] vs. [0.079, 1]. Do we know why this is? The shape of the saliency maps look generally consistent though.

Copy link
Contributor Author

@schencej schencej Apr 5, 2022

Choose a reason for hiding this comment

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

I believe this is due to the updated sliding window implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had environment issues and was running with the old sliding window implementation. Re-ran and it matches master now.

@kwrobot-v1
Copy link

kwrobot-v1 bot commented Apr 5, 2022

Errors:

  • Failed to reserve ref f7a66d6 for the merge request: invalid git ref: 'no such commit'.
  • Failed to run the checks: mr utilities error: failed to list commits of f7a66d6b6a76588d748f271578c2ad4851fbc93b for https://github.com/XAITK/xaitk-saliency/pull/107: fatal: bad object f7a66d6b6a76588d748f271578c2ad4851fbc93b .

@sonarcloud
Copy link

sonarcloud bot commented Apr 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@brianhhu brianhhu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@Purg Purg merged commit d51dcc3 into XAITK:master Apr 5, 2022
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.

None yet

3 participants