RePaintScheduler¶
RePaintScheduler
is a DDPM-based inpainting scheduler for unsupervised inpainting with extreme masks. It is designed to be used with the [RePaintPipeline
], and it is based on the paper RePaint: Inpainting using Denoising Diffusion Probabilistic Models by Andreas Lugmayr et al.
The abstract from the paper is:
Free-form inpainting is the task of adding new content to an image in the regions specified by an arbitrary binary mask. Most existing approaches train for a certain distribution of masks, which limits their generalization capabilities to unseen mask types. Furthermore, training with pixel-wise and perceptual losses often leads to simple textural extensions towards the missing areas instead of semantically meaningful generation. In this work, we propose RePaint: A Denoising Diffusion Probabilistic Model (DDPM) based inpainting approach that is applicable to even extreme masks. We employ a pretrained unconditional DDPM as the generative prior. To condition the generation process, we only alter the reverse diffusion iterations by sampling the unmasked regions using the given image information. Since this technique does not modify or condition the original DDPM network itself, the model produces high-quality and diverse output images for any inpainting form. We validate our method for both faces and general-purpose image inpainting using standard and extreme masks. RePaint outperforms state-of-the-art Autoregressive, and GAN approaches for at least five out of six mask distributions. GitHub Repository: this http URL.
The original implementation can be found at andreas128/RePaint.
mindone.diffusers.RePaintScheduler
¶
Bases: SchedulerMixin
, ConfigMixin
RePaintScheduler
is a scheduler for DDPM inpainting inside a given mask.
This model inherits from [SchedulerMixin
] and [ConfigMixin
]. Check the superclass documentation for the generic
methods the library implements for all schedulers such as loading and saving.
PARAMETER | DESCRIPTION |
---|---|
num_train_timesteps |
The number of diffusion steps to train the model.
TYPE:
|
beta_start |
The starting
TYPE:
|
beta_end |
The final
TYPE:
|
beta_schedule |
The beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose from
TYPE:
|
eta |
The weight of noise for added noise in diffusion step. If its value is between 0.0 and 1.0 it corresponds to the DDIM scheduler, and if its value is between -0.0 and 1.0 it corresponds to the DDPM scheduler.
TYPE:
|
trained_betas |
Pass an array of betas directly to the constructor to bypass
TYPE:
|
clip_sample |
Clip the predicted sample between -1 and 1 for numerical stability.
TYPE:
|
Source code in mindone/diffusers/schedulers/scheduling_repaint.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
mindone.diffusers.RePaintScheduler.scale_model_input(sample, timestep=None)
¶
Ensures interchangeability with schedulers that need to scale the denoising model input depending on the current timestep.
PARAMETER | DESCRIPTION |
---|---|
sample |
The input sample.
TYPE:
|
timestep |
The current timestep in the diffusion chain.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
|
Source code in mindone/diffusers/schedulers/scheduling_repaint.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
mindone.diffusers.RePaintScheduler.set_timesteps(num_inference_steps, jump_length=10, jump_n_sample=10)
¶
Sets the discrete timesteps used for the diffusion chain (to be run before inference).
PARAMETER | DESCRIPTION |
---|---|
num_inference_steps |
The number of diffusion steps used when generating samples with a pre-trained model. If used,
TYPE:
|
jump_length |
The number of steps taken forward in time before going backward in time for a single jump (“j” in RePaint paper). Take a look at Figure 9 and 10 in the paper.
TYPE:
|
jump_n_sample |
The number of times to make a forward time jump for a given chosen time sample. Take a look at Figure 9 and 10 in the paper.
TYPE:
|
Source code in mindone/diffusers/schedulers/scheduling_repaint.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
mindone.diffusers.RePaintScheduler.step(model_output, timestep, sample, original_image, mask, generator=None, return_dict=False)
¶
Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusion process from the learned model outputs (most often the predicted noise).
PARAMETER | DESCRIPTION |
---|---|
model_output |
The direct output from learned diffusion model.
TYPE:
|
timestep |
The current discrete timestep in the diffusion chain.
TYPE:
|
sample |
A current instance of a sample created by the diffusion process.
TYPE:
|
original_image |
The original image to inpaint on.
TYPE:
|
mask |
The mask where a value of 0.0 indicates which part of the original image to inpaint.
TYPE:
|
generator |
A random number generator.
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[RePaintSchedulerOutput, Tuple]
|
[ |
Source code in mindone/diffusers/schedulers/scheduling_repaint.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
mindone.diffusers.schedulers.scheduling_repaint.RePaintSchedulerOutput
dataclass
¶
Bases: BaseOutput
Output class for the scheduler's step function output.
PARAMETER | DESCRIPTION |
---|---|
prev_sample |
Computed sample (x_{t-1}) of previous timestep.
TYPE:
|
pred_original_sample |
The predicted denoised sample (x_{0}) based on the model output from
the current timestep.
TYPE:
|
Source code in mindone/diffusers/schedulers/scheduling_repaint.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|