1: 
2: # Beyond One-Hot Labels: Semantic Mixing for Model Calibration (PyTorch)
3: 
4: ![PyTorch](https://img.shields.io/badge/PyTorch-%23EE4C2C.svg?style=for-the-badge&logo=PyTorch&logoColor=white)
5: ![Python](https://img.shields.io/badge/python-3.8%2B-blue.svg)
6: ![License](https://img.shields.io/badge/License-CC--BY--NC--4.0-lightgrey.svg)
7: 
8: Official PyTorch implementation of our ICLR 2025 paper **"Beyond One-Hot Labels: Semantic Mixing for Model Calibration"**.
9: 
10: 📄 [Read the full paper on arXiv](https://arxiv.org/pdf/2504.13548)
11: 
12: ## Table of Contents
13: - [Dependencies](#dependencies)
14: - [Getting Started](#getting-started)
15:   - [Augmented Samples](#augmented-samples)
16:   - [Sample Reannotation](#sample-reannotation)
17:   - [Training & Testing](#training--testing)
18: - [Citation](#citation)
19: - [Acknowledgements](#acknowledgements)
20: 
21: ## Dependencies
22: 
23: - Python ≥ 3.8
24: - PyTorch ≥ 1.8.1
25: 
26: **Setup Instructions:**
27: 1. Create a virtual environment
28: 2. Install dependencies:
29:    ```bash
30:    # For sample augmentation
31:    cd gen_edm_mix
32:    conda env create -f environment.yml
33:    
34:    # For training & testing
35:    pip install -r requirements.txt
36:    ```
37: 
38: ## Getting Started
39: 
40: ### Augmented Samples
41: 
42: 1. **Generate augmented samples:**
43:    ```bash
44:    cd gen_edm_mix
45:    sh run_mix.sh
46:    ```
47: 
48: 2. **Post-process to get image files:**
49:    ```bash
50:    python convert_pths.py
51:    ```
52:    Output will be saved in `gen_edm-mix/out_{dset}_imgs_mix`
53: 
54: ### Sample Reannotation
55: 
56: Run annotation for your dataset (e.g., CIFAR100):
57: ```bash
58: python annotate.py \
59:   --dset_name c100 [c10 | tiny] \
60:   --clip_path [CLIP_DOWNLOAD_PATH] \
61:   --train_path [TRAINING_IMAGES_PATH] \
62:   --mix_path ./gen_edm-mix/out_c10_imgs_mix
63: ```
64: 
65: Annotations will be saved at `annotations/clip_lam_anno_edm_{args.dset_name}.pth`
66: 
67: ### Training & Testing
68: 
69: 1. Configure your experiment:
70:    - Modify `configs/defaults.yaml` for dataset and model selection
71:    - Update paths in `configs/cifar100.yaml` (or corresponding dataset config)
72: 
73: 2. Start training with calibration tests:
74:    ```bash
75:    python train_net.py
76:    ```
77: 
78: ## Citation
79: 
80: If you use this work in your research, please cite:
81: 
82: ```bibtex
83: @article{luo2025beyond,
84:   title={Beyond One-Hot Labels: Semantic Mixing for Model Calibration},
85:   author={Luo, Haoyang and Tao, Linwei and Dong, Minjing and Xu, Chang},
86:   journal={arXiv preprint arXiv:2504.13548},
87:   year={2025}
88: }
89: ```
90: 
91: ## Acknowledgements
92: 
93: We are inspired by these excellent works:
94: 1. [RankMixup](https://github.com/cvlab-yonsei/RankMixup) [1]
95: 2. [EDM](https://github.com/NVlabs/edm) [2]
96: 3. [DM-Improves-AT](https://github.com/wzekai99/DM-Improves-AT) [3]
97: 
98: We thank the authors for sharing their code.
99: 
100: [1] Noh, J., Park, H., Lee, J., & Ham, B. (2023). Rankmixup: Ranking-based mixup training for network calibration. In Proceedings of the IEEE/CVF International Conference on Computer Vision (pp. 1358-1368).
101: 
102: [2] Karras, T., Aittala, M., Aila, T., & Laine, S. (2022). Elucidating the design space of diffusion-based generative models. Advances in Neural Information Processing Systems, 35, 26565-26577.
103: 
104: [3] Wang, Z., Pang, T., Du, C., Lin, M., Liu, W., & Yan, S. (2023, July). Better diffusion models further improve adversarial training. In International Conference on Machine Learning (pp. 36246-36263). PMLR.