This is the official implementation for our paper "[Diff-Feat: Diffusion-Based Cross-Modal Feature Extraction for Multi-Label Classification]".
This module extracts intermediate representations from pretrained DiT-XL/2(256$\times$256) models and trains a lightweight classifier on datasets like MSCOCO, VG500, or Tiny-ImageNet, using diffusion features across different timesteps and Transformer blocks.
This pipeline includes:
- Loading raw images
- Extracting transformer block features at specific diffusion timesteps
- Saving extracted features as
.npzfiles for reproducibility and fusion - Training a linear classifier on extracted features
- Evaluating Top-1 / Top-5 accuracy (for single-label) or mAP, F1, Precision, Recall (for multi-label)
The environment setup is identical to that required for training and evaluating the DiT model. Please refer to the DiT repository for installation and dependency instructions.
If starting from raw images:
# Use provided script to encode raw images into VAE latents(vae_latent.py)
torchrun --nproc_per_node=4 vae_latent.py
# Output: {dataset_name}/latent/*.npztorchrun --nproc_per_node=4 linear_image.py \
--name layer-12 \
--time 20 \
--epoch 40 \
--lr 1e-3 \
--batch_size 128 \
--use_amp-
Extracted features are saved to:
{dataset_name}/features/train_features_t20_layer-12.npz {dataset_name}/features/val_features_t20_layer-12.npz -
Final classification metrics are appended to:
{dataset_name}/result/final_results.csv
Metrics Reported:
- Single-label classification: Top-1 Accuracy, Top-5 Accuracy;
- Multi-label classification: mAP, CP, CR, CF1, OP, OR, OF1, Top-3 versions of the above metrics;
This module provides the code for extracting intermediate representations from a pretrained language diffusion model Plaid 1B and training a simple linear classifier for multi-label classification. It is designed to support experiments on datasets such as VG500 with minimal modification.
Please refer to the Plaid repository for installation and dependency instructions.
Download the Plaid 1B weights and place them in:
../plaid1b_weights/
├── model.pt
├── embedding_matrix.pt
├── noise_schedule.pt
└── gamma_bounds.pt
Place your training and testing CSVs in dataset/{dataset_name}/.
Each row in the CSV should include:
image_id: unique identifiercaption: the input textlabel: a list of binary values (as stringified list), e.g.,"[0, 1, 0, ..., 1]"
torchrun --nproc_per_node=4 linear_language.py --timestep 30 --blockname layer-12Optional arguments:
--timestep: index in the diffusion schedule (default: 0)--blockname: transformer block name to extract activations (e.g.,layer-20)
- Extracted features are saved as
.npzfiles in{dataset_name}/features/ - After training, the script prints:
- mAP, CP, CR, CF1, OP, OR, OF1
- Top-3 versions of the above metrics
- Different datasets may require different
seq_lenvalues, which can significantly impact experimental results. Please adjustseq_lenaccordingly in the configuration, and analyze the token length distribution usingtoken_distribution.pyto make an informed choice. - Feature extraction supports deterministic ODE-style sampling by default. For stochastic DDPM/Appendix experiments, you can modify the sampler accordingly.
This module fuses latent features extracted from pretrained diffusion models in two modalities — image and language — for downstream multi-label classification. It supports flexible fusion strategies, distributed training, and standard evaluation metrics.
- Image features: From diffusion models (e.g., DiT), saved as
.npz - Language features: From language diffusion models(e.g., Plaid), saved as
.npz - Labels: Multi-label vectors (e.g., VG500 object categories), saved as
.csv
Linear AdditionLinear ConcatSimple ConcatCross Attention
Ensure the following files exist:
-
Image latent features:
../DiT/VG500/features/train_t{image_time}_{image_name}.npz ../DiT/VG500/features/test_t{image_time}_{image_name}.npz -
Text latent features:
../plaid/VG500/features/train_t{lang_name}_{lang_time}.npz ../plaid/VG500/features/test_t{lang_name}_{lang_time}.npz -
Label files:
../plaid/dataset/VG500/train_vg.csv ../plaid/dataset/VG500/test_vg.csv
torchrun --nproc_per_node=4 train_multimodal_fusion.py \
--image_time 100 --image_name layer-8 \
--lang_time 30 --lang_name layer-12 \
--batch_size 128 --epoch 40 --lr 1e-3 --use_ampAt the end of training, the following evaluation metrics are printed:
- mAP, CP, CR, CF1, OP, OR, OF1
- Top-3 versions of the above metrics
This project is based on the DiT, Plaid and DDAE. Thanks for their great work!