PDiscoFormer: Relaxing Part Discovery Constraints with Vision Transformers

ECCV 2024 Oral Presentation
1 Inria, Univ Montpellier, CNRS, LIRMM, UMR TETIS, Montpellier, France
2 Inria, INRAE, Univ Montpellier, UMR TETIS, Montpellier, France

Concentration vs. Total Variation as Part Priors

Comparison of concentration prior versus total variation prior for part discovery
Figure 1: Concentration vs. total variation as part priors. (Left) Prior methods like PDiscoNet enforce compact, single-component parts around a centroid. (Right) PDiscoFormer leverages self-supervised Vision Transformers (DINOv2) to relax these rigid constraints using a Total Variation (TV) prior, allowing parts to form arbitrary shapes and multiple connected components (e.g. wings, legs, head, flower petals) while preserving spatial smoothness.

Concentration Prior (Previous Work)

\[ \mathcal{L}_\text{conc} = \frac{\sum_{k=1}^K \sigma_v^2(\mathbf{A}^k) + \sigma_h^2(\mathbf{A}^k)}{K} \]

where \(\sigma_v^2(\mathbf{A}^k)\) and \(\sigma_h^2(\mathbf{A}^k)\) represent the vertical and horizontal spatial variance over the attention maps.

Limitation: Fails on disconnected components (e.g., pairs of wings/limbs) or elongated, irregular shapes (e.g., snakes).

Total Variation Prior (PDiscoFormer)

Penalizes only spatial gradients / boundary roughness, allowing multiple connected components of arbitrary shape and size:

\[ \mathcal{L}_{\text{tv}} = \frac{1}{HW} \sum_{k=1}^{K+1} \sum_{i,j} \left| \nabla a_{ij}^k \right| \]

Advantage: Unlocks natural, multi-component semantic parts while maintaining smooth, coherent segmentations.

Abstract

Computer vision methods that explicitly detect object parts and reason on them are a step towards inherently interpretable models. Existing approaches that perform part discovery driven by a fine-grained classification task make very restrictive assumptions on the geometric properties of the discovered parts; they should be small and compact. Although this prior is useful in some cases, in this paper we show that pre-trained transformer-based vision models, such as self-supervised DINOv2 ViT, enable the relaxation of these constraints.

In particular, we find that a total variation (TV) prior, which allows for multiple connected components of any size, substantially outperforms previous work. We test our approach on three fine-grained classification benchmarks: CUB, PartImageNet, and Oxford Flowers, and compare our results to previously published methods as well as a re-implementation of the state-of-the-art method PDiscoNet with a transformer-based backbone. We consistently obtain substantial improvements across the board, both on part discovery metrics and the downstream classification task, showing that the strong inductive biases in self-supervised ViT models require rethinking the geometric priors used for unsupervised part discovery.

Methodology & Architecture

PDiscoFormer model architecture diagram
Figure 2: Overview of PDiscoFormer Architecture. Given an input image \(\mathbf{x}\), patch tokens are extracted using a DINOv2 ViT backbone (with register tokens). Negative squared Euclidean distances to learnable prototypes \(\mathbf{p}^k\) followed by Gumbel-Softmax generate \(K\) foreground attention maps and 1 background map. The attention maps weight-average the features into part embeddings \(\mathbf{v}^k\), which are modulated by per-part Layer Normalization and passed to a linear classifier with part dropout. The training objective synergizes classification with total variation, entropy, presence, background boundary mask, and equivariance losses.

1. Prototype Attention Maps via Gumbel-Softmax

Given patch features \(\mathbf{z} \in \mathbb{R}^{D \times H \times W}\) from a pre-trained ViT, we compute attention maps \(\mathbf{A} \in [0, 1]^{(K+1) \times H \times W}\) representing \(K\) foreground parts and a background channel. Attention probabilities are computed by comparing patch tokens \(\mathbf{z}_{ij}\) with learnable prototypes \(\mathbf{p}^k\), sampled through a Gumbel-Softmax:

\[ a_{ij}^k = \frac{\exp\left(-\| \mathbf{z}_{ij} - \mathbf{p}^k\|^2 + \gamma_k \right)}{\sum_{l=1}^{K+1} \exp\left(-\| \mathbf{z}_{ij} - \mathbf{p}^l\|^2 + \gamma_l\right)} \]

where \(\gamma_k \sim \text{Gumbel}(0, 1)\). Part embedding vectors \(\mathbf{v}^k\) are then obtained by weighted average pooling of features \(\mathbf{z}\) over each attention map \(A^k\).

