yobx.sklearn.feature_extraction.patch_extractor#
- yobx.sklearn.feature_extraction.patch_extractor.sklearn_patch_extractor(g: GraphBuilderExtendedProtocol, sts: Dict, outputs: List[str], estimator: PatchExtractor, X: str, name: str = 'patch_extractor') str[source]#
Converts a
sklearn.feature_extraction.image.PatchExtractorinto ONNX.The transformer extracts patches from a collection of images using a sliding window. The image dimensions must be known at conversion time (i.e. concrete, not symbolic) because the number and positions of the patches depend on them.
Only the deterministic, exhaustive extraction (
max_patches=None) is supported. Passingmax_patchesother thanNoneraisesNotImplementedError.Supported input shapes
3-D
(n_samples, image_height, image_width)– grayscale images.4-D
(n_samples, image_height, image_width, n_channels)– colour images.
Graph layout
For a 3-D input with
patch_size = (ph, pw)and an image grid of(h, w)pixels, the graph contains:For each (i, j) in [0..h-ph] × [0..w-pw]: Slice(X, [i,j], [i+ph, j+pw], axes=[1,2]) → (N, ph, pw) Unsqueeze(·, axis=1) → (N, 1, ph, pw) Concat(all unsqueezed patches, axis=1) → (N, n_p, ph, pw) Reshape(·, [-1, ph, pw]) → (N*n_p, ph, pw)- Parameters:
g – the graph builder to add nodes to
sts – shapes defined by scikit-learn (unused; present for interface consistency)
estimator – a fitted
PatchExtractoroutputs – desired output names
X – input name
name – prefix name for the added nodes
- Returns:
output name