HSNet
HSNet (Hypercorrelation Squeeze Networks) is a few-shot semantic segmentation model that treats the task as analysing dense feature correspondences rather than as matching prototypes.
- Paper: Juhong Min, Dahyun Kang, Minsu Cho (POSTECH), Hypercorrelation Squeeze for Few-Shot Segmentation, ICCV 2021, arXiv:2104.01538.
- Core idea: build a pyramid of 4D correlation tensors, a hypercorrelation, from every intermediate convolutional layer of a frozen backbone, and squeeze it down to a segmentation mask with deeply stacked 4D convolutions.
- Center-pivot 4D convolution: the second contribution; a weight-sparsified 4D kernel that decomposes into two 2D convolutions.
- Cost and result: cuts the model to 2.6M learnable parameters and 25.5 ms per episode while improving accuracy over dense 4D kernels.

Problem setup
Few-shot semantic segmentation segments a target object in a query image given only a few annotated support images of the same class. Training and test sets are disjoint with respect to object classes, and training is episodic: each episode samples a support set and a query set , and the model learns a mapping . At test time the learned mapping is applied to novel classes with no further optimization.
The dominant prior paradigm is prototypical: masked average pooling collapses the support foreground into one (or a few) global vectors, which are then compared against query features. That discards spatial structure. HSNet instead keeps all pairwise support-query matches and learns to read the geometric patterns in them — importing two ideas from the semantic-correspondence literature (multi-level features, and 4D convolutions for neighbourhood consensus) into few-shot segmentation.
Architecture

Three stages: hypercorrelation construction, a 4D-convolutional pyramid encoder, and a 2D-convolutional context decoder.
Hypercorrelation construction
Query and support images go through the same frozen backbone, producing pairs of intermediate feature maps — for VGG16, for ResNet50, for ResNet101, i.e. essentially every conv layer of the last blocks, not just the final one.
Each support feature map is masked to discard background activations:
where is the Hadamard product and bilinearly interpolates the mask to layer ‘s spatial size and expands it along channels.
Each layer then yields a 4D correlation tensor by cosine similarity between every query position and every support position :
the ReLU suppressing noisy negative scores. Tensors sharing a spatial resolution are concatenated along a new channel dimension into a hypercorrelation at pyramidal layer . With pyramid levels for all backbones, this gives the pyramid at resolutions (ResNet) or (VGG16). Note the correlation itself is parameter-free — it is a similarity, not a learned matching head, exactly as in PerSAM’s location prior, only computed densely at every level instead of pooled.
4D-convolutional pyramid encoder
Two building-block types, each three sequences of multi-channel 4D convolution → group normalization → ReLU:
- Squeezing block : strides periodically squeeze the support spatial dimensions (down to in practice) while the query dimensions are preserved:
- Mixing block : FPN-style top-down propagation — the output of level is upsampled by 2 along the query dimensions and added element-wise to level ‘s output, then processed by further 4D convs.
After iterative top-down mixing, the lowest block’s output is average-pooled over its support dimensions, giving a 2D context that condenses the whole hypercorrelation. This is the “coarse-to-fine squeeze”: high-level semantic evidence from the deep, low-resolution correlations is propagated down into the fine geometric correlations before collapsing.
2D-convolutional context decoder
A small stack of 2D convs, ReLU and upsampling (3x3 conv 128 → ReLU → 3x3 conv 64 → ReLU → upsample ×2 → 3x3 conv 64 → ReLU → 3x3 conv 2 → upsample ×4 → softmax), producing a two-channel map of foreground/background probabilities. 259K parameters, identical for all backbones.
Center-pivot 4D convolution