2. Part Modulation & Dropout

Each part vector \(\mathbf{v}^k\) is modulated with a dedicated per-part Layer Normalization:

\[ \mathbf{v}_m^k = \frac{\mathbf{v}^k - \mathbb{E}[\mathbf{v}^k]}{\sqrt{\text{Var}[\mathbf{v}^k] + \epsilon}} \odot \mathbf{w}_m^k + \mathbf{b}_m^k \]

During training, entire part embedding vectors are randomly dropped (Part Dropout). This forces each individual part to be discriminative for the fine-grained classification task rather than relying on a single dominant part.

3. Rethinking Geometric Part Priors: From Concentration to Total Variation

Previous weakly-supervised part discovery approaches (such as PDiscoNet, van der Klis et al.) enforce compactness on the learned attention maps \(\mathbf{A}^k\) through a concentration loss \(\mathcal{L}_{\text{conc}}\):

\[ \mathcal{L}_\text{conc} = \frac{\sum_{k=1}^K \sigma_v^2(\mathbf{A}^k) + \sigma_h^2(\mathbf{A}^k)}{K} \]

where \(\sigma_v\) and \(\sigma_h\) denote the vertical and horizontal spatial variance respectively over the attention maps, computed with respect to the part centroid \((c_v^k, c_h^k)\):

\[ c_v^k = \frac{\sum_{i,j} i \cdot a_{ij}^k}{\sum_{i,j} a_{ij}^k}, \qquad c_h^k = \frac{\sum_{i,j} j \cdot a_{ij}^k}{\sum_{i,j} a_{ij}^k} \]
\[ \sigma_v^2(\mathbf{A}^k) = \sum_{i,j} a_{ij}^k \left( \frac{i - c_v^k}{H} \right)^2, \qquad \sigma_h^2(\mathbf{A}^k) = \sum_{i,j} a_{ij}^k \left( \frac{j - c_h^k}{W} \right)^2 \]

While \(\mathcal{L}_{\text{conc}}\) was essential for CNN backbones to avoid degenerate solutions, penalizing spatial variance strictly constrains discovered parts to be compact and unimodal. As a result, it fundamentally struggles with:

  • Multi-component parts: Natural parts that are spatially separated (e.g., both wings of a bird, pairs of quadruped legs, disconnected flower petals).
  • Irregular and elongated geometries: Non-compact structures such as snake bodies, stems, or animal tails.

Because self-supervised Vision Transformers (such as DINOv2) already encode strong patch-level semantic grouping, PDiscoFormer relaxes this rigid centroid constraint by replacing \(\mathcal{L}_{\text{conc}}\) with a Total Variation prior:

  • Total Variation Loss (\(\mathcal{L}_{\text{tv}}\)): Penalizes spatial gradients of attention maps to favor piece-wise constant, spatially connected regions without restricting shape, elongation, or number of connected components:
    \[ \mathcal{L}_{\text{tv}} = \frac{1}{HW} \sum_{k=1}^{K+1} \sum_{ij} \left| \nabla a_{ij}^k \right| \]
  • Entropy Loss (\(\mathcal{L}_{\text{ent}}\)): Encourages crisp assignment of each patch to a single part prototype:
    \[ \mathcal{L}_{\text{ent}} = \frac{-1}{K+1}\sum_{k=1}^{K+1}\sum_{ij} a_{ij}^k \log\left(a_{ij}^k\right) \]
  • Background Presence Loss (\(\mathcal{L}_{\text{p}_0}\)): Enforces the background channel to be present in every image, prioritized near image boundaries via a soft spatial border mask \(m_{ij}\):
    \[ \mathcal{L}_{\text{p}_0} = -\frac{1}{B}\sum_b \log\left(\max_{i,j} m_{ij} \bar{a}_{ij}^{K+1}(\mathbf{x}_b)\right) \]
  • Orthogonality (\(\mathcal{L}_{\perp}\)) & Equivariance (\(\mathcal{L}_{\text{eq}}\)): Ensure that different part embedding vectors are decorrelated, and that predicted part maps transform equivariantly under rigid affine augmentations.

Quantitative Benchmarks

PDiscoFormer is evaluated across three diverse fine-grained benchmarks: CUB-200-2011 (birds with compact parts), PartImageNet OOD (158 classes across 11 super-classes with complex non-compact parts), and Oxford 102 Flowers (multi-instance flower petals).

