π§ͺ ReSAGE-PAR: Representational Similarity Assessment for Generative Expansion in Pedestrian Attribute Recognition πΆββοΈβ¨
End-to-end pipeline to generate dataset-aware synthetic pedestrian images, score textβimage alignment, and produce pseudo-labels for training Pedestrian Attribute Recognition (PAR) models.
π Stages: πΌοΈ Stage A (Generation) β π Stage B (Scoring) β π·οΈ Stage C (Pseudo-labeling)
π Optional: Metric tools to compare Real vs Synthetic distributions (FID/CFID/CMMD/FD-DINO)
- β¨ Overview
- β‘ Quick Start
- π§± Pipeline Stages
- ποΈ Config Files
- π§ͺ Environments
- π¦ Inputs & Outputs
- π§° Troubleshooting
This repo supports a generateβscoreβautolabel workflow:
- β Stage A generates synthetic images using Stable Diffusion + LoRA (optionally with attribute editing).
- β Stage B computes imageβtext similarity scores to assess alignment between the synthetic image and its prompt.
- β Stage C trains a lightweight SI-classifier on real scores and uses it to generate pseudo-label vectors for synthetic data.
Run everything with YAML configs:
./wholePipelineWithConfigs.shThis executes:
- πΌοΈ Stage A: generation
- π Stage B: scoring (real + synthetic)
- π·οΈ Stage C: pseudo-labeling
python src/stage_a_generation/run_stage_a.py --config configs/stage_a.yamlpython -m src.stage_b_scoring.run_stage_b --config configs/stage_b_scores.yamlpython -m src.stage_b_scoring.run_stage_b --config configs/stage_b_scores_syn.yamlpython -m src.stage_c_pseudolabeling.run_stage_c --config configs/stage_c_train.yamlpython -m src.stage_c_pseudolabeling.run_stage_c --config configs/stage_c_test.yamlpython -m src.stage_c_pseudolabeling.run_stage_c --config configs/stage_c_labeling_syn.yamlπ‘ Tip: Prefer
python -m ...to avoid relative-import issues.
π src/stage_a_generation/
Generate synthetic images using a trained LoRA model and prompts derived from attribute vectors.
- Config:
configs/stage_a.yaml - Script:
src/stage_a_generation/run_stage_a.py
π src/stage_b_scoring/
Compute similarity scores (e.g. BLIP score) for:
-
real images + (positive / complemented) prompts (train/test)
-
synthetic images + generation prompt
-
Configs:
configs/stage_b_scores.yaml(real)configs/stage_b_scores_syn.yaml(synthetic)
π src/stage_c_pseudolabeling/
Train/test an SI-classifier on real scores and produce pseudo-labels for synthetic samples.
-
Configs:
configs/stage_c_train.yamlconfigs/stage_c_test.yamlconfigs/stage_c_labeling_syn.yaml
π tools/metricAspect/
Compare distributions between Real and Synthetic using metrics like:
FID, CFID, CMMD, FD-DINO.
All configs live in configs/:
lora.yamlβ LoRA training (optional / may be commented out in full pipeline)getMetadata.yamlβ metadata.jsonl generation (optional)stage_a.yamlβ generation settingsstage_b_scores.yamlβ scoring on real datastage_b_scores_syn.yamlβ scoring on synthetic datastage_c_train.yamlβ classifier trainingstage_c_test.yamlβ classifier testingstage_c_labeling_syn.yamlβ synthetic pseudo-labeling
name: "experiment_name"
testing: true
model:
pretrained_model_name_or_path: "..."
generation: # or: training, scoring, dataset, etc.
dataset_name: "RAPzs"
output:
output_dir: "results/"β Run with config:
python script.py --config configs/stage_a.yamlβ Override a YAML value:
python script.py --config configs/stage_a.yaml --height 512π Rule: CLI arguments override YAML values.
Each stage has its own conda environment for reproducibility:
conda env create -f environments/stage_a.yaml
conda env create -f environments/stage_b.yaml
conda env create -f environments/stage_c.yamlconda activate stage_a # LoRA + generation
conda activate stage_b # scoring
conda activate stage_c # pseudo-labelingconda env create -f environments/tool_metric_aspect.yaml
conda activate tool_metric_aspectBefore running the pipeline, ensure the real datasets are available on disk. The stages expect three dataset-related paths (which you can override via YAML or CLI in Stages A, B, and C):
- path_dataset: folder with dataset images used by the pipeline
- path_gt: path to the ground-truth pickle (dataset_all.pkl)
- path_gt_img: folder with ground-truth image files (used for GT lookups/metrics)
Defaults vary by dataset. Example defaults for PA100k (as used in configs/getMetadata_custom_paths.yaml):
- path_dataset (images): /mnt/rhome/paa/pedestrian/datasetForFID/PA100k/train/
- path_gt (pickle): /mnt/rhome/paa/pedestrian/Rethinking_of_PAR/data/PA100k/dataset_all.pkl
- path_gt_img (GT images): /mnt/rhome/paa/pedestrian/Rethinking_of_PAR/data/PA100k/data/
Example folder layout (PA100k):
/path/
βββ datasetdivided/
β βββ PA100k/
β βββ train/ # path_dataset β images for training split
β βββ test/
βββ data/
βββ PA100k/
βββ dataset_all.pkl # path_gt β ground-truth annotations
βββ data/ # path_gt_img β GT image directory
You can provide custom paths per dataset in any stage:
- Via YAML: uncomment the
dataset:block and setpath_dataset,path_gt,path_gt_imgin the stage config (e.g., configs/stage_a.yaml, configs/stage_b_scores.yaml, configs/stage_c_train.yaml) - Via CLI: pass
--path_dataset,--path_gt,--path_gt_imgwhen running the stage scripts
CLI takes precedence over YAML; if not provided, the code uses dataset-specific defaults.
If you only have the PA100k ground-truth images and the dataset_all.pkl, you can automatically create the split folders using the helper script:
# Dry-run: preview the actions
python tools/dataset_splitters/create_dataset_split.py \
--dataset PA100k \
--pkl /mnt/rhome/paa/pedestrian/Rethinking_of_PAR/data/PA100k/dataset_all.pkl \
--images_root /mnt/rhome/paa/pedestrian/Rethinking_of_PAR/data/PA100k/data \
--out_root /mnt/rhome/paa/pedestrian/datasetForFID \
--mode symlink \
--dry_run
# Execute: create symlinks into train/ and test/
python tools/dataset_splitters/create_dataset_split.py \
--dataset PA100k \
--pkl /mnt/rhome/paa/pedestrian/Rethinking_of_PAR/data/PA100k/dataset_all.pkl \
--images_root /mnt/rhome/paa/pedestrian/Rethinking_of_PAR/data/PA100k/data \
--out_root /mnt/rhome/paa/pedestrian/datasetForFID \
--mode symlinkThis will create the following structure if it doesn't exist already:
/mnt/rhome/paa/pedestrian/datasetForFID/
βββ PA100k/
βββ train/ # or trainval/ for RAPv1
βββ test/
You can switch --mode to hardlink or copy if you prefer. Once created, use these paths as path_dataset in your stage configs:
- Train:
/mnt/rhome/paa/pedestrian/datasetForFID/PA100k/train/ - Test:
/mnt/rhome/paa/pedestrian/datasetForFID/PA100k/test/
Use --dataset / dataset_name with:
PA100k, PETA, PETAzs, RAPv1, RAPv2, RAPzs
Before running LoRA training or prompt-based generation, you typically need:
β
metadata.jsonl (captions/prompts for each image)
Optional: include attribute vectors with --save-vectors.
Example:
# Run from repo root (recommended)
PYTHONPATH=. python src/lora_training/getMetadataDataset.py \
--module customDatasets.RAPzsAll \
--class RAPzsDatasetAll \
--pathDataset /path/to/RAPzs/ \
--num-images 17062 \
--save-vectorsGiven --path_syn <OUTPUT_DIR> (or config equivalent), you should get:
<path_syn>/condImgs/β conditional (real) images<path_syn>/generatedImgs/β synthetic images<path_syn>/generated.csvβ prompt + filenames (+ optional vectors)
Scores are written under folders like:
-
<dataset>_<prompting>_<score_name>_<strategy>_scores/scores_train.xlsx(+.csv)scores_test.xlsx(+.csv)
Synthetic scoring typically creates:
scores_syn.xlsx/scores_syn.csv(depending on config)
Artifacts under folders like:
-
<dataset>_<prompting>_<score_name>_<strategy>_<clf_tag>_si/artifacts/classifier.pklclassifier_tag.txttrain_predictions.csvtest_predictions.csvpseudolabels_syn.csv
Youβre likely running a file directly like:
python src/stage_c_pseudolabeling/run_stage_c.py ...β Fix: run as a module from repo root:
PYTHONPATH=. python -m src.stage_c_pseudolabeling.run_stage_c --config configs/stage_c_train.yamlRun tests from repo root with:
PYTHONPATH=. pytest -qThis often happens when mixing python file.py and python -m module.
β
Stick to python -m ... consistently.
- Prefer running from repo root.
- Use YAML configs for reproducibility.
- Use
python -m ...to avoid import issues.
Happy experimenting! πβ¨