Skip to content

Commit f6af9f4

Browse files
authored
Improve clarity in denoising sections of index.html
Revised descriptions and code snippets for clarity in sections on one-step and iterative denoising.
1 parent a2bad34 commit f6af9f4

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

project-5/index.html

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ <h4>t = 750</h4>
230230
<section id="part-1-3">
231231
<h2>Part 1.3 – Implementing One Step Denoising</h2>
232232

233-
A much more effective method is to use a pretrained diffusion model. Using <code>stage_1.unet</code>, we can estimate the amount of noise in the noisy image. With the forward equation, we can solve for x<sub>0</sub> (the original image) given the timestamp <code>t</code>:
233+
A much more effective method is to use a pretrained diffusion model. Using <code>stage_1.unet</code>, we can estimate the amount of noise in the noisy image. With the forward equation, we can solve for <code>x<sub>0</sub></code> (the original image) given the timestamp <code>t</code>:
234234

235235
<div class="subsection">
236236
<pre><code>at_x0 = im_noisy_cpu - (1 - alpha_cumprod).sqrt() * noise_est
@@ -300,22 +300,32 @@ <h2>Part 1.4 – Iterative Denoising</h2>
300300

301301
Instead of using one step, we can obtain better results by iterativly denoising from step <code>t</code> until step 0. However, this means running the diffusion model 1000 times in the worst case, which is slow and costly.<br>
302302
<br>
303-
Fortunately, we can speed up the computation by first defining series of strided timestamps, starting at close to 1000 and ending at 0. For the examples below, we will use <code>strided_timestamps = list(range(990, -1, -30))</code>. Then, we can use the formula
303+
Fortunately, we can speed up the computation by first defining series of strided timestamps, starting at close to 1000 and ending at 0. For the examples below, we will use <code>strided_timestamps = [990, 960, ..., 30, 0]</code>. Then, we can use the formula
304304

305305
<div class="image-row">
306306
<figure>
307-
<img src="images/campanile.png" alt="campanile.png" />
307+
<img src="images/equation.png" alt="equation.png" />
308308
</figure>
309309
</div>
310310

311+
to compute <code>x</code> at timestamp <code>T</code>, where <code>T</code> (or <code>prev_t</code>) is the next timestamp after the current timestamp <code>t</code> in <code>strided_timestamps</code>. First, we compute the constants:
312+
311313
<div class="subsection">
312-
<h3>Code: iterative_denoise</h3>
313-
<pre><code># TODO
314-
# def iterative_denoise(im_noisy, i_start, timesteps, ...):
315-
# # Loop from timesteps[i_start] down to 0 using Equation 3
316-
# return clean_image</code></pre>
314+
<pre><code>alpha_cumprod = alphas_cumprod[t]
315+
alpha_cumprod_prev = alphas_cumprod[prev_t]
316+
alpha_t = alpha_cumprod / alpha_cumprod_prev
317+
beta_t = 1 - alpha_t</code></pre>
317318
</div>
318319

320+
Then, we can compute <code>x<sub>T</sub></code> by using the one-step estimate of <code>x<sub>0</sub></code> as follows:
321+
322+
<div class="subsection">
323+
<pre><code>x_0 = (image - (1 - alpha_cumprod).sqrt() * noise_est) / alpha_cumprod.sqrt()
324+
term_1 = alpha_cumprod_prev.sqrt() * beta_t
325+
term_2 = alpha_t.sqrt() * (1 - alpha_cumprod_prev)
326+
pred_pi_nonoise = (term_1 * x_0 + term_2 * image) / (1 - alpha_cumprod)
327+
pred_prev_image = add_variance(predicted_variance, t, pred_pi_nonoise)</code></pre></div>
328+
319329
<div class="subsection">
320330
<h3>Denoising Loop Visualizations (i_start = 10)</h3>
321331

0 commit comments

Comments
 (0)