{"id":20599641,"url":"https://github.com/adamdad/repfusion","last_synced_at":"2025-10-09T17:02:22.411Z","repository":{"id":198655180,"uuid":"614373418","full_name":"Adamdad/Repfusion","owner":"Adamdad","description":null,"archived":false,"fork":false,"pushed_at":"2023-10-06T07:53:46.000Z","size":1672,"stargazers_count":54,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T00:41:51.653Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Adamdad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-15T13:09:19.000Z","updated_at":"2024-12-06T05:55:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"c30292a4-17f4-49ad-a967-a27be2ebb8b0","html_url":"https://github.com/Adamdad/Repfusion","commit_stats":null,"previous_names":["adamdad/repfusion"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2FRepfusion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2FRepfusion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2FRepfusion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2FRepfusion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Adamdad","download_url":"https://codeload.github.com/Adamdad/Repfusion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986270,"owners_count":21194024,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T08:33:38.906Z","updated_at":"2025-10-09T17:02:22.336Z","avatar_url":"https://github.com/Adamdad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Diffusion Model as Representation Learner\n\nThis repository contains the official implementation of the ICCV 2023 paper\n\n**Diffusion Model as Representation Learner**\nXingyi Yang, Xinchao Wang\n\n[[arxiv](https://arxiv.org/abs/2308.10916)] [[code](https://github.com/Adamdad/Repfusion)]\n\n![tiser](assets/concept.jpg)\n\n\u003e In this paper, we conduct an in-depth investigation of the representation power of DPMs, and propose a novel knowledge transfer method that leverages the knowledge acquired by generative DPMs for recognition tasks. We introduce a novel knowledge transfer paradigm named RepFusion. Our paradigm  extracts representations at different time steps from off-the-shelf DPMs and dynamically employs them as supervision for student networks, in which the optimal time is determined through reinforcement learning. \n\n## File Orgnizations\n\nBasicly, we contain the code for distillation, the 3 downstream tasks including `classification`, `segmentation`, `landmark`\n\n```\n             \n├── classification_distill/ \n    # code for image classification \n    # and knowledge distillation\n    ├── configs/\n        ├── \u003cDATASET\u003e-\u003cDISTILL_LOSS\u003e/\n            ddpm-\u003cBACKBONE\u003e_\u003cDISTILL_LOSS\u003e.py\n            # config file for Repfussion on \u003cDATASET\u003e \n            # with \u003cDISTILL_LOSS\u003e as loss function \n            # and \u003cBACKBONE\u003e as architecture\n        ├── baseline/\n            \u003cBACKBONE\u003e_\u003cBATCHSIZE\u003e_\u003cDATASET\u003e_finetune.py\n    ├── mmcls/\n        ├── models/\n            ├── guided_diffusion/\n                # code taken from the guided diffusion repo\n            ├── classifiers/\n                ├── kd.py\n                    # distillation baselines\n                ├── repfusion.py\n                    # core code for distillation from diffusion model\n\n\n├── landmark/\n    # code for facial landmark detection \n    ├── configs/face/2d_kpt_sview_rgb_img/topdown_heatmap/wflw\n        \u003cBACKBONE\u003e_wflw_256x256_baseline_\u003cBATCHSIZE\u003e.py\n        \u003cBACKBONE\u003e_wflw_256x256_\u003cBATCHSIZE\u003e_repfussion.py\n            \n\n├── segmentation/\n    # code for face parsing\n    ├── configs/\n        ├── celebahq_mask/\n            bisenetv1_\u003cBACKBONE\u003e_lr5e-3_2x8_448x448_160k_coco-celebahq_mask_baseline.py\n            bisenetv1_\u003cBACKBONE\u003e_lr5e-3_2x8_448x448_160k_coco-celebahq_mask_repfusion.py\n\n```\n\n## Installation\nWe mainly depend on 4 packages, namely \n1. `mmclassification`. Please install the enviroment using [INSTALL](https://mmclassification.readthedocs.io/en/latest/install.html)\n2. `mmsegmentation`. Please install the enviroment using [INSTALL](https://mmsegmentation.readthedocs.io/en/latest/get_started.html)\n3. `mmpose`.  Please install the enviroment using [INSTALL](https://mmpose.readthedocs.io/en/v0.29.0/install.html)\n4. `diffusers`. Install via `pip install --upgrade diffusers[torch]`, or go to the [official repo](https://github.com/huggingface/diffusers) for help.\n\n## Data Preparation\nWe use 4 datasets in our paper. Please put them all under the `data/\u003cDATASET\u003e`\n\n   \n1. [CelabAMask-HQ](https://github.com/switchablenorms/CelebAMask-HQ), and please follow the guideline on official repo.\n2. [WFLW](https://wywu.github.io/projects/LAB/WFLW.html). For WFLW data, please download images from [WFLW Dataset](https://wywu.github.io/projects/LAB/WFLW.html). Please download the annotation files from [wflw_annotations](https://download.openmmlab.com/mmpose/datasets/wflw_annotations.tar). \n3. [TinyImageNet](http://cs231n.stanford.edu/tiny-imagenet-200.zip), please download dataset using this [script](https://github.com/DennisHanyuanXu/Tiny-ImageNet/blob/master/prep.sh).\n4. [CIAFR10](https://www.cs.toronto.edu/~kriz/cifar.html), `mmcls` will automatically download it for you. \n\n\n## Teacher Checkpoints\n- For DPMs based on huggingface, the model will be automatically downloaded. Just make sure you gets the correct model id, e.g.\n\n- For DPM on Tiny-ImageNet, we download it from the [guided-diffusion](https://github.com/openai/guided-diffusion) repo from the link [weight](https://openaipublic.blob.core.windows.net/diffusion/jul-2021/64x64_diffusion.pt).\n   \n\n## Training\n- We first do distillation from a trained DPM\n\n```shell script\n# \u003cCONFIG_NAME\u003e: config path for distillation \n# \u003cGPU_NUMS\u003e: num of gpus for training\ncd classification_distill\nbash tools/dist_train.sh \u003cCONFIG_NAME\u003e \u003cGPU_NUMS\u003e\n```\n- Put the saved checkpoint in config as installization for downstream training. For example\n```python\nmodel = dict(\n    ...\n    backbone=dict(\n        ...\n        backbone_cfg=dict(\n            ...\n            init_cfg=dict(\n                type='Pretrained', \n                checkpoint=\u003cCHECKPOINT_PATH\u003e , \n                # Put the disilled checkpoint hear\n                prefix='student.backbone.')\n            )\n        ), \n    )\n```\n\n\n- Do downstream training\n\n```shell script\n# \u003cCONFIG_NAME\u003e: config path for distillation \n# \u003cGPU_NUMS\u003e: num of gpus for training\n# \u003cTASK_NAME\u003e: either 'classification_distill', 'segmentation' or 'landmark'\ncd \u003cTASK_NAME\u003e\nbash tools/dist_train.sh \u003cCONFIG_NAME\u003e \u003cGPU_NUMS\u003e\n```\n\n## Citation\n```bibtex\n@article{yang2023diffusion,\n    author    = {Xingyi Yang, Xinchao Wang},\n    title     = {Diffusion Model as Representation Learner},\n    journal   = {International Conference on Computer Vision (ICCV)},\n    year      = {2023},\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamdad%2Frepfusion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamdad%2Frepfusion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamdad%2Frepfusion/lists"}