Method CUB (%) PartImageNet OOD (%) Flowers (%)
\(K\) Kp \(\downarrow\) NMI \(\uparrow\) ARI \(\uparrow\) Top-1 \(\uparrow\) \(K\) NMI \(\uparrow\) ARI \(\uparrow\) Top-1 \(\uparrow\) \(K\) Fg. mIoU \(\uparrow\) Top-1 \(\uparrow\)
Dino (Amir et al.)** 4-31.1811.21- 819.177.59- 254.95-
8-47.2119.76- 2531.4614.16- 455.11-
16-50.5726.14- 5037.8116.50- 854.44-
Huang et al. 411.5129.7414.0487.30 85.881.5374.22 229.9293.07
811.6035.7215.9086.05 257.561.2573.56 433.2293.14
1612.6043.9221.1085.93 5010.191.0573.20 817.2692.86
PDiscoNet (ResNet) 49.1237.8215.2686.17 827.138.7688.58 219.0477.51
88.5250.0826.9686.72 2532.4110.6989.00 434.7683.05
167.6756.8738.0587.49 5041.4914.1786.06 849.1081.04
PDiscoNet + ViT-B 47.7052.5926.6688.61 819.2834.7290.95 24.9292.75
86.3465.0137.9086.95 2528.2350.3590.29 41.9595.48
165.9568.6343.4184.04 5029.4827.8089.69 813.1897.40
PDiscoFormer (Ours) 47.4158.1325.1189.06 829.0052.4089.75 273.6299.61
85.9969.8743.4988.79 2544.7159.2790.77 473.3299.54
165.7473.3855.8388.72 5046.2962.2191.01 869.5999.64

** Method does not use any class supervision. Best results across methods are highlighted in bold blue.

Ablation Study

Ablating individual loss components confirms that every proposed component contributes crucially to part discovery and classification:

Ablation Variant PartImageNet OOD (\(K=25\)) CUB (\(K=16\))
NMI \(\uparrow\) ARI \(\uparrow\) Top-1 \(\uparrow\) Kp \(\downarrow\) NMI \(\uparrow\) ARI \(\uparrow\) Top-1 \(\uparrow\)
Full PDiscoFormer 44.71 59.27 90.77 5.74 73.38 55.83 88.72
No \(\mathcal{L}_{\text{tv}}\) (Total Variation) 33.73 25.35 90.47 6.01 70.78 51.83 80.22
No \(\mathcal{L}_{\text{ent}}\) (Entropy) 39.16 54.46 91.19 5.57 66.88 45.68 88.21
No \(\mathcal{L}_{\text{p}_0}\) (Background Presence) 41.05 49.08 89.81 5.85 68.66 43.09 83.64
No \(\mathcal{L}_{\text{p}_1}\) (Foreground Presence) 33.98 58.31 91.07 7.14 61.04 34.28 89.04
No \(\mathcal{L}_{\text{eq}}\) (Equivariance) 43.38 54.19 90.47 9.05 56.85 30.63 83.71
No Per-Part LayerNorm 31.14 40.73 89.69 5.74 70.70 50.62 69.73
No Part Dropout 33.08 43.98 89.99 6.08 70.28 41.69 87.14
No Gumbel-Softmax 32.98 54.68 90.71 6.44 68.92 43.61 86.43

Entropy Analysis

Analyzing the entropy of learned part attention maps shows that PDiscoFormer yields significantly sharper, less ambiguous assignments across all foreground and background regions compared to baselines.

Entropy on CUB
CUB Dataset: Lower entropy indicates cleaner, more confident part boundaries.
Entropy on PartImageNet
PartImageNet OOD: PDiscoFormer consistently achieves minimal entropy across parts.

Qualitative Results

Visual comparison of discovered part segmentations across different datasets. Notice how PDiscoFormer successfully segments irregular parts (e.g. bird wings, elongated snake bodies, quadruped limbs, flower petals) without breaking them into arbitrary compact blobs.

Input
Input
Input
Input
Input
PDiscoNet (ResNet)
PDiscoNet
PDiscoNet
PDiscoNet
PDiscoNet
PDiscoNet (ViT-B)
PDiscoNet ViT
PDiscoNet ViT
PDiscoNet ViT
PDiscoNet ViT
PDiscoFormer (Ours)
Ours
Ours
Ours
Ours

Discovered parts on CUB (\(K=8\)). PDiscoFormer naturally captures full wings, heads, tails, and torsos consistently across poses.

