-
Notifications
You must be signed in to change notification settings - Fork 24
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
Vectorize image similarity interfaces #110
Conversation
Codecov Report
@@ Coverage Diff @@
## master #110 +/- ##
=======================================
Coverage 99.87% 99.87%
=======================================
Files 57 57
Lines 2327 2329 +2
=======================================
+ Hits 2324 2326 +2
Misses 3 3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
8fb1603
to
cba7ef8
Compare
xaitk_saliency/impls/gen_descriptor_sim_sal/similarity_scoring.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, LGTM- thanks for the update! Added a few minor suggestions for typo and grammar fixes.
xaitk_saliency/impls/gen_descriptor_sim_sal/similarity_scoring.py
Outdated
Show resolved
Hide resolved
xaitk_saliency/impls/gen_descriptor_sim_sal/similarity_scoring.py
Outdated
Show resolved
Hide resolved
I did! I thought I wrote a comment related to that, but I see that I must not have (or missed pressing the "Comment" button). Changing the requirement to be a Alternatively, we can still acquire such a count without requiring an explicit sequence by creating a wrapper iterator around it: def generate(...):
...
num_query = 0
def wrap():
nonlocal num_query
for q in query_images:
yield q
num_query += 1
# the same "get actual output" line as before, but changing the iterable input to the wrapper iterator
output = self._generate(ref_image, wrap(), blackbox)
# num_query should now be the number of query images
assert output.shape[0] == num_query, f"Output heatmaps didn't match input images: {output.shape[0]} != {num_query}"
... I suppose technically the iterator count be copied into separate processes (e.g. torch dataloader with iterable dataset), and there is a solution to that as well using def generate(...):
...
with multiprocessing.Manager() as manager:
num_query = manager.Value(int, 0)
idx_obs = manager.dict()
lock = manager.Lock()
def wrap():
nonlocal lock, count, idx_obs
for i, q in enumerate(query_images):
yield q
with lock:
if i not in idx_obs:
num_query.value += 1
idx_obs[i] = 1
output = self._generate(ref_image, wrap(), blackbox)
# num_query should now be the number of query images
assert output.shape[0] == num_query.value, \
f"Output heatmaps didn't match input images: {output.shape[0]} != {num_query.value}"
... |
I have no strong opinion on this matter, but what are the drawbacks of just making it a Sequence? At first glance, it looks like a lot of added complexity for that check if we decide to still use iterators. In the end, I'm open to whatever we think is best- thanks! |
The only obvious drawback is that we would not be able to operate on an unsized container, e.g. a stream, but considering that use-case in this context is likely over-design. I think your comment on complexity is valid. We can change to the simpler |
@@ -98,7 +94,7 @@ def generate( | |||
sal = np.clip(sal, -1, 1) | |||
|
|||
# return just HxW components |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is extraneous given we reverted back to returning NxHxW saliency maps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
xaitk_saliency/impls/gen_descriptor_sim_sal/similarity_scoring.py
Outdated
Show resolved
Hide resolved
8f89df8
to
2aed5af
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Addressed the last comment and autosquashed. Should be good to go. |
Similarity interfaces vectorized per out discussion.
One point of contention:
Iterable
. If we switched toSequence
we could check that the number of output heatmaps matches the number of input images