IPruningMask<T>
Interfaces · AiDotNet.Interfaces
Represents a binary mask for pruning weights in a neural network layer.
Known implementations: PruningMask<T>
For Beginners
Think of a pruning mask as a stencil or template.
Imagine you’re painting a picture and want to cover certain areas:
- The mask has holes (1s) where paint should go through (weights to keep)
- The mask is solid (0s) where paint should be blocked (weights to prune/remove)
In neural networks:
- A pruning mask helps you selectively remove less important connections
- This makes your model smaller and faster without losing too much accuracy
- The mask can be applied to weight matrices to zero out pruned weights
How It Works
A pruning mask is a binary matrix that determines which weights to keep (1) and which to remove (0) during model compression. It enables selective removal of network parameters while maintaining the ability to restore the network structure.
Properties
| Property | Summary |
|---|---|
SparsityPattern Pattern { get; } |
Gets the sparsity pattern type. |
int[] Shape { get; } |
Gets the mask dimensions matching the weight matrix shape. |
Methods
| Method | Summary |
|---|---|
IPruningMask<T> CombineWith(IPruningMask<T> otherMask) |
Combines this mask with another mask (logical AND). |
Matrix<T> Apply(Matrix<T> weights) |
Applies the mask to a weight tensor (for convolutional layers). |
T[] GetMaskData() |
Gets the raw mask data as a flat array. |
Tensor<T> Apply(Tensor<T> weights) |
Applies the mask to a weight tensor (for convolutional layers). |
Vector<T> Apply(Vector<T> weights) |
Applies the mask to a weight tensor (for convolutional layers). |
double GetSparsity() |
Gets the sparsity ratio (proportion of zeros). |
int[] GetKeptIndices() |
Gets indices of non-zero (kept) elements. |
int[] GetPrunedIndices() |
Gets indices of zero (pruned) elements. |
void UpdateMask(Array keepIndices) |
Updates the mask with new N-D keep/prune decisions. |
void UpdateMask(bool[] keepIndices) |
Updates the mask with new N-D keep/prune decisions. |
void UpdateMask(bool[] keepIndices) |
Updates the mask with new N-D keep/prune decisions. |