-
-
Notifications
You must be signed in to change notification settings - Fork 26.2k
[MRG + 1] Fix for image.extract_patches_2d when # of patches requested > all possible patches #10101
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
[MRG + 1] Fix for image.extract_patches_2d when # of patches requested > all possible patches #10101
Conversation
image.extract_patches_2d
when # of patches requested > all possible patches
please add a test |
Added 2 tests |
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.
Couple of nitpicks. Otherwise LGTM
@@ -162,6 +162,7 @@ def test_extract_patches_max_patches(): | |||
|
|||
expected_n_patches = int(0.5 * (i_h - p_h + 1) * (i_w - p_w + 1)) | |||
patches = extract_patches_2d(face, (p_h, p_w), max_patches=0.5) | |||
|
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.
remove the blank line.
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.
Done
i_h, i_w = face.shape | ||
|
||
# Request patches of the same size as image | ||
# Should return just the single patch a.k.a. the image |
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.
I would like probably to assert the number of returned patch
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.
Understood
def test_extract_patches_less_than_max_patches(): | ||
face = downsampled_face | ||
i_h, i_w = face.shape | ||
p_h, p_w = int(3*i_h/4), int(3*i_w/4) # get patches of 3/4th the image size |
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.
Can you put some space between the mathematical operator and you don't need for any comment. This is straightforward
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.
You should also used python 3 standard without casting
p_h, p_w = 3 * i_h // 4, 3 * i_w // 4
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.
Just add at the beginning of the file
from __future__ import division
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.
Awesome! I was trying to be backwards compatible. Thank you!
4779bc9
to
19ced42
Compare
just don't forget to update what's new |
@agramfort can you please elaborate some more on your last comment? I seem to have lost the context in which it was made. |
You need to document the change in the whats_new.rst page |
Codecov Report
@@ Coverage Diff @@
## master #10101 +/- ##
==========================================
+ Coverage 96.1% 96.1% +<.01%
==========================================
Files 337 337
Lines 63295 63309 +14
==========================================
+ Hits 60828 60842 +14
Misses 2467 2467
Continue to review full report at Codecov.
|
cd24992
to
b98b42f
Compare
@agramfort thank you for the info. I have updated the document. |
doc/whats_new/v0.20.rst
Outdated
@@ -175,6 +175,14 @@ Metrics | |||
:issue:`10093` by :user:`alexryndin <alexryndin>` | |||
and :user:`Hanmin Qin <qinhanmin2014>`. | |||
|
|||
Feature Extraction | |||
|
|||
- Fixed a bug in :func:`feature_extraction.image._compute_n_patches` where an exception |
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.
you cannot point to a private function feature_extraction.image._compute_n_patches
make sure doc renders fine
@varunagrawal could you solve the conflict and address @agramfort comments |
b98b42f
to
424c447
Compare
@glemaitre I have made the requested changes. Apologies for the delay. |
424c447
to
e53ae2b
Compare
don't document changes in private function. Say what public function is impacted. btw see how doc renders: https://15080-843222-gh.circle-artifacts.com/0/home/ubuntu/scikit-learn/doc/_build/html/stable/whats_new.html |
e53ae2b
to
f19b1e1
Compare
@agramfort sorry about that. Still getting used to the way things are done here. |
Merging since only what's new was pending. Thanks for your contribution. |
…d > all possible patches (scikit-learn#10101)
Reference Issues/PRs
Fixes #10100
What does this implement/fix? Explain your changes.
This updates the
_compute_n_patches
function to check if the max_patches value >= all_patches and return the appropriate value for number of patches.Any other comments?