From 5cb4bda50c90d6f41007be740eab9a09c3823a89 Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Tue, 18 Dec 2018 11:38:50 -0500 Subject: [PATCH 01/18] Finalizes fix for #12202 from abandonned PR by @parul-l --- sklearn/feature_extraction/image.py | 41 ++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index b6e68537c091c..f6fe284e132f1 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -51,7 +51,7 @@ def _make_edges_3d(n_x, n_y, n_z=1): def _compute_gradient_3d(edges, img): - n_x, n_y, n_z = img.shape + _, n_y, n_z = img.shape gradient = np.abs(img[edges[0] // (n_y * n_z), (edges[0] % (n_y * n_z)) // n_z, (edges[0] % (n_y * n_z)) % n_z] - @@ -499,6 +499,45 @@ def transform(self, X): `n_patches` is either `n_samples * max_patches` or the total number of patches that can be extracted. + Example + -------- + from sklearn.datasets import load_sample_images + from sklearn.feature_extraction import image + + # Use the array data from the second image in this dataset: + X = load_sample_images().images[1] + print(f'Image shape: {X.shape}') + + pe = image.PatchExtractor(patch_size=(2, 2)) + pe_fit = pe.fit(X) + pe_trans = pe.transform(X) + + print(f'Patches shape: {pe_trans.shape}') + print(f'Shapes arrays:\n{pe_trans}') + + output: + Image shape: (427, 640, 3) + Patches shape: (545706, 2, 2) + Shapes arrays: + [[[ 2. 19.] + [ 3. 18.]] + + [[19. 13.] + [18. 13.]] + + [[ 3. 18.] + [ 7. 20.]] + + ... + + [[46. 28.] + [45. 28.]] + + [[ 8. 45.] + [ 9. 43.]] + + [[45. 28.] + [43. 27.]]] """ self.random_state = check_random_state(self.random_state) n_images, i_h, i_w = X.shape[:3] From a39baedb9c9b80282886c038263f69370574674e Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Tue, 18 Dec 2018 11:43:01 -0500 Subject: [PATCH 02/18] Completes 12202 fix abandoned by @parul-l --- sklearn/feature_extraction/image.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index f6fe284e132f1..9569734603a8d 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -538,6 +538,7 @@ def transform(self, X): [[45. 28.] [43. 27.]]] + """ self.random_state = check_random_state(self.random_state) n_images, i_h, i_w = X.shape[:3] From a5b73bbf4be75d0dd243031fa25202e7cbb7658e Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Tue, 18 Dec 2018 11:51:50 -0500 Subject: [PATCH 03/18] Completes 12202 fix abandoned by @parul-l --- sklearn/feature_extraction/image.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 9569734603a8d..e33acf6ed48e8 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -537,8 +537,7 @@ def transform(self, X): [ 9. 43.]] [[45. 28.] - [43. 27.]]] - + [43. 27.]]] """ self.random_state = check_random_state(self.random_state) n_images, i_h, i_w = X.shape[:3] From e9f95948fb399b68ad4152dc5b5b7d5ea6366f04 Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Tue, 18 Dec 2018 13:03:47 -0500 Subject: [PATCH 04/18] Extends 12202 fix over feature_extraction/image.py --- sklearn/feature_extraction/image.py | 138 ++++++++++++++++------------ 1 file changed, 79 insertions(+), 59 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index e33acf6ed48e8..7ea993d8dabdc 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -339,25 +339,45 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): Examples -------- - >>> from sklearn.feature_extraction import image - >>> one_image = np.arange(16).reshape((4, 4)) - >>> one_image - array([[ 0, 1, 2, 3], - [ 4, 5, 6, 7], - [ 8, 9, 10, 11], - [12, 13, 14, 15]]) - >>> patches = image.extract_patches_2d(one_image, (2, 2)) - >>> print(patches.shape) - (9, 2, 2) - >>> patches[0] - array([[0, 1], - [4, 5]]) - >>> patches[1] - array([[1, 2], - [5, 6]]) - >>> patches[8] - array([[10, 11], - [14, 15]]) + from sklearn.datasets import load_sample_images + from sklearn.feature_extraction import image + + # Use the array data from the first image in this dataset: + one_image = load_sample_images().images[0] + print(f'Image shape: {one_image.shape}') + + patches = image.extract_patches_2d(one_image, (2, 2)) + + print(f'Patches shape: {patches.shape}') + + print(f'\nPatches 0:\n{patches[0]}') + print(f'\nPatches 1:\n{patches[1]}') + print(f'\nPatches 800:\n{patches[800]}') + + # output: + Image shape: (427, 640, 3) + Patches shape: (272214, 2, 2, 3) + + Patches 0: + [[[174 201 231] + [174 201 231]] + + [[172 199 229] + [173 200 230]]] + + Patches 1: + [[[174 201 231] + [174 201 231]] + + [[173 200 230] + [173 200 230]]] + + Patches 800: + [[[187 214 243] + [188 215 244]] + + [[187 214 243] + [188 215 244]]] """ i_h, i_w = image.shape[:2] p_h, p_w = patch_size @@ -461,6 +481,46 @@ class PatchExtractor(BaseEstimator): If None, the random number generator is the RandomState instance used by `np.random`. + Examples + -------- + from sklearn.datasets import load_sample_images + from sklearn.feature_extraction import image + + # Use the array data from the second image in this dataset: + X = load_sample_images().images[1] + print(f'Image shape: {X.shape}') + + pe = image.PatchExtractor(patch_size=(2, 2)) + pe_fit = pe.fit(X) + pe_trans = pe.transform(X) + + print(f'Patches shape: {pe_trans.shape}') + print(f'Shapes arrays:\n{pe_trans}') + + # output: + + Image shape: (427, 640, 3) + Patches shape: (545706, 2, 2) + Shapes arrays: + [[[ 2. 19.] + [ 3. 18.]] + + [[19. 13.] + [18. 13.]] + + [[ 3. 18.] + [ 7. 20.]] + + ... + + [[46. 28.] + [45. 28.]] + + [[ 8. 45.] + [ 9. 43.]] + + [[45. 28.] + [43. 27.]]] """ def __init__(self, patch_size=None, max_patches=None, random_state=None): self.patch_size = patch_size @@ -498,46 +558,6 @@ def transform(self, X): The collection of patches extracted from the images, where `n_patches` is either `n_samples * max_patches` or the total number of patches that can be extracted. - - Example - -------- - from sklearn.datasets import load_sample_images - from sklearn.feature_extraction import image - - # Use the array data from the second image in this dataset: - X = load_sample_images().images[1] - print(f'Image shape: {X.shape}') - - pe = image.PatchExtractor(patch_size=(2, 2)) - pe_fit = pe.fit(X) - pe_trans = pe.transform(X) - - print(f'Patches shape: {pe_trans.shape}') - print(f'Shapes arrays:\n{pe_trans}') - - output: - Image shape: (427, 640, 3) - Patches shape: (545706, 2, 2) - Shapes arrays: - [[[ 2. 19.] - [ 3. 18.]] - - [[19. 13.] - [18. 13.]] - - [[ 3. 18.] - [ 7. 20.]] - - ... - - [[46. 28.] - [45. 28.]] - - [[ 8. 45.] - [ 9. 43.]] - - [[45. 28.] - [43. 27.]]] """ self.random_state = check_random_state(self.random_state) n_images, i_h, i_w = X.shape[:3] From 35da14ab5fd279c1833c6ff7e6863ad9f4e4a81c Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Tue, 18 Dec 2018 13:19:26 -0500 Subject: [PATCH 05/18] Closes #12202; white space removal --- sklearn/feature_extraction/image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 7ea993d8dabdc..5acececcd987c 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -520,7 +520,7 @@ class PatchExtractor(BaseEstimator): [ 9. 43.]] [[45. 28.] - [43. 27.]]] + [43. 27.]]] """ def __init__(self, patch_size=None, max_patches=None, random_state=None): self.patch_size = patch_size From 0730c7a3927786b6d4ad572736ddba9e8fdc1373 Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Tue, 18 Dec 2018 13:56:54 -0500 Subject: [PATCH 06/18] Closes #12202; white space removal2 --- sklearn/feature_extraction/image.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 5acececcd987c..24ca0b31bf68c 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -440,7 +440,6 @@ def reconstruct_from_patches_2d(patches, image_size): ------- image : array, shape = image_size the reconstructed image - """ i_h, i_w = image_size[:2] p_h, p_w = patches.shape[1:3] @@ -496,9 +495,8 @@ class PatchExtractor(BaseEstimator): print(f'Patches shape: {pe_trans.shape}') print(f'Shapes arrays:\n{pe_trans}') - - # output: + # output: Image shape: (427, 640, 3) Patches shape: (545706, 2, 2) Shapes arrays: From f81beda87718223dca2f2554d685279e01d3c107 Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Tue, 18 Dec 2018 14:22:35 -0500 Subject: [PATCH 07/18] Closes #12202; 3.5 compliance; added >>> in docstring code. --- sklearn/feature_extraction/image.py | 75 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 24ca0b31bf68c..dcb6a0a083dba 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -338,21 +338,20 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): Examples -------- + >>> from sklearn.datasets import load_sample_images + >>> from sklearn.feature_extraction import image - from sklearn.datasets import load_sample_images - from sklearn.feature_extraction import image + >>> # Use the array data from the first image in this dataset: + >>> one_image = load_sample_images().images[0] - # Use the array data from the first image in this dataset: - one_image = load_sample_images().images[0] - print(f'Image shape: {one_image.shape}') + >>> print('Image shape: {}'.format(one_image.shape)) - patches = image.extract_patches_2d(one_image, (2, 2)) + >>> patches = image.extract_patches_2d(one_image, (2, 2)) - print(f'Patches shape: {patches.shape}') - - print(f'\nPatches 0:\n{patches[0]}') - print(f'\nPatches 1:\n{patches[1]}') - print(f'\nPatches 800:\n{patches[800]}') + >>> print('Patches shape: {}'.format(patches.shape)) + >>> print('\nPatches 0:\n{}'.format(patches[0])) + >>> print('\nPatches 1:\n{}'.format(patches[1])) + >>> print('\nPatches 800:\n{}'.format(patches[800])) # output: Image shape: (427, 640, 3) @@ -482,43 +481,43 @@ class PatchExtractor(BaseEstimator): Examples -------- - from sklearn.datasets import load_sample_images - from sklearn.feature_extraction import image + >>> from sklearn.datasets import load_sample_images + >>> from sklearn.feature_extraction import image - # Use the array data from the second image in this dataset: - X = load_sample_images().images[1] - print(f'Image shape: {X.shape}') + >>> # Use the array data from the second image in this dataset: + >>> X = load_sample_images().images[1] + >>> print(f'Image shape: {X.shape}') - pe = image.PatchExtractor(patch_size=(2, 2)) - pe_fit = pe.fit(X) - pe_trans = pe.transform(X) + >>> pe = image.PatchExtractor(patch_size=(2, 2)) + >>> pe_fit = pe.fit(X) + >>> pe_trans = pe.transform(X) - print(f'Patches shape: {pe_trans.shape}') - print(f'Shapes arrays:\n{pe_trans}') + >>> print('Patches shape: {}'.format(pe_trans.shape)) + >>> print('Shapes arrays:\n{}'.format(pe_trans)) - # output: - Image shape: (427, 640, 3) - Patches shape: (545706, 2, 2) - Shapes arrays: - [[[ 2. 19.] - [ 3. 18.]] + # output: + Image shape: (427, 640, 3) + Patches shape: (545706, 2, 2) + Shapes arrays: + [[[ 2. 19.] + [ 3. 18.]] - [[19. 13.] - [18. 13.]] + [[19. 13.] + [18. 13.]] - [[ 3. 18.] - [ 7. 20.]] + [[ 3. 18.] + [ 7. 20.]] - ... + ... - [[46. 28.] - [45. 28.]] + [[46. 28.] + [45. 28.]] - [[ 8. 45.] - [ 9. 43.]] + [[ 8. 45.] + [ 9. 43.]] - [[45. 28.] - [43. 27.]]] + [[45. 28.] + [43. 27.]]] """ def __init__(self, patch_size=None, max_patches=None, random_state=None): self.patch_size = patch_size From 294ce613309f86ea6db93fd1aef2b18d10c4681e Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Tue, 18 Dec 2018 15:45:13 -0500 Subject: [PATCH 08/18] Closes #12202; indentation discrep. --- sklearn/feature_extraction/image.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index dcb6a0a083dba..b8daeeca1794d 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -331,10 +331,10 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): Returns ------- patches : array, shape = (n_patches, patch_height, patch_width) or - (n_patches, patch_height, patch_width, n_channels) - The collection of patches extracted from the image, where `n_patches` - is either `max_patches` or the total number of patches that can be - extracted. + (n_patches, patch_height, patch_width, n_channels) + The collection of patches extracted from the image, where `n_patches` + is either `max_patches` or the total number of patches that can be + extracted. Examples -------- From 4f123302fdcf3ffa0c5ffc6bc2eb1fefc6073862 Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Tue, 18 Dec 2018 17:06:32 -0500 Subject: [PATCH 09/18] Closes #12202; indentation discrep.2 --- sklearn/feature_extraction/image.py | 70 ++++++++++++++--------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index b8daeeca1794d..b54c2f37aabab 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -353,30 +353,30 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): >>> print('\nPatches 1:\n{}'.format(patches[1])) >>> print('\nPatches 800:\n{}'.format(patches[800])) - # output: - Image shape: (427, 640, 3) - Patches shape: (272214, 2, 2, 3) + >>> # output: + Image shape: (427, 640, 3) + Patches shape: (272214, 2, 2, 3) - Patches 0: - [[[174 201 231] - [174 201 231]] + Patches 0: + [[[174 201 231] + [174 201 231]] - [[172 199 229] - [173 200 230]]] + [[172 199 229] + [173 200 230]]] - Patches 1: - [[[174 201 231] - [174 201 231]] + Patches 1: + [[[174 201 231] + [174 201 231]] - [[173 200 230] - [173 200 230]]] + [[173 200 230] + [173 200 230]]] - Patches 800: - [[[187 214 243] - [188 215 244]] + Patches 800: + [[[187 214 243] + [188 215 244]] - [[187 214 243] - [188 215 244]]] + [[187 214 243] + [188 215 244]]] """ i_h, i_w = image.shape[:2] p_h, p_w = patch_size @@ -495,29 +495,29 @@ class PatchExtractor(BaseEstimator): >>> print('Patches shape: {}'.format(pe_trans.shape)) >>> print('Shapes arrays:\n{}'.format(pe_trans)) - # output: - Image shape: (427, 640, 3) - Patches shape: (545706, 2, 2) - Shapes arrays: - [[[ 2. 19.] - [ 3. 18.]] + >>> # output: + Image shape: (427, 640, 3) + Patches shape: (545706, 2, 2) + Shapes arrays: + [[[ 2. 19.] + [ 3. 18.]] - [[19. 13.] - [18. 13.]] + [[19. 13.] + [18. 13.]] - [[ 3. 18.] - [ 7. 20.]] + [[ 3. 18.] + [ 7. 20.]] - ... + ... - [[46. 28.] - [45. 28.]] + [[46. 28.] + [45. 28.]] - [[ 8. 45.] - [ 9. 43.]] + [[ 8. 45.] + [ 9. 43.]] - [[45. 28.] - [43. 27.]]] + [[45. 28.] + [43. 27.]]] """ def __init__(self, patch_size=None, max_patches=None, random_state=None): self.patch_size = patch_size From 2a8d782d7e97969c7be7df61d945b80bda1b0809 Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Fri, 21 Dec 2018 13:24:33 -0500 Subject: [PATCH 10/18] Example output formating; @jnotham --- sklearn/feature_extraction/image.py | 57 +++++++++++++---------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index b54c2f37aabab..b14489e5224a0 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -345,25 +345,15 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): >>> one_image = load_sample_images().images[0] >>> print('Image shape: {}'.format(one_image.shape)) + Image shape: (427, 640, 3) >>> patches = image.extract_patches_2d(one_image, (2, 2)) >>> print('Patches shape: {}'.format(patches.shape)) - >>> print('\nPatches 0:\n{}'.format(patches[0])) - >>> print('\nPatches 1:\n{}'.format(patches[1])) - >>> print('\nPatches 800:\n{}'.format(patches[800])) - - >>> # output: - Image shape: (427, 640, 3) - Patches shape: (272214, 2, 2, 3) - - Patches 0: - [[[174 201 231] - [174 201 231]] - - [[172 199 229] - [173 200 230]]] + Patches shape: (272214, 2, 2, 3) + >>> # Here are just two of these patches: + >>> print('\nPatches 1:\n{}'.format(patches[1])) Patches 1: [[[174 201 231] [174 201 231]] @@ -371,6 +361,7 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): [[173 200 230] [173 200 230]]] + >>> print('\nPatches 800:\n{}'.format(patches[800])) Patches 800: [[[187 214 243] [188 215 244]] @@ -378,6 +369,7 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): [[187 214 243] [188 215 244]]] """ + i_h, i_w = image.shape[:2] p_h, p_w = patch_size @@ -486,39 +478,40 @@ class PatchExtractor(BaseEstimator): >>> # Use the array data from the second image in this dataset: >>> X = load_sample_images().images[1] + >>> print(f'Image shape: {X.shape}') + Image shape: (427, 640, 3) >>> pe = image.PatchExtractor(patch_size=(2, 2)) >>> pe_fit = pe.fit(X) >>> pe_trans = pe.transform(X) >>> print('Patches shape: {}'.format(pe_trans.shape)) - >>> print('Shapes arrays:\n{}'.format(pe_trans)) + Patches shape: (545706, 2, 2) - >>> # output: - Image shape: (427, 640, 3) - Patches shape: (545706, 2, 2) - Shapes arrays: - [[[ 2. 19.] - [ 3. 18.]] + >>> print('Shapes arrays:\n{}'.format(pe_trans)) + Shapes arrays: + [[[ 2. 19.] + [ 3. 18.]] - [[19. 13.] - [18. 13.]] + [[19. 13.] + [18. 13.]] - [[ 3. 18.] - [ 7. 20.]] + [[ 3. 18.] + [ 7. 20.]] - ... + ... - [[46. 28.] - [45. 28.]] + [[46. 28.] + [45. 28.]] - [[ 8. 45.] - [ 9. 43.]] + [[ 8. 45.] + [ 9. 43.]] - [[45. 28.] - [43. 27.]]] + [[45. 28.] + [43. 27.]]] """ + def __init__(self, patch_size=None, max_patches=None, random_state=None): self.patch_size = patch_size self.max_patches = max_patches From d14b3b6fea16648f40bca6d9971e5cc5f0c65426 Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Fri, 21 Dec 2018 13:53:41 -0500 Subject: [PATCH 11/18] Example output formating; forgot flake8 --- sklearn/feature_extraction/image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index b14489e5224a0..d019c781e9f81 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -369,7 +369,7 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): [[187 214 243] [188 215 244]]] """ - + i_h, i_w = image.shape[:2] p_h, p_w = patch_size From 3f8b0b1c9cd12c0eb966c8fe46833553ca13f67d Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Sat, 5 Jan 2019 12:40:47 -0500 Subject: [PATCH 12/18] Closes #12202; Removed excessive indentation in docstring (#wimlds) --- sklearn/feature_extraction/image.py | 44 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index d019c781e9f81..46587a95b05e4 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -338,36 +338,36 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): Examples -------- - >>> from sklearn.datasets import load_sample_images - >>> from sklearn.feature_extraction import image + >>> from sklearn.datasets import load_sample_images + >>> from sklearn.feature_extraction import image - >>> # Use the array data from the first image in this dataset: - >>> one_image = load_sample_images().images[0] + >>> # Use the array data from the first image in this dataset: + >>> one_image = load_sample_images().images[0] - >>> print('Image shape: {}'.format(one_image.shape)) - Image shape: (427, 640, 3) + >>> print('Image shape: {}'.format(one_image.shape)) + Image shape: (427, 640, 3) - >>> patches = image.extract_patches_2d(one_image, (2, 2)) + >>> patches = image.extract_patches_2d(one_image, (2, 2)) - >>> print('Patches shape: {}'.format(patches.shape)) - Patches shape: (272214, 2, 2, 3) + >>> print('Patches shape: {}'.format(patches.shape)) + Patches shape: (272214, 2, 2, 3) - >>> # Here are just two of these patches: - >>> print('\nPatches 1:\n{}'.format(patches[1])) - Patches 1: - [[[174 201 231] - [174 201 231]] + >>> # Here are just two of these patches: + >>> print('\nPatches 1:\n{}'.format(patches[1])) + Patches 1: + [[[174 201 231] + [174 201 231]] - [[173 200 230] - [173 200 230]]] + [[173 200 230] + [173 200 230]]] - >>> print('\nPatches 800:\n{}'.format(patches[800])) - Patches 800: - [[[187 214 243] - [188 215 244]] + >>> print('\nPatches 800:\n{}'.format(patches[800])) + Patches 800: + [[[187 214 243] + [188 215 244]] - [[187 214 243] - [188 215 244]]] + [[187 214 243] + [188 215 244]]] """ i_h, i_w = image.shape[:2] From 236dafb6104d94d24ef027f72333f5f45a7e4e9d Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Sat, 5 Jan 2019 15:32:47 -0500 Subject: [PATCH 13/18] Closes #12202; Fixed inconsistent indentation in docstring (#wimlds) --- sklearn/feature_extraction/image.py | 40 ++++++++--------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 251e8ecb28804..73707a8d11a8f 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -338,11 +338,7 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): Examples -------- -<<<<<<< HEAD >>> from sklearn.datasets import load_sample_images -======= - >>> import numpy as np ->>>>>>> 301c18e31038d83e531a33b83b885f01df6e5c63 >>> from sklearn.feature_extraction import image >>> # Use the array data from the first image in this dataset: @@ -352,40 +348,26 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): Image shape: (427, 640, 3) >>> patches = image.extract_patches_2d(one_image, (2, 2)) -<<<<<<< HEAD >>> print('Patches shape: {}'.format(patches.shape)) Patches shape: (272214, 2, 2, 3) >>> # Here are just two of these patches: >>> print('\nPatches 1:\n{}'.format(patches[1])) - Patches 1: - [[[174 201 231] - [174 201 231]] + Patches 1: + [[[174 201 231] + [174 201 231]] - [[173 200 230] - [173 200 230]]] + [[173 200 230] + [173 200 230]]] >>> print('\nPatches 800:\n{}'.format(patches[800])) - Patches 800: - [[[187 214 243] - [188 215 244]] - - [[187 214 243] - [188 215 244]]] -======= - >>> patches.shape - (9, 2, 2) - >>> patches[0] - array([[0, 1], - [4, 5]]) - >>> patches[1] - array([[1, 2], - [5, 6]]) - >>> patches[8] - array([[10, 11], - [14, 15]]) ->>>>>>> 301c18e31038d83e531a33b83b885f01df6e5c63 + Patches 800: + [[[187 214 243] + [188 215 244]] + + [[187 214 243] + [188 215 244]]] """ i_h, i_w = image.shape[:2] From 0bbbea4ad2c6ab029be65efa22d99527f4838dae Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Wed, 9 Jan 2019 11:43:09 -0500 Subject: [PATCH 14/18] Closes #12202 (#wimlds); intentation, v3.5 compliance --- sklearn/feature_extraction/image.py | 53 +++++++++++++++-------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 73707a8d11a8f..52c3e859e0b2a 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -432,6 +432,7 @@ def reconstruct_from_patches_2d(patches, image_size): image : array, shape = image_size the reconstructed image """ + i_h, i_w = image_size[:2] p_h, p_w = patches.shape[1:3] img = np.zeros(image_size) @@ -473,43 +474,43 @@ class PatchExtractor(BaseEstimator): Examples -------- - >>> from sklearn.datasets import load_sample_images - >>> from sklearn.feature_extraction import image + >>> from sklearn.datasets import load_sample_images + >>> from sklearn.feature_extraction import image - >>> # Use the array data from the second image in this dataset: - >>> X = load_sample_images().images[1] + >>> # Use the array data from the second image in this dataset: + >>> X = load_sample_images().images[1] - >>> print(f'Image shape: {X.shape}') - Image shape: (427, 640, 3) + >>> print('Image shape: {}'.format(X.shape)) + Image shape: (427, 640, 3) - >>> pe = image.PatchExtractor(patch_size=(2, 2)) - >>> pe_fit = pe.fit(X) - >>> pe_trans = pe.transform(X) + >>> pe = image.PatchExtractor(patch_size=(2, 2)) + >>> pe_fit = pe.fit(X) + >>> pe_trans = pe.transform(X) - >>> print('Patches shape: {}'.format(pe_trans.shape)) - Patches shape: (545706, 2, 2) + >>> print('Patches shape: {}'.format(pe_trans.shape)) + Patches shape: (545706, 2, 2) - >>> print('Shapes arrays:\n{}'.format(pe_trans)) - Shapes arrays: - [[[ 2. 19.] - [ 3. 18.]] + >>> print('Shapes arrays:\n{}'.format(pe_trans)) + Shapes arrays: + [[[ 2. 19.] + [ 3. 18.]] - [[19. 13.] - [18. 13.]] + [[19. 13.] + [18. 13.]] - [[ 3. 18.] - [ 7. 20.]] + [[ 3. 18.] + [ 7. 20.]] - ... + ... - [[46. 28.] - [45. 28.]] + [[46. 28.] + [45. 28.]] - [[ 8. 45.] - [ 9. 43.]] + [[ 8. 45.] + [ 9. 43.]] - [[45. 28.] - [43. 27.]]] + [[45. 28.] + [43. 27.]]] """ def __init__(self, patch_size=None, max_patches=None, random_state=None): From f173bf649cd8b0555ba07b851ab62172aaaf17fe Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Wed, 16 Jan 2019 11:50:25 -0500 Subject: [PATCH 15/18] Closes #12202 (#wimlds); Output format issue solved with addition of # doctest: +NORMALIZE_WHITESPACE +DONT_ACCEPT_BLANKLINE +ELLIPSIS for print statements. --- sklearn/feature_extraction/image.py | 58 +++++++---------------------- 1 file changed, 13 insertions(+), 45 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 52c3e859e0b2a..98892fa93c584 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -340,34 +340,27 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): -------- >>> from sklearn.datasets import load_sample_images >>> from sklearn.feature_extraction import image - + >>> >>> # Use the array data from the first image in this dataset: >>> one_image = load_sample_images().images[0] - >>> print('Image shape: {}'.format(one_image.shape)) Image shape: (427, 640, 3) - + >>> >>> patches = image.extract_patches_2d(one_image, (2, 2)) - >>> print('Patches shape: {}'.format(patches.shape)) Patches shape: (272214, 2, 2, 3) - + >>> >>> # Here are just two of these patches: - >>> print('\nPatches 1:\n{}'.format(patches[1])) - Patches 1: + >>> print(patches[1]) # doctest: +NORMALIZE_WHITESPACE +DONT_ACCEPT_BLANKLINE [[[174 201 231] - [174 201 231]] - - [[173 200 230] - [173 200 230]]] - - >>> print('\nPatches 800:\n{}'.format(patches[800])) - Patches 800: + [174 201 231]] + [[173 200 230] + [173 200 230]]] + >>> print(patches[800]) # doctest: +NORMALIZE_WHITESPACE +DONT_ACCEPT_BLANKLINE [[[187 214 243] - [188 215 244]] - - [[187 214 243] - [188 215 244]]] + [188 215 244]] + [[187 214 243] + [188 215 244]]] """ i_h, i_w = image.shape[:2] @@ -432,7 +425,6 @@ def reconstruct_from_patches_2d(patches, image_size): image : array, shape = image_size the reconstructed image """ - i_h, i_w = image_size[:2] p_h, p_w = patches.shape[1:3] img = np.zeros(image_size) @@ -476,41 +468,17 @@ class PatchExtractor(BaseEstimator): -------- >>> from sklearn.datasets import load_sample_images >>> from sklearn.feature_extraction import image - + >>> >>> # Use the array data from the second image in this dataset: >>> X = load_sample_images().images[1] - >>> print('Image shape: {}'.format(X.shape)) Image shape: (427, 640, 3) - + >>> >>> pe = image.PatchExtractor(patch_size=(2, 2)) >>> pe_fit = pe.fit(X) >>> pe_trans = pe.transform(X) - >>> print('Patches shape: {}'.format(pe_trans.shape)) Patches shape: (545706, 2, 2) - - >>> print('Shapes arrays:\n{}'.format(pe_trans)) - Shapes arrays: - [[[ 2. 19.] - [ 3. 18.]] - - [[19. 13.] - [18. 13.]] - - [[ 3. 18.] - [ 7. 20.]] - - ... - - [[46. 28.] - [45. 28.]] - - [[ 8. 45.] - [ 9. 43.]] - - [[45. 28.] - [43. 27.]]] """ def __init__(self, patch_size=None, max_patches=None, random_state=None): From aeae3b0b14358cd670e2ce167aabf3f0f395ee4a Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Wed, 16 Jan 2019 15:14:02 -0500 Subject: [PATCH 16/18] Closes #12202 (#wimlds); Output format issue solved with addition of # doctest: +NORMALIZE_WHITESPACE +DONT_ACCEPT_BLANKLINE for print statements. --- sklearn/feature_extraction/image.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 98892fa93c584..8d4ee26d7f392 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -351,18 +351,19 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): Patches shape: (272214, 2, 2, 3) >>> >>> # Here are just two of these patches: - >>> print(patches[1]) # doctest: +NORMALIZE_WHITESPACE +DONT_ACCEPT_BLANKLINE + >>> print(patches[1]) # doctest: +NORMALIZE_WHITESPACE \ + +DONT_ACCEPT_BLANKLINE [[[174 201 231] [174 201 231]] [[173 200 230] [173 200 230]]] - >>> print(patches[800]) # doctest: +NORMALIZE_WHITESPACE +DONT_ACCEPT_BLANKLINE + >>> print(patches[800])# doctest: +NORMALIZE_WHITESPACE \ + +DONT_ACCEPT_BLANKLINE [[[187 214 243] [188 215 244]] [[187 214 243] [188 215 244]]] """ - i_h, i_w = image.shape[:2] p_h, p_w = patch_size From e38bca92f5f12cdb98e8cb2550ad40c4673f5fd9 Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Fri, 25 Jan 2019 15:22:37 -0500 Subject: [PATCH 17/18] Closes #12202 (#wimlds); Testing doctest direc.: removed DONT_ACCEPT_BLANKLINE (@jnothmam, @reshamas) --- sklearn/feature_extraction/image.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 8d4ee26d7f392..4e6ee8e258d84 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -351,14 +351,12 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): Patches shape: (272214, 2, 2, 3) >>> >>> # Here are just two of these patches: - >>> print(patches[1]) # doctest: +NORMALIZE_WHITESPACE \ - +DONT_ACCEPT_BLANKLINE + >>> print(patches[1]) # doctest: +NORMALIZE_WHITESPACE [[[174 201 231] [174 201 231]] [[173 200 230] [173 200 230]]] - >>> print(patches[800])# doctest: +NORMALIZE_WHITESPACE \ - +DONT_ACCEPT_BLANKLINE + >>> print(patches[800])# doctest: +NORMALIZE_WHITESPACE [[[187 214 243] [188 215 244]] [[187 214 243] From f9352abd78e17739a6e94f12f3242e206d03d86e Mon Sep 17 00:00:00 2001 From: Cat Chenal Date: Wed, 30 Jan 2019 13:30:41 -0500 Subject: [PATCH 18/18] Closes #12202 (#wimlds); Removed blank lines in doctest example. --- sklearn/feature_extraction/image.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sklearn/feature_extraction/image.py b/sklearn/feature_extraction/image.py index 4e6ee8e258d84..7bb9e6a14effc 100644 --- a/sklearn/feature_extraction/image.py +++ b/sklearn/feature_extraction/image.py @@ -340,16 +340,13 @@ def extract_patches_2d(image, patch_size, max_patches=None, random_state=None): -------- >>> from sklearn.datasets import load_sample_images >>> from sklearn.feature_extraction import image - >>> >>> # Use the array data from the first image in this dataset: >>> one_image = load_sample_images().images[0] >>> print('Image shape: {}'.format(one_image.shape)) Image shape: (427, 640, 3) - >>> >>> patches = image.extract_patches_2d(one_image, (2, 2)) >>> print('Patches shape: {}'.format(patches.shape)) Patches shape: (272214, 2, 2, 3) - >>> >>> # Here are just two of these patches: >>> print(patches[1]) # doctest: +NORMALIZE_WHITESPACE [[[174 201 231] @@ -467,12 +464,10 @@ class PatchExtractor(BaseEstimator): -------- >>> from sklearn.datasets import load_sample_images >>> from sklearn.feature_extraction import image - >>> >>> # Use the array data from the second image in this dataset: >>> X = load_sample_images().images[1] >>> print('Image shape: {}'.format(X.shape)) Image shape: (427, 640, 3) - >>> >>> pe = image.PatchExtractor(patch_size=(2, 2)) >>> pe_fit = pe.fit(X) >>> pe_trans = pe.transform(X)