openfl.pipelines.stc_pipeline.SparsityTransformer
- class openfl.pipelines.stc_pipeline.SparsityTransformer(p=0.01)
Bases:
TransformerA transformer class to sparsify input data.
- Class Attributes:
p (float) – The sparsity ratio.
lossy (bool) – A flag indicating if the transformation is lossy.
Methods
Recover data array with the right shape and numerical type.
Sparsify data and pass over only non-sparsified elements by reducing the array size.
- backward(data, metadata, **kwargs)
Recover data array with the right shape and numerical type.
- Parameters:
data – an numpy array with non-zero values.
metadata – dictionary to contain information for recovering back to original data array.
- Returns:
recovered_data – an numpy array with original shape.
- forward(data, **kwargs)
Sparsify data and pass over only non-sparsified elements by reducing the array size.
- Parameters:
data – an numpy array from the model tensor_dict.
- Returns:
sparse_data – a flattened, sparse representation of the input tensor.
metadata – dictionary to store a list of meta information.