scikit-learn/scikit-learn — Issue #517: Shape problems building a pipeline containing PatchExtractor and MiniBatchDictionaryLearning
Author: josharian
Created: 2011-12-28 01:53:29+00:00
State: open

As part of a learning project, I was trying to adapt the [Image Denoising example](http://scikit-learn.org/stable/auto_examples/decomposition/plot_image_denoising.html#example-decomposition-plot-image-denoising-py) to use a pipeline containing `PatchExtractor` instead of manipulating the image data using `extract_patches_2d`.

The attempt can be found here: https://gist.github.com/1525765. For either value of `RESHAPE`, the code throws a `ValueError`. Expected result: No exceptions thrown (perhaps with the introduction of a `Reshape` preprocessor or a `flatten` or `shape` parameter to `PatchExtractor`).

As far as I can tell, the issue is due to shape incompatibilities between `PatchExtractor` and `MiniBatchDictionaryLearning`. `PatchExtractor` expects, and yields, a 3d tensor of images `(n_images, image_height, image_width)`. However, `MiniBatchDictionaryLearning` wants the `image_height` and `image_width` flattened: `(n_images, image_height * image_width)`. The original example code explicitly reshapes the output of `extract_patches_2d`; that's not currently easily available in the middle of a pipeline.