README.md

September 2, 2025 · View on GitHub

Official PyTorch implementation of "Pedestrian Attribute Recognition via CLIP based Vision-Language Fusion with Prompt Tuning"


Pedestrian Attribute Recognition via CLIP based Vision-Language Fusion with Prompt Tuning, Xiao Wang, Jiandong Jin, Chenglong Li*, Jin Tang, Cheng Zhang, Wei Wang

Usage

Requirements

we use single RTX A6000 48G GPU for training and evaluation.

Python 3.9.16
pytorch 1.12.1
torchvision 0.13.1
scipy 1.10.0
Pillow
easydict
tqdm
opencv-python
ftfy
regex

Configuration for Windows System

conda create -n OpenPAR
conda activate OpenPAR
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
pip install -r .\requirements.txt

Dataset Processing (Here, let's take the PETA for an example)

  • Download the PETA dataset directly from the Baidu Drive and place it under ``OpenPAR-main\PromptPAR\dataset"
链接: https://pan.baidu.com/s/1Gv_VUSSb0QCDgD2evLrw7w?pwd=upfs 提取码: upfs
  • Process the PETA dataset using the following script:
  cd .\dataset\preprocess\ && python .\peta_pad.py

It will generate a new file ``pad.pkl".

Training Script

python train.py PETA --use_textprompt --use_div --use_vismask --use_GL --use_mm_former

If you meet the following issues

please modify the num_workers in the train.py to a smaller one (default num_workers=8), such as:

    train_set = MultiModalAttrDataset(args=args, split=args.train_split, transform=train_tsfm) 
    train_loader = DataLoader(
        dataset=train_set,
        batch_size=args.batchsize, 
        shuffle=True,
        num_workers=2, 
        pin_memory=True,  
    )
    valid_set = MultiModalAttrDataset(args=args, split=args.valid_split, transform=valid_tsfm) 
    valid_loader = DataLoader(
        dataset=valid_set,
        batch_size=args.batchsize,
        shuffle=False,
        num_workers=2,
        pin_memory=True,
    )

If you handle all the issues, you can train the PromptPAR successfully!

Test Script

python test_example.py PETA --checkpoint --dir your_dir --use_div --use_vismask --vis_prompt 50 --use_GL --use_textprompt --use_mm_former 

Config

ParametersImplication
ag_thresholdThresholding in global localized image text aggregation (0,1)
use_divWhether or not to use regional splits
use_vismaskWhether to use a visual mask
use_GLWhether or not to use global localized image text aggregation
use_textpromptWhether or not to use text prompt
use_mm_formerFusion of features using multimodal Transformer or linear layers
div_numNumber of split regions
overlap_rowNumber of overlapping rows in the split regions
text_promptNumber of text prompts
vis_promptNumber of visual prompts
vis_depthDepth of visual prompts [1,24]

Vit-Large Checkpoint Download

DatasetBaiduYunExtracted codeGoogleDrive
RAPBaiduYun1oenGoogleDrive
PETABaiduYunMMICGoogleDrive
PA100kBaiduYunMMICGoogleDrive

News:

Abstract

Existing pedestrian attribute recognition (PAR) algorithms adopt pre-trained CNN (e.g., ResNet) as their backbone network for visual feature learning, which might obtain sub-optimal results due to the insufficient employment of the relations between pedestrian images and attribute labels. In this paper, we formulate PAR as a vision-language fusion problem and fully exploit the relations between pedestrian images and attribute labels. Specifically, the attribute phrases are first expanded into sentences, and then the pre-trained vision-language model CLIP is adopted as our backbone for feature embedding of visual images and attribute descriptions. The contrastive learning objective connects the vision and language modalities well in the CLIP-based feature space, and the Transformer layers used in CLIP can capture the long-range relations between pixels. Then, a multi-modal Transformer is adopted to fuse the dual features effectively and feed-forward network is used to predict attributes. To optimize our network efficiently, we propose the region-aware prompt tuning technique to adjust very few parameters(i.e., only the prompt vectors and classification heads) and fix both the pre-trained VL model and multi-modal Transformer. Our proposed PAR algorithm only adjusts 0.75% learnable parameters compared with the fine-tuning strategy. It also achieves new state-of-the-art performance on both standard and zero-shot settings for PAR, including RAPv1, RAPv2, WIDER, PA100K, and PETA-ZS, RAP-ZS datasets.

Our Proposed Approach

Experimental Results

Acknowledgments

Our code is extended from the following repositories. We sincerely appreciate for their contributions.