A 4D convolution with kernel on a correlation tensor at position is
with the 4D neighbourhood the Cartesian product — hence weights and quadratic complexity in the feature-map size. Two problems follow. Cost: this is why prior correspondence work could afford only a few 4D layers. Over-parameterization: a single activation is touched a number of times exponential in the dimensionality, so unreliable large-magnitude activations at insignificant 4D positions inject noise.
HSNet’s answer is weight sparsification: keep only the neighbours that pivot on one of the two 2D centers or ,
and . The resulting center-pivot (CP) 4D convolution is a union of two separate 4D convolutions, , which — because each collapses onto a fixed 2D slice of the tensor — reduces exactly to two 2D convolutions:
with and . Weights drop from to and complexity becomes linear, which is what makes deeply stacked 4D convolutions affordable at all. The full derivation is Appendix A of the paper.
Unlike the spatially separable 4D kernel of Yang & Ramanan, which needs auxiliary transformation layers with batch normalization for numerical stability, the CP decomposition is a sum of two independent 2D convolutions and needs none — hence half the parameters and half the latency.
Training and -shot inference
The backbone is frozen throughout — only the encoder and decoder are learned (2.6M parameters for every backbone). The network is optimized with the mean of the cross-entropy loss between the two-channel prediction and the ground truth over all pixel locations; at test time the per-pixel argmax gives .
-shot inference needs no architectural change: run forward passes to get , sum the predictions at every pixel, divide by the maximum voting score, and threshold at for the foreground.
Freezing the backbone is not merely an efficiency choice. The ablation on fine-tuning (Fig. 9) shows a fine-tuned backbone — even with its learning rate set 100× lower — rapidly overfits the training folds and loses validation mIoU, while the frozen model keeps the generic ImageNet representation and generalizes to novel classes. The claim is that in the few-shot regime one should learn feature correlations, not features.
Hyperparameters
| Setting | Value |
|---|---|
| Backbones | VGG16, ResNet50, ResNet101 (ImageNet-pretrained, frozen) |
| Feature extraction (VGG16) | after every conv layer in conv4_x–conv5_x, plus after the last maxpool; |
| Feature extraction (ResNet) | end of each bottleneck before the ReLU, conv3_x–conv5_x; (R50), (R101) |
| Pyramid levels | for all backbones |
| Input resolution | (), support and query alike |
| Correlation resolutions | , , (ResNet) / (VGG16) |
| Squeezed support size | |
| Encoder channels | 128 |
| 4D convs per building block | 3 (accuracy saturates beyond this) |
| Normalization | group norm, groups |
| Optimizer | Adam, learning rate |
| Batch size | 20 (PASCAL-5), 40 (COCO-20), 20 (FSS-1000) |
| Framework | PyTorch |
| -shot voting threshold | |
| Data augmentation | none |
| Learnable parameters | 2.6M for every backbone (decoder 259K; squeezing blocks ~168–203K each; mixing blocks 886K each) |
| Evaluation protocol | 4-fold cross-validation, 1,000 randomly sampled episodes per target fold |
The paper does not state a number of training epochs (it trains to validation-mIoU convergence; the learning curves in Fig. 9 run to roughly 100 epochs on PASCAL-5).
Results
Metrics are mean IoU (averaged over the classes of a fold) and foreground-background IoU, ; the paper focuses on mIoU as the better indicator of generalization.
PASCAL-5 (mIoU averaged over the 4 folds):
| Backbone | 1-shot mIoU | 1-shot FB-IoU | 5-shot mIoU | 5-shot FB-IoU | Params |
|---|---|---|---|---|---|
| VGG16 | 59.7 | 73.4 | 64.1 | 76.6 | 2.6M |
| ResNet50 | 64.0 | 76.7 | 69.5 | 80.6 | 2.6M |
| ResNet101 | 66.2 | 77.6 | 70.4 | 80.6 | 2.6M |
| ResNet101, no support masking | 61.5 | 72.5 | 63.7 | 73.8 | 2.6M |
With ResNet101 this is +6.1%p (1-shot) and +4.8%p (5-shot) mIoU over PFENet, with the fewest learnable parameters of any compared method (PFENet 10.8M, RePRI 46.7M, FWB 43.0M, OSLSM 276.7M).
COCO-20:
| Backbone | 1-shot mIoU | 1-shot FB-IoU | 5-shot mIoU | 5-shot FB-IoU |
|---|---|---|---|---|
| ResNet50 | 39.2 | 68.2 | 46.9 | 70.7 |
| ResNet101 | 41.2 | 69.1 | 47.1 | 72.4 |
+2.7%p (1-shot) and +6.8%p (5-shot) over PFENet with ResNet101.
FSS-1000 (mIoU): VGG16 82.3 / 85.8, ResNet50 85.5 / 87.8, ResNet101 86.5 / 88.5 (1-shot / 5-shot) — state of the art on all three benchmarks.
Larger (ResNet50, PASCAL-5 / COCO-20): 64.0 / 39.2 at , 69.5 / 46.9 at , 70.6 / 48.7 at , i.e. +2.5%p and +4.6%p over the previous best at 10-shot.
Efficiency
Comparison of the three 4D kernels (ResNet101, PASCAL-5; timings on an Intel i7-7820X and an NVIDIA Titan-XP):
| Kernel | 1-shot mIoU | 5-shot mIoU | Params | Time / episode | Memory | FLOPs |
|---|---|---|---|---|---|---|
| Original dense 4D | 64.9 | 70.1 | 11.3M | 512.17 ms | 4.12 GB | 702.35 G |
| Spatially separable 4D | 65.9 | 70.2 | 4.4M | 28.48 ms | 1.50 GB | 28.40 G |
| Center-pivot 4D (ours) | 66.2 | 70.4 | 2.6M | 25.51 ms | 1.39 GB | 20.56 G |
A 20× speed-up and 34× FLOP reduction over the dense kernel, with higher accuracy — direct evidence that most weights in a high-dimensional kernel are not merely redundant but actively harmful.
Ablations
- Multi-level vs. single-level correlation (ResNet101, PASCAL-5 1-shot mIoU): (a single shallowest correlation) 59.1, (single deepest) 61.7, full multi-channel 66.2. So +4.5%p from stacking all intermediate layers, and the shallow-vs-deep gap confirms that reliable features live in deeper layers.
- Pyramid layers: (deepest level only) 55.5, 63.9, full 66.2 (1-shot). Without the geometric (fine) levels the model gives only coarse localization and cannot refine boundaries; the intermediate level is especially important.
- Depth of building blocks: accuracy improves up to three 4D conv layers per block, then saturates.
- Support masking: removing Eqn. 1 entirely (a setting close to co-segmentation) still gives 61.5 mIoU 1-shot with ResNet101, +1.4%p over the previous best masked method (and 63.7 at 5-shot, rivalling it) — the model can identify the common instance across two images without being told where it is in the support.
- Domain shift (train on COCO-20, test on PASCAL-5, disjoint classes, no data augmentation): HSNet-R50 61.6 (1-shot) / 68.7 (5-shot), HSNet-R101 64.1 / 70.3, versus RePRI 63.2 / 67.7 with 46.7M parameters and flip augmentation, and PFENet 61.1 / 63.4 with flip/rotate/crop.
ignore_label: some prior methods do not use PASCAL’s ambiguous-boundary ignore label. Evaluated without it too, HSNet-R50 still gets 59.1 (1-shot) / 64.2 (5-shot) mIoU, +2.8%p / +5.4%p over the best of those methods.
Limitations
- Quadratic correlation cost. The CP kernel makes the convolutions linear, but the hypercorrelation tensor itself is still per level — memory grows quadratically with feature-map resolution, which caps the input at and the finest correlation at .
- Frozen backbone caps the representation. Everything downstream depends on ImageNet features that were never adapted to the task; fine-tuning them overfits, so the ceiling is whatever correspondence signal those features already contain.
- Failure modes (Fig. A11): severe occlusion, large intra-class variance between support and query, and extremely tiny objects in either image cause localization failures.
- No data augmentation is used, and the paper notes domain-shift robustness “may further increase” with the augmentations used by competitors — the reported numbers are therefore not the ceiling.
- Support masking is at feature resolution. The mask is bilinearly downsampled to each layer’s grid, so thin structures are lost before the correlation is even computed.
- The method solves a class-agnostic binary task per episode; multi-class segmentation requires one pass per class, and -shot inference costs forward passes since aggregation happens at the prediction level, not in the feature space.
See also
- PerSAM — the same idea of dense cosine-similarity matching against a masked reference feature map, but training-free and on top of a frozen SAM rather than feeding a learned 4D-conv encoder.
- SAM — promptable segmentation from a very different angle: instead of learning to match one support example, train on 1.1B masks so a click suffices.
- SAM3 — promptable concept segmentation, including with exemplar images; the modern, foundation-model answer to the problem HSNet attacks with correspondence.
- Your ViT is Secretly an Image Segmentation Model — the opposite architectural bet: strip the specialized segmentation machinery and let a large pre-trained ViT do the work.
- Implementing Research Papers — HSNet’s episodic 4-fold protocol and 1,000-episode sampling are exactly the kind of evaluation detail that decides whether a reproduction matches.