-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG + 1] Remove pilutil from examples #10527
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] Remove pilutil from examples #10527
Conversation
You really need to stop referring to skimage as scikit-learn here. It's just too funny. Above you propose we need a new dependency on our own library... |
Oh, you're obviously right, shame on me! |
Here are the links to the artifacts for python 2 ( The resulting differences between before and after this PR on my local machine for For Update: |
Good catch I updated the README.md for matplotlib and pushed in master (sorry you'll need to fix the conflicts). At the moment we decided to use the versions from Ubuntu 14.04 as our minimal dependencies. We could specify the numpy and scipy version in .circleci/config.yml, if you could do that in a separate PR, that would be great! For the image comparison you need to compare to the dev doc and not stable. To make it easier to compare, this is better if you post one image for this PR and the same image from the dev doc and then go on to the next image. If you could edit your previous post, that'd be great. About the image difference, I don't know. Maybe @glemaitre and @jmargeta have some idea since they work on #9062. Other comments:
|
yep this is due to the fix. I work better now :) The last example (with kmeans) shows the fix. We get cluster which are more consistent. |
I second what @glemaitre says. @jotasi, it is always good to see it being reproduced, thank you! It leads me to question whether this image is actually a good example for the technique for a image segmentation / superpixels task. In contrast to papers using similar techniques I do not find the current results particularly convincing (e.g. boundaries are jagged and do not follow the real objects' boundaries). Wouldn't an image with crisper boundaries show the potential more clearly? |
I fixed the conflicts. I think this PR should focus on removing |
Thanks for taking care of the conflicts @lesteve, and thanks everyone for the feedback. I've updated my comment above now comparing the 3 images 1-to-1 with the dev-docs. I'll add separate issues/PRs for the following things:
|
@@ -26,26 +26,30 @@ | |||
|
|||
import numpy as np | |||
import scipy as sp | |||
from scipy.ndimage.filters import gaussian_filter |
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 use scikit image:
http://scikit-image.org/docs/dev/api/skimage.filters.html#skimage.filters.gaussian
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 found that as well. The problem with it is that it changed both name and module at different times since version 0.9.3 (which is the default in Ubuntu trusty) and thus one would need multiple try:... except ImportError:...
which did not seem right for a simple example to me. (See the 3rd additional comment in opening post of the PR).
Do you agree that I then should keep SciPys version or should I change it anyway?
face = imresize(face, 0.10) / 255. | ||
# Applying a Gaussian filter for smoothing prior to down-scaling | ||
# reduces aliasing artifacts. | ||
smoothened_face = gaussian_filter(orig_face/255., sigma=(1/0.10-1)/2.) |
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.
Actually you don't need that:
http://scikit-image.org/docs/dev/api/skimage.transform.html#skimage.transform.rescale
You can turn anti_aliasing=True
to get the same effect.
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.
Actually, this is only in the current dev-version. In the docs of the current stable version (0.13.1) it is not listed, yet. One might want to keep this in mind and change in the (rather far) future, though.
(See also discussion here)
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.
Agreed. In this case rewrite it as:
smoothened_face = gaussian_filter(orig_face, sigma=4.5)
face = imresize(face, 0.10) / 255. | ||
# Applying a Gaussian filter for smoothing prior to down-scaling | ||
# reduces aliasing artifacts. | ||
smoothened_face = gaussian_filter(orig_face/255., sigma=(1/0.10-1)/2.) |
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.
see my previous comment
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.
Same here
Thanks for reviewing @glemaitre. I've explained my reasoning to your comments inline. Please let me know if you want to change this anyway (or something else). |
I see the point regarding the filtering. Let's keep scipy since that scikit-image is not released. |
except ImportError: | ||
face = sp.face(gray=True) | ||
orig_face = sp.face(gray=True) |
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.
to avoid using the / 255
, let's use make the following
from skimage import img_as_float64
orig_face = img_as_float64(sp.face(gray=True))
# Applying a Gaussian filter for smoothing prior to down-scaling | ||
# reduces aliasing artifacts. | ||
smoothened_face = gaussian_filter(orig_face/255., sigma=(1/0.10-1)/2.) | ||
rescaled_face = rescale(smoothened_face, 0.10, mode="reflect") |
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.
0.10 -> 0.1
except ImportError: | ||
face = sp.face(gray=True) | ||
orig_face = sp.face(gray=True) |
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.
See previous comments
I've implemented your suggestions. My original reasoning for |
Good point. I should really check the stable documentation :) So this PR LGTM. @jotasi could you open some issue with the points mentioned there: #10527 (comment) |
Sorry, that was not really true. Actually, the first point
is not really fixed, as the PR had to be reverted. It is not possible to simply add the minimum version of SciPy mentioned in the README ( |
I pushed some minor tweaks, I will merge when CIs are green. |
Circle is green and I checked that the examples looked fine. Merging thanks a lot @jotasi! |
Reference Issues/PRs
See discussion in #10502
What does this implement/fix?
#10502 replaced
scipy.misc.imresize
, which was deprecated by SciPy, with the local copysklearn.externals._pilutil.imresize
. As pointed out by @jnothman and agreed on in the linked discussion, this usage of a private module in an example is non-ideal. So this PR replaces it again by a combination ofscipy.ndimage.filters.gaussian_filter
andskimage.image.rescale
. The new dependency (scikit-image) is added to the README and to circleCI as pointed out by @lesteve in his instructions on how to proceed (Thank you for these, btw).Any other comments?
face
from a function to images of different resolution, I introduced new variablesorig_face
,smoothened_face
, andrescaled_face
. If preferred, I can also change it back, though.skimage.filters.gaussian
. This wrapper aroundscipy.ndimage.filters.gaussian_filter
changed names fromskimage.filter.gaussian_filter
toskimage.filters.gaussian_filter
in version 0.11 and then toskimage.filters.gaussian
in 0.12, whileskimage.filters.gaussian_filter
was deprecated and is removed in the current dev version 0.14. As the resulting convolution oftry: except ImportError:
blocks did not seem right for a minor part of a simple example, I went withscipy.ndimage.filters.gaussian_filter
instead.matplotlib/contour.py:967: UserWarning: The following kwargs were not used by contour: 'contours'
plot_face_segmentation.py
also raises:sklearn/utils/graph.py:115: FutureWarning: Conversion of the second argument of issubdtype from int to np.signedinteger is deprecated. In future, it will be treated as np.int64 == np.dtype(int).type.
Should I remove the offending parts as well?