<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tian Lan on Medium]]></title>
        <description><![CDATA[Stories by Tian Lan on Medium]]></description>
        <link>https://medium.com/@taran.lan?source=rss-cd77f5270b42------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mzfcuWjWUTD_N9hb9f6lSg@2x.jpeg</url>
            <title>Stories by Tian Lan on Medium</title>
            <link>https://medium.com/@taran.lan?source=rss-cd77f5270b42------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 05:44:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@taran.lan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Unlocking Diffusion Models: From Concept to Image and Video Generation]]></title>
            <link>https://medium.com/@taran.lan/2023-summary-of-diffusion-models-2370a264d6f1?source=rss-cd77f5270b42------2</link>
            <guid isPermaLink="false">https://medium.com/p/2370a264d6f1</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[diffusion-models]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[stable-diffusion]]></category>
            <dc:creator><![CDATA[Tian Lan]]></dc:creator>
            <pubDate>Tue, 26 Dec 2023 23:41:22 GMT</pubDate>
            <atom:updated>2023-12-27T17:44:36.253Z</atom:updated>
            <content:encoded><![CDATA[<p>2023 was an amazing year for diffusion models. Image generation has taken massive leaps forward and video generation starts to arrive. In this post, I will first go over the basics of diffusion models, and then provide a deep dive into a few exemplary models within the domains of text-to-image (T2I) and text-to-video (T2V).</p><h3>What are Diffusion Models?</h3><p>Diffusion models [1,2,3] are a class of generative models, inspired by physics (non-equilibrium thermodynamics). Similar to other generative models, diffusion models are used to generate new data that resemble the data on which they are trained.</p><p>Diffusion models consist of a <strong>forward diffusion process</strong> and a <strong>reverse diffusion process</strong>. The forward diffusion process destroys training data by iteratively adding Gaussian noise. The reverse diffusion process learns to recover the data by reversing the noising process step by step. After training, we can use the Diffusion Model to generate data by simply passing randomly sampled noise through the learned reverse diffusion process.</p><h3>Background</h3><p>The <strong>forward diffusion process</strong> is formulated as a Markov chain. This chain gradually injects Gaussian noise to the input image through a series of T steps, until all structures of the image are lost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*z1A3jycfhviDJPG0" /><figcaption>Forward diffusion process. [<a href="https://arxiv.org/pdf/2006.11239.pdf?ref=assemblyai.com">source</a>]</figcaption></figure><p>x0 is sampled from the real data distribution q(x). At each step t, we add Gaussian noise to xₜ₋₁, producing xₜ​ according to a normal distribution q(xₜ​​∣xₜ₋₁​) defined in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/0*ajNjQTdKpEhSNJuV" /></figure><p>βₜ determines the amount of noise to be added in each step. It can be either learned or fixed. For example, DDPM [3] chose a fixed linear schedule ranging <em>βₜ</em> from 0.0001 at timestep 0 to 0.02 at timestep T.</p><p>The goal of training a diffusion model is to learn the <strong>reverse diffusion process</strong>, i.e. recreate real samples from a Gaussian noise input. However, it poses a computational challenge that estimating q(xₜ₋₁​∣xₜ​) is intractable. Therefore, we leverage a parameterized model pθ to approximate these conditional probability distributions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6wykJWIcH03-kFDS" /><figcaption>Reverse diffusion process. [<a href="https://arxiv.org/pdf/2006.11239.pdf?ref=assemblyai.com">source</a>]</figcaption></figure><p>pθ(xₜ₋₁​∣xₜ​) is represented as a Gaussian, for which just the mean and variance are parameterized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/0*sod6YekeLfdKg1oO" /></figure><p>The training objective minimizes the KL divergence between the learned distribution <em>p</em> and the forward process posteriors <em>q</em>. Although one can train the model to directly predict µt (the mean of the forward process posteriors), the author of DDPM [3] found that training the model to predict the noise ϵ<strong><em> </em></strong>∼ N (0, I) yields more stable training and better results. The model is re-parameterized as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Dqmpko_xEmtVv1Q4" /></figure><p>To summarize, the role of the model is to predict the noise present in the image at every timestep t. The training process compares the predicted noise to the actual noise for calculating the loss function. During inference, the network starts from random Gaussian noise, then gradually removes the noise by predicting the noise present in the image at every timestep t.</p><h3>A Simple Illustration</h3><p>Given a batch of images, training consists of the following steps (the figure below shows a visual example of training):</p><ul><li>Sample a random timestep t for each training example and add Gaussian noise to the training example according to the noise scheduler.</li><li>Encode the timestep t into an embedding vector.</li><li>Given the noisy image and the time embedding, predict the noise present in the image.</li><li>Compare the predicted noise to the actual noise to produce the gradient and update the diffusion model’s parameters via backpropagation.</li></ul><p>These steps repeat until convergence. Note that different timesteps are sampled for the same image in different epochs, which allows the model to learn the reverse diffusion process at any timestep.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Enqb4CpwkhLn_iAK" /><figcaption>An illustration of the training process. [<a href="https://medium.com/@steinsfu/stable-diffusion-clearly-explained-ed008044e07e">source</a>]</figcaption></figure><p>Sampling starts from pure Gaussian noise at the last timestep T. At every timestep t, it predicts the noise present in the image. Then it subtracts a fraction of the predicted noise to generate the image at the previous timestep t-1. This process repeats for T steps until a new image is generated at timestep 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IGbY35EH1_kA0ZYY" /><figcaption>An illustration of the denoising process. [<a href="https://blog.marvik.ai/2023/11/28/an-introduction-to-diffusion-models-and-stable-diffusion/">source</a>]</figcaption></figure><h3>Text to Image (T2I)</h3><p>The text-to-image (T2I) models have taken massive leaps forward in 2023, the latest T2I models include: <a href="https://openai.com/dall-e-3">DALL-E 3</a>, <a href="https://stablediffusionxl.com/">Stable Diffusion XL</a>, <a href="https://deepmind.google/technologies/imagen-2/">Imagen 2</a>, <a href="https://aituts.com/midjourney-versions/">Midjourney V6</a>. In the last section, we introduced diffusion models that use random noise as input to generate an image. The model does not have any guided information on what image will be generated. In this section, we will introduce conditioning inputs such as text descriptions into the model so that the model will generate images based on the text prompts.</p><p>In the following, we use <a href="https://arxiv.org/pdf/2112.10752.pdf">Latent Diffusion Models</a> (LDM) as an example to explain the basics of T2I. A remarkable breakthrough in LDM is the “conditioning” mechanism, which feeds additional information such as text prompts into the image generation process. The architecture of LDM is shown in the following figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AEPYjArUGs78tL-C" /><figcaption>An illustration of the Latent Diffusion Models. [adapted from <a href="https://arxiv.org/pdf/2112.10752.pdf">source</a>]</figcaption></figure><p>The steps of LDM are explained the following (they are also labeled in the above figure):</p><ol><li>LDM runs the diffusion process not in the pixel space, but in the latent space. The input image is compressed into the latent space through an encoder. It speeds up the image generation process and lowers the training cost.</li><li>The forward diffusion process also runs in the latent space. The Gaussian noise is iteratively added to the latent representations.</li><li>The conditioning inputs are compressed into embedding vectors through an encoder. Here we use text prompts as an example, but the conditioning inputs aren’t limited to text.</li><li>The text embeddings are fed into the denoising model through cross-attention.</li><li>Similar to the standard diffusion models, at each step t, the U-Net predicts the noise present in the image, and then removes a fraction of the predicted noise to obtain the image at timestep t-1. Both the image and the predicted noise are in the latent space, instead of the pixel space.</li><li>This denoising process repeats for T steps and outputs the image representation z in the latent space.</li><li>In the end, the decoder transforms the image from the latent space to the pixel space.</li></ol><p><strong>Reading materials</strong></p><p><a href="https://arxiv.org/pdf/2302.05543.pdf">ControlNet</a>: Diffusion model based T2I are incredibly powerful, but exerting control via just a text prompt can be limited and imprecise. ControlNet offers a far greater degree of control, e.g., edges, depth, segmentation, human pose, etc., over the output of T2I diffusion models.</p><p><a href="https://arxiv.org/abs/2106.09685">LoRA</a>: It was originally developed for parameter-efficient fine-tuning of pretrained LLMs. LoRA freezes the pre-trained model weights and inserts small, low-rank matrices into the base model, greatly reducing the trainable parameters for downstream tasks. The technique is generic and has been introduced in computer vision to fine-tune diffusion models (an <a href="https://github.com/cloneofsimo/lora">implementation</a> of LoRA fine-tuning on stable diffusion).</p><h3>Text to Video (T2V)</h3><p>Generating high quality videos from text has been considered as an extremely challenging task in computer vision. Compared to T2I, T2V requires modeling a higher dimensional spatiotemporal space while still being conditioned only on a text prompt. Over the year of 2023, the success of T2I diffusion models has been extended to the video domain. In the following, we will go over <a href="https://static1.squarespace.com/static/6213c340453c3f502425776e/t/655ce779b9d47d342a93c890/1700587395994/stable_video_diffusion.pdf">Stable Video Diffusion (SVD)</a>, the latest T2V model released by Stability AI.</p><p>SVD adopts the architecture of the Latent Video Diffusion Models [<a href="https://arxiv.org/pdf/2304.08818.pdf">5</a>, <a href="https://arxiv.org/pdf/2209.14792.pdf">6</a>]. The architecture inserts temporal layers into the text-to-image LDMs that we reviewed in the last section. Specifically, a 1D temporal convolution layer is added after every spatial convolution, and a 1D temporal attention layer after every spatial attention layer. The architecture is shown in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9qAz607bnd9i4BNw" /><figcaption>An illustration of the space-time U-Net. [adapted from <a href="https://arxiv.org/pdf/2112.10752.pdf">source</a>]. In the figure, we mark the input tensor shape of each convolution and attention block.</figcaption></figure><p>The details of the space-time U-Net architecture are summarized in the following:</p><ul><li><strong>Space-time convolution.</strong> It adopts the 2+1D architecture — a 1D convolution block is stacked after each 2D convolution block. Given an input tensor (video) of shape BxTxCxHxW (batch, frames, channels, height, width), the temporal axis is shifted into the batch dimension, so that the 2D conv layers interpret the video as a batch of images. After each 2D conv layer, the tensor is reshaped back to the temporal dimension of the video. The 1D conv is performed on the temporal axis of the video.</li><li><strong>Space-time attention.</strong> Adding temporal dimension to the attention layers is infeasible in terms of memory consumption. Similar to the convolution layers, the architecture adopts a factorized space-time attention. The 2D attention block in U-Net remains as attention over space. After that, a 1D attention block is inserted to perform attention over time, where the spatial dimension (HxW) is shifted into the batch dimension. A relative positional embedding is inserted into the 1D attention block so that the network is aware of the ordering of frames.</li></ul><p>Next, we summarize the main steps of Stable Video Diffusion:</p><ul><li><strong>Stage I. Image pretraining.</strong> Video diffusion models still rely on pretrained image diffusion models as initialization — training from scratch doesn’t work. The spatial layers are frozen with pretrained image model weights, only the temporal layers’ parameters are updated.</li><li><strong>Stage II. Data curation and video model pretraining.</strong> The video pretraining dataset is carefully curated. The initial dataset (after applying cut detection) contains 580M video clips. They are annotated with three captioning methods: an image captioner that annotates the middle frame, a video captioner that annotates the video, an LLM that summarizes the first two captions. After that, a series of filtering algorithms are introduced to remove unwanted examples, the final pretraining dataset consists of 152M clips, about ¼ of the original dataset.</li><li><strong>Stage III. High quality video fine-tuning. </strong>Fine-tuning is done on a smaller 250K video dataset, at high resolution (in contrast to pretraining on low-res videos).</li></ul><p><strong>Reading materials</strong></p><p>There are a lot of recent works on video diffusion models and T2V. We list a couple of representative ones below. We recommend watching the <a href="https://www.youtube.com/watch?v=0K56LA821ys">Video diffusion model tutorial</a> for a more thorough understanding of this domain.</p><p><a href="https://arxiv.org/pdf/2209.14792.pdf">Make-A-Video</a></p><p><a href="https://arxiv.org/pdf/2204.03458.pdf">Video Diffusion Models</a></p><p><a href="https://emu-video.metademolab.com/">Emu video</a></p><p><a href="https://sites.research.google/videopoet/">VideoPoet</a> (non diffusion model)</p><h3>References</h3><p>[1] Jascha Sohl-Dickstein et al. <a href="https://arxiv.org/abs/1503.03585">“Deep Unsupervised Learning using Nonequilibrium Thermodynamics.”</a> ICML 2015.</p><p>[2] Yang Song &amp; Stefano Ermon. <a href="https://arxiv.org/abs/1907.05600">“Generative modeling by estimating gradients of the data distribution.”</a> NeurIPS 2019.</p><p>[3] Jonathan Ho et al. <a href="https://arxiv.org/abs/2006.11239">“Denoising diffusion probabilistic models.”</a> arxiv Preprint arxiv:2006.11239 (2020).</p><p>[4] Rombach &amp; Blattmann, et al. <a href="https://arxiv.org/abs/2112.10752">“High-Resolution Image Synthesis with Latent Diffusion Models.”</a> CVPR 2022</p><p>[5] Lvmin Zhang et al. <a href="https://openaccess.thecvf.com/content/ICCV2023/papers/Zhang_Adding_Conditional_Control_to_Text-to-Image_Diffusion_Models_ICCV_2023_paper.pdf">“Adding Conditional Control to Text-to-Image Diffusion Models”</a>. ICCV 2023.</p><p>[6] Edward Hu et al. <a href="https://arxiv.org/pdf/2106.09685.pdf">“LoRA: Low-Rank Adaptation of Large Language Models”</a>. CoRR 2021.</p><p>[7] Andreas Blattmann et al. <a href="https://arxiv.org/abs/2311.15127">“Stable Video Diffusion: Scaling Latent Video Diffusion Models to Large Datasets”.</a> arxiv:2311.15127 (2023)</p><p>[8] Andreas Blattmann et al. “<a href="https://arxiv.org/abs/2304.08818">Align your Latents: High-Resolution Video Synthesis with Latent Diffusion Models</a>”. CVPR 2023</p><p>[9] Uriel Singer et al. <a href="https://openreview.net/pdf?id=nJfylDvgzlq">“Make-A-Video: Text-to-Video Generation without Text-Video Data”.</a> ICLR 2023</p><p>[10] Jonathan Ho et al. <a href="https://arxiv.org/abs/2204.03458">“Video Diffusion Models”.</a> arXiv preprint arXiv:2204.03458, 2022</p><p>[11] Rohit Girdhar et al. <a href="https://arxiv.org/abs/2311.10709">“EMU VIDEO: Factorizing Text-to-Video Generation by Explicit Image Conditioning.”</a> arXiv:2311.10709, 2023</p><p>[12] <a href="https://blog.marvik.ai/2023/11/28/an-introduction-to-diffusion-models-and-stable-diffusion/">An Introduction to Diffusion Models and Stable Diffusion</a> Ignacio Aristimuño, 2023</p><p>[13] <a href="https://lilianweng.github.io/posts/2021-07-11-diffusion-models/">What are Diffusion Models?</a>, Lilian Weng, 2022</p><p>[14] <a href="https://www.youtube.com/watch?v=0K56LA821ys">Tutorial: Video Diffusion Models.</a> Mike Shou, 2023</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2370a264d6f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>