torch.nn.MaxUnpool1dOptions
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
Definition
export interface MaxUnpool1dOptions {
/** Stride of the pooling operation (default: kernel_size) */
stride?: number;
/** Padding used in MaxPool1d (default: 0) */
padding?: number;
}stride(number)optional- – Stride of the pooling operation (default: kernel_size)
padding(number)optional- – Padding used in MaxPool1d (default: 0)
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);
}
}