nicolas-dufour commited on
Commit
8a50f08
·
verified ·
1 Parent(s): 54eccc7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +150 -3
README.md CHANGED
@@ -9,6 +9,153 @@ tags:
9
  - pytorch_model_hub_mixin
10
  ---
11
 
12
- This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
13
- - Library: https://github.com/nicolas-dufour/CAD
14
- - Docs: [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  - pytorch_model_hub_mixin
10
  ---
11
 
12
+ - Library: https://github.com/nicolas-dufour/CAD
13
+ <div align="center">
14
+
15
+ # Don’t drop your samples! Coherence-aware training benefits Conditional diffusion
16
+
17
+ <a href="https://nicolas-dufour.github.io/" >Nicolas Dufour</a>, <a href="https://scholar.google.com/citations?user=n_C2h-QAAAAJ&hl=fr&oi=ao" >Victor Besnier</a>, <a href="https://vicky.kalogeiton.info/" >Vicky Kalogeiton</a>, <a href="https://davidpicard.github.io/" >David Picard</a>
18
+
19
+
20
+ ![CAD](https://nicolas-dufour.github.io/assets/publications/cad_cvpr/varying_coherence.png)
21
+
22
+ </div>
23
+ This repo has the code for the paper "Dont Drop Your samples: Coherence-aware training benefits Condition Diffusion" accepted at CVPR 2024 as a Highlight.
24
+
25
+ The core idea is that diffusion model is usually trained on noisy data. The usual solution is to filter massive datapools. We propose a new training method that leverages the coherence of the data to improve the training of diffusion models. We show that this method improves the quality of the generated samples on several datasets.
26
+
27
+ Project website: [https://nicolas-dufour.github.io/cad](https://nicolas-dufour.github.io/cad)
28
+
29
+ ## Install
30
+
31
+ To install, first create a conda env with python 3.10
32
+
33
+ ```bash
34
+ conda create -n cad python=3.10
35
+ ```
36
+ Activate the env
37
+
38
+ ```bash
39
+ conda activate cad
40
+ ```
41
+
42
+ For inference only,
43
+
44
+ ```bash
45
+ pip install cad-diffusion
46
+ ```
47
+
48
+ ## Pretrained models
49
+
50
+ To use the pretrained model do the following:
51
+ ```python
52
+ from cad import CADT2IPipeline
53
+
54
+ pipe = CADT2IPipeline("nicolas-dufour/CAD_256").to("cuda")
55
+
56
+ prompt = "An avocado armchair"
57
+
58
+ image = pipe(prompt, cfg=15)
59
+ ```
60
+
61
+ If you just want to download the models, not the sampling pipeline, you can do:
62
+
63
+ ```python
64
+ from cad import CAD
65
+
66
+ model = CAD.from_pretrained("nicolas-dufour/CAD_256")
67
+ ```
68
+
69
+ Models are hosted in the hugging face hub. The previous scripts download them automatically, but weights can be found at:
70
+
71
+ [https://huggingface.co/nicolas-dufour/CAD_256](https://huggingface.co/nicolas-dufour/CAD_256)
72
+
73
+ [https://huggingface.co/nicolas-dufour/CAD_512](https://huggingface.co/nicolas-dufour/CAD_512)
74
+
75
+ ## Using the Pipeline
76
+
77
+ The `CADT2IPipeline` class provides a comprehensive interface for generating images from text prompts. Here's a detailed guide on how to use it:
78
+
79
+ ### Basic Usage
80
+
81
+ ```python
82
+ from cad import CADT2IPipeline
83
+
84
+ # Initialize the pipeline
85
+ pipe = CADT2IPipeline("nicolas-dufour/CAD_512").to("cuda")
86
+
87
+ # Generate an image from a prompt
88
+ prompt = "An avocado armchair"
89
+ image = pipe(prompt, cfg=15)
90
+ ```
91
+
92
+ ### Advanced Configuration
93
+
94
+ The pipeline can be initialized with several customization options:
95
+
96
+ ```python
97
+ pipe = CADT2IPipeline(
98
+ model_path="nicolas-dufour/CAD_512",
99
+ sampler="ddim", # Options: "ddim", "ddpm", "dpm", "dpm_2S", "dpm_2M"
100
+ scheduler="sigmoid", # Options: "sigmoid", "cosine", "linear"
101
+ postprocessing="sd_1_5_vae", # Options: "consistency-decoder", "sd_1_5_vae"
102
+ scheduler_start=-3,
103
+ scheduler_end=3,
104
+ scheduler_tau=1.1,
105
+ device="cuda"
106
+ )
107
+ ```
108
+
109
+ ### Generation Parameters
110
+
111
+ The pipeline's `__call__` method accepts various parameters to control the generation process:
112
+
113
+ ```python
114
+ image = pipe(
115
+ cond="A beautiful landscape", # Text prompt or list of prompts
116
+ num_samples=4, # Number of images to generate
117
+ cfg=15, # Classifier-free guidance scale
118
+ guidance_type="constant", # Type of guidance: "constant", "linear"
119
+ guidance_start_step=0, # Step to start guidance
120
+ coherence_value=1.0, # Coherence value for sampling
121
+ uncoherence_value=0.0, # Uncoherence value for sampling
122
+ thresholding_type="clamp", # Type of thresholding: "clamp", "dynamic_thresholding", "per_channel_dynamic_thresholding"
123
+ clamp_value=1.0, # Clamp value for thresholding
124
+ thresholding_percentile=0.995 # Percentile for thresholding
125
+ )
126
+ ```
127
+
128
+ #### Guidance Types
129
+ - `constant`: Applies uniform guidance throughout the sampling process
130
+ - `linear`: Linearly increases guidance strength from start to end
131
+ - `exponential`: Exponentially increases guidance strength from start to end
132
+
133
+ #### Thresholding Types
134
+ - `clamp`: Clamps values to a fixed range using `clamp_value`
135
+ - `dynamic`: Dynamically adjusts thresholds based on the batch statistics
136
+ - `percentile`: Uses percentile-based thresholding with `thresholding_percentile`
137
+
138
+ ### Advanced Parameters
139
+
140
+ For more control over the generation process, you can also specify:
141
+
142
+ - `x_N`: Initial noise tensor
143
+ - `latents`: Previous latents for continuation
144
+ - `num_steps`: Custom number of sampling steps
145
+ - `sampler`: Custom sampler function
146
+ - `scheduler`: Custom scheduler function
147
+ - `guidance_start_step`: Step to start guidance
148
+ - `generator`: Random number generator for reproducibility
149
+ - `unconfident_prompt`: Custom unconfident prompt text
150
+
151
+ ## Citation
152
+ If you happen to use this repo in your experiments, you can acknowledge us by citing the following paper:
153
+
154
+ ```bibtex
155
+ @article{dufour2024dont,
156
+ title={Don’t drop your samples! Coherence-aware training benefits Conditional diffusion},
157
+ author={Nicolas Dufour and Victor Besnier and Vicky Kalogeiton and David Picard},
158
+ journal={CVPR}
159
+ year={2024}
160
+ }
161
+ ```