HPT++

February 2, 2025 ยท View on GitHub

:rocket: Contributions

  • We refine the knowledge generation process, producing and merging coarse-grained and fine-grained descriptions into multi-granularity descriptions for generating structured graphs with more discriminative semantics.
  • We experiment with various methods to model structured information and re-design the relationship-driven attention re-weighting module, enabling re-weighting of attention maps according to relationships between key elements with a predefined ratio.
  • To avoid over-fitting in downstream generalization tasks, we incorporate a consistency constraint between prompted and pre-trained text encoders to learn more robust representations. These improvements and comparisons to HPT are validated with extensive experiments.

๐Ÿ“Š Results

Base-to-New Generalization

Results reported below show average accuracy for base and new classes across 11 recognition datasets averaged over 3 seeds. Please refer to our paper for more numerical results

NameBase AccuracyNew AccuracyHarmonic Mean
CLIP69.3474.2271.70
CoOp82.6963.2271.66
CoCoOp80.4771.6975.83
MaPLe82.2875.1478.55
HPT84.3276.8680.23
HPT++84.1377.9980.95

Cross-Dataset Evaluation

Results reported below show accuracy for the source dataset ImageNet and 4 ImageNet-variant datasets averaged over 3 seeds.

ImNetCaltechPetsCarsFlowersFoodAircraftSUN397DTDEuroSATUCFAverage
CLIP71.5193.7089.1464.5168.7185.3018.4764.1541.9246.3966.5563.88
CoCoOp71.0294.4390.1465.3271.8886.0622.9467.3645.7345.3768.2165.74
MaPLe70.7293.5390.4965.5772.2386.2024.7467.0146.4948.0668.6966.30
HPT71.7294.2092.6366.3374.8486.2125.6868.7550.8747.3670.5067.74
HPT++71.8194.0292.1665.5572.4386.3428.6068.7851.0250.7670.5368.02

Domain Generalization

Results reported below show accuracy for the source dataset ImageNet and the other 10 target datasets averaged over 3 seeds.

ImageNetImageNetV2ImageNet-SImageNet-AImageNet-RAverage
CLIP66.7360.8346.1547.7773.9657.17
CoOp71.5164.2047.9949.7175.2159.28
CoCoOp71.0264.0748.7550.6376.1859.90
MaPLe70.7264.0749.1550.9076.9860.26
HPT71.7265.2549.3650.8577.3860.71
HPT++71.8165.3149.2851.1877.5260.82

๐Ÿ—‚๏ธ Corpus Preparation

Our Multi-Granularity Knowledge Generation mechanism is implemented on Llama3-8B (Local deployment) and GPT-3.5-turbo (Calling the API), with the main experimental results obtained from Llama3. The generated corpus is available in the directories ./data/corpus (for Llama3) and ./data/corpus_gpt (for GPT-3.5). To customize the generation process, please check the relevant code in ./llms, as instructed below.

Llama3

Please follow the official Llama website instructions to deploy Llama3-8B locally and download the model files to ./llms/meta-llama.

./meta-llama
โ””โ”€โ”€ Meta-Llama-3-8B-Instruct
    โ”œโ”€โ”€ config.json
    โ”œโ”€โ”€ generation_config.json
    โ”œโ”€โ”€ gitattributes
    โ”œโ”€โ”€ LICENSE
    โ”œโ”€โ”€ model-00001-of-00004.safetensors
    โ”œโ”€โ”€ model-00002-of-00004.safetensors
    โ”œโ”€โ”€ model-00003-of-00004.safetensors
    โ”œโ”€โ”€ model-00004-of-00004.safetensors
    โ”œโ”€โ”€ model.safetensors.index.json
    โ”œโ”€โ”€ README.md
    โ”œโ”€โ”€ special_tokens_map.json
    โ”œโ”€โ”€ tokenizer_config.json
    โ”œโ”€โ”€ tokenizer.json
    โ””โ”€โ”€ USE_POLICY.md

Run the following script to generate the corpus under ./data/corpus folder.

python test_llama.py

GPT-3.5

Please enter your API_KEY and ENDPOINT for GPT-3.5-turbo in ./llama/test_gpt.py. Run the following script to generate the corpus under ./data/corpus_gpt folder.

python test_gpt.py

This project defaults to using the corpus generated by Llama3. If you need to switch to the corpus generated by GPT-3.5, please modify the path in the ./trainer/hpt_plus.py file.

๐Ÿงช Training and Evaluation

The training and evaluation scripts are consistent with those used in HPT. For detailed instructions on training and evaluation, please refer to RUN.md, ensuring that the script root is updated from ./scripts/hpt to ./scripts/hpt_plus.