-
Notifications
You must be signed in to change notification settings - Fork 253
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 bugs with passing images_background to AnchorImage #542
Fix bugs with passing images_background to AnchorImage #542
Conversation
@@ -221,13 +221,12 @@ def perturbation( | |||
segments_mask[:, anchor] = 1 | |||
|
|||
# for each sample, need to sample one of the background images if provided | |||
if self.images_background: | |||
if self.images_background is not None: |
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.
self.images_background
is either None
or np.ndarray
so we must check explicitly for None
as np.ndarray
doesn't have a working __bool__
method.
@@ -247,7 +246,7 @@ def perturbation( | |||
mask = np.zeros(segments.shape).astype(bool) | |||
for superpixel in to_perturb: | |||
mask[segments == superpixel] = True | |||
if background_idx: | |||
if background_idx is not None: |
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.
The main bug. Here background_idx
can be 0
but in the previous version it would cause it to go down this (wrong) branch and end up using fudged_image
which is not defined. The fix is to explicitly check for None
.
backgrounds = np.random.choice( | ||
range(len(self.images_background)), | ||
segments_mask.shape[0], | ||
replace=True, | ||
) | ||
segments_mask = np.hstack((segments_mask, backgrounds.reshape(-1, 1))) |
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 line appears to be completely random and just doesn't work.
Codecov Report
@@ Coverage Diff @@
## master #542 +/- ##
==========================================
+ Coverage 82.46% 82.50% +0.03%
==========================================
Files 77 77
Lines 10416 10418 +2
==========================================
+ Hits 8590 8595 +5
+ Misses 1826 1823 -3
|
Added a simple test by parametrizing |
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.
@jklaise, looks good to me!
Resolves #540.
I have manually checked that the code now works passing an array of
images_background
and that the proposed anchor is actually superimposed on these background images. I will see if an automated test can also be written relatively easily.