Skip to content

Conversation

varunagrawal
Copy link
Contributor

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?

@varunagrawal varunagrawal changed the title Fix for image.extract_patches_2d when # of patches requested > all possible patches Fix for image.extract_patches_2d when # of patches requested > all possible patches Nov 9, 2017
@agramfort
Copy link
Member

please add a test

@varunagrawal
Copy link
Contributor Author

Added 2 tests

Copy link
Member

@glemaitre glemaitre left a 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)

Copy link
Member

Choose a reason for hiding this comment

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

remove the blank line.

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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!

@varunagrawal varunagrawal force-pushed the sample-patches-fix branch 3 times, most recently from 4779bc9 to 19ced42 Compare November 10, 2017 00:48
@varunagrawal varunagrawal changed the title Fix for image.extract_patches_2d when # of patches requested > all possible patches [MRG] Fix for image.extract_patches_2d when # of patches requested > all possible patches Nov 10, 2017
@agramfort
Copy link
Member

just don't forget to update what's new

@varunagrawal
Copy link
Contributor Author

@agramfort can you please elaborate some more on your last comment? I seem to have lost the context in which it was made.

@agramfort
Copy link
Member

You need to document the change in the whats_new.rst page

@codecov
Copy link

codecov bot commented Nov 15, 2017

Codecov Report

Merging #10101 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10101      +/-   ##
==========================================
+ Coverage    96.1%    96.1%   +<.01%     
==========================================
  Files         337      337              
  Lines       63295    63309      +14     
==========================================
+ Hits        60828    60842      +14     
  Misses       2467     2467
Impacted Files Coverage Δ
sklearn/feature_extraction/image.py 100% <100%> (ø) ⬆️
sklearn/feature_extraction/tests/test_image.py 100% <100%> (ø) ⬆️
sklearn/linear_model/sag.py 94.36% <0%> (ø) ⬆️

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 9808810...f19b1e1. Read the comment docs.

@varunagrawal
Copy link
Contributor Author

@agramfort thank you for the info. I have updated the document.

@@ -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
Copy link
Member

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

@glemaitre
Copy link
Member

@varunagrawal could you solve the conflict and address @agramfort comments

@varunagrawal
Copy link
Contributor Author

@glemaitre I have made the requested changes. Apologies for the delay.

@agramfort
Copy link
Member

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

@varunagrawal
Copy link
Contributor Author

@agramfort sorry about that. Still getting used to the way things are done here.
Hopefully the current changes are to your satisfaction. Thank you again for your immense patience.

@glemaitre glemaitre changed the title [MRG] Fix for image.extract_patches_2d when # of patches requested > all possible patches [MRG + 1] Fix for image.extract_patches_2d when # of patches requested > all possible patches Nov 25, 2017
@glemaitre
Copy link
Member

Merging since only what's new was pending.

Thanks for your contribution.

@glemaitre glemaitre merged commit 6eb218e into scikit-learn:master Nov 25, 2017
jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
@varunagrawal varunagrawal deleted the sample-patches-fix branch February 8, 2018 04:49
@varunagrawal varunagrawal restored the sample-patches-fix branch January 11, 2019 23:29
@varunagrawal varunagrawal deleted the sample-patches-fix branch December 31, 2020 18:38
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.

image.extract_patches_2d fails if max_patches > all_patches
3 participants