torch.nn.MaxUnpool1d
class MaxUnpool1d extends Modulenew MaxUnpool1d(kernel_size: number, options?: MaxUnpool1dOptions)
- readonly
kernel_size(number) - readonly
stride(number) - readonly
padding(number)
1D max unpooling: reconstructs input-like tensor from MaxPool1d output and indices.
Inverse operation of MaxPool1d. Requires indices from MaxPool1d (return_indices=true). Places pooled values back at maximum positions; other positions get zero. Useful for:
- Deconvolution networks (upsampling path)
- Autoencoders with pooling/unpooling symmetry
- Visualization of which regions contributed to pooled output
- Reconstruction from compressed pooled representations
- Feature map upsampling in U-Net style architectures
How it works: MaxPool1d saves indices of where each max value came from. MaxUnpool1d places those values back at the original positions, zeroing everything else. Partial inverse since non-max values are lost.
Usage pattern:
- Create MaxPool1d with return_indices=true
- In forward pass, get [pooled_output, indices]
- In backward/unpooling, call unpool(pooled_output, indices)
- Result has same shape as original input to MaxPool1d
- Requires indices: Must use MaxPool1d with return_indices=true to get indices
- Partial inverse: Non-max values not recoverable (zeroed in output)
- Shape restoration: Output shape matches original input to MaxPool1d
- Zero-filled: All positions except max indices get zero values
- No learnable parameters: Pure reconstruction operation
- Deterministic: Given same pooled input and indices, always produces same output
- Information loss: Non-max values permanently lost; perfect reconstruction impossible
- Index mismatch: Indices must match kernel_size and stride parameters
- Requires matching parameters: kernel_size, stride, padding must match MaxPool1d
- Output size: Affected by padding and stride; may not exactly match original
Examples
// Unpooling with indices from MaxPool1d
const pool = new torch.nn.MaxPool1d(2, 2, 0, true); // return_indices=true
const x = torch.randn([32, 64, 100]);
const [y, indices] = pool.forward(x) as [torch.Tensor, torch.Tensor]; // [32, 64, 50]
const unpool = new torch.nn.MaxUnpool1d(2, 2);
const reconstructed = unpool.unpool(y, indices); // [32, 64, 100] - restored shape// Autoencoder with pooling/unpooling symmetry
class SimpleAutoencoder extends torch.nn.Module {
// Encoder
pool1: torch.nn.MaxPool1d;
// Decoder
unpool1: torch.nn.MaxUnpool1d;
constructor() {
super();
this.pool1 = new torch.nn.MaxPool1d(2, 2, 0, true); // Save indices
this.unpool1 = new torch.nn.MaxUnpool1d(2, 2);
}
forward(x: torch.Tensor): torch.Tensor {
// Encoding: pool with indices
const [pooled, indices] = this.pool1.forward(x) as [torch.Tensor, torch.Tensor];
// Decoding: unpool using saved indices
return this.unpool1.unpool(pooled, indices);
}
}