ReshapeLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Represents a reshape layer that transforms the dimensions of input data without changing its content.
Inheritance: LayerBase<T> → ReshapeLayer<T>
Implements: IBatchAwareShapeContract
For Beginners
This layer changes how your data is organized without changing the data itself.
Think of the ReshapeLayer like reorganizing a deck of playing cards:
- If you have cards arranged in 4 rows of 13 cards (representing the 4 suits)
- You could reorganize them into 13 rows of 4 cards (representing the 13 ranks)
- The cards themselves haven’t changed, just how they’re arranged
For example, in image processing:
- You might have an image of shape [height, width, channels]
- But a particular layer might need the data as a flat vector
- A reshape layer can convert between these formats without losing information
Common use cases include:
- Flattening data (e.g., converting a 2D image to a 1D vector for a dense layer)
- Reshaping for convolutional operations (e.g., turning a vector into a 3D tensor)
- Batch dimension manipulation (e.g., splitting or combining batch items)
The key requirement is that the total number of elements stays the same - you’re just reorganizing them into a different dimensional structure.
How It Works
The ReshapeLayer rearranges the elements of the input tensor into a new shape without changing the data itself. This operation is useful for connecting layers with different shape requirements or for preparing data for specific layer types. The total number of elements must remain the same between the input and output shapes.
Constructors
| Constructor | Summary |
|---|---|
ReshapeLayer(int[] outputShape) |
Initializes a new instance of the ReshapeLayer class. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
Gets a value indicating whether this layer supports training. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank, bool isBatched) |
|
int[] GetTargetShape() |
Gets the target shape for the reshape operation. |
void ResetState() |
Resets the internal state of the reshape layer. |