sksfa.utils
.ReceptiveSlicer¶
-
sksfa.utils.
ReceptiveSlicer
(input_shape, field_size=(3, 3), strides=(1, 1), padding='valid', copy=True)[source]¶ Slicing part of field slicing.
This transformer takes input of shape (n_samples, width, height, channels) and slices inputs in a receptive field manner.
- Parameters
- field_sizetuple
Shape of the receptive field as a tuple of integers.
- stridestuple
Strides in each axis as tuple of integers.
- paddingstr
Either “valid” or “same”. Only “valid” is implemented as of now.
- copybool, default=True
If False, data passed to fit are overwritten and running fit(X).transform(X) will not yield the expected results, use fit_transform(X) instead.
Examples
>>> from sksfa.utils import ReceptiveSlicer >>> import numpy as np >>> >>> ones = np.ones((2, 2)) >>> # This could be an image or rebuilt output from a lower layer >>> data = np.block([[0 * ones, 1 * ones], [2 * ones, 3 * ones]])[None, ..., None] >>> >>> print(data.squeeze()) [[0. 0. 1. 1.] [0. 0. 1. 1.] [2. 2. 3. 3.] [2. 2. 3. 3.]] >>> print(f"Input shape: {data.shape}") Input shape: (1, 4, 4, 1) >>> slicer = ReceptiveSlicer(input_shape=data.shape, field_size=ones.shape, strides=(1, 1)) >>> slicer = slicer.fit(data) >>> sliced_output = slicer.transform(data) >>> print(f"Output shape: {sliced_output.shape}") Output shape: (9, 4) >>> for idx, field_sample in enumerate(sliced_output): print(f"Output sample {idx}: {field_sample.squeeze()}") Output sample 0: [0. 0. 0. 0.] Output sample 1: [0. 1. 0. 1.] Output sample 2: [1. 1. 1. 1.] Output sample 3: [0. 0. 2. 2.] Output sample 4: [0. 1. 2. 3.] Output sample 5: [1. 1. 3. 3.] Output sample 6: [2. 2. 2. 2.] Output sample 7: [2. 3. 2. 3.] Output sample 8: [3. 3. 3. 3.]