Input
Input
Input
Input
Input
PDiscoNet (ResNet)
PDiscoNet
PDiscoNet
PDiscoNet
PDiscoNet
PDiscoNet (ViT-B)
PDiscoNet ViT
PDiscoNet ViT
PDiscoNet ViT
PDiscoNet ViT
PDiscoFormer (Ours)
Ours
Ours
Ours
Ours

Discovered parts on PartImageNet Snake super-class. PDiscoFormer adheres to curved, elongated bodies without arbitrary circular fragmentation.

Input
Input
Input
Input
Input
PDiscoNet (ResNet)
PDiscoNet
PDiscoNet
PDiscoNet
PDiscoNet
PDiscoNet (ViT-B)
PDiscoNet ViT
PDiscoNet ViT
PDiscoNet ViT
PDiscoNet ViT
PDiscoFormer (Ours)
Ours
Ours
Ours
Ours

Discovered parts on PartImageNet Quadruped super-class. Legs, torsos, and heads are distinctly and coherently segmented.

Input
Input
Input
Input
Input
PDiscoNet (ResNet)
PDiscoNet
PDiscoNet
PDiscoNet
PDiscoNet
PDiscoNet (ViT-B)
PDiscoNet ViT
PDiscoNet ViT
PDiscoNet ViT
PDiscoNet ViT
PDiscoFormer (Ours)
Ours
Ours
Ours
Ours

Discovered foreground flower masks (\(K=2\)). Baselines severely degrade on multi-instance flowers, while PDiscoFormer sharply isolates petal boundaries.

Interactive Live Demo

Try PDiscoFormer interactively in your browser via our Hugging Face Space. Upload an image or choose one of the built-in examples (birds, flowers, PartImageNet) to discover semantic object parts and visualize attention maps in real time.

Pre-trained Models & Quickstart

Pre-trained checkpoints for CUB-200-2011, PartImageNet OOD, and Oxford Flowers across various part configurations (\(K\)) are available directly via Hugging Face 🤗 and PyTorch Hub.

# Install required dependencies
# pip install huggingface-hub timm

from models import IndividualLandmarkViT

# --- CUB-200-2011 Models ---
pdiscoformer_cub_k_4  = IndividualLandmarkViT.from_pretrained("ananthu-aniraj/pdiscoformer_cub_k_4")
pdiscoformer_cub_k_8  = IndividualLandmarkViT.from_pretrained("ananthu-aniraj/pdiscoformer_cub_k_8")
pdiscoformer_cub_k_16 = IndividualLandmarkViT.from_pretrained("ananthu-aniraj/pdiscoformer_cub_k_16")

# --- PartImageNet OOD Models ---
pdiscoformer_pimg_k_8  = IndividualLandmarkViT.from_pretrained("ananthu-aniraj/pdiscoformer_part_imagenet_ood_k_8", input_size=224)
pdiscoformer_pimg_k_25 = IndividualLandmarkViT.from_pretrained("ananthu-aniraj/pdiscoformer_part_imagenet_ood_k_25", input_size=224)
pdiscoformer_pimg_k_50 = IndividualLandmarkViT.from_pretrained("ananthu-aniraj/pdiscoformer_part_imagenet_ood_k_50", input_size=224)

# --- Oxford Flowers Models ---
pdiscoformer_flw_k_2 = IndividualLandmarkViT.from_pretrained("ananthu-aniraj/pdiscoformer_flowers_k_2", input_size=224)
pdiscoformer_flw_k_4 = IndividualLandmarkViT.from_pretrained("ananthu-aniraj/pdiscoformer_flowers_k_4", input_size=224)
pdiscoformer_flw_k_8 = IndividualLandmarkViT.from_pretrained("ananthu-aniraj/pdiscoformer_flowers_k_8", input_size=224)

# --- Forward Pass ---
# attention_maps: [B, K+1, H, W] for K foreground parts + 1 background channel
# class_logits:   [B, num_classes] predicted class scores
attention_maps, class_logits = pdiscoformer_cub_k_16(images)

BibTeX

@inproceedings{aniraj2024pdiscoformer,
  title={PDiscoFormer: Relaxing Part Discovery Constraints with Vision Transformers},
  author={Aniraj, Ananthu and Dantas, Cassio F. and Ienco, Dino and Marcos, Diego},
  booktitle={European Conference on Computer Vision (ECCV)},
  pages={256--272},
  year={2024},
  organization={Springer},
  doi={10.1007/978-3-031-73013-9_15}
}