Your AI powered learning assistant

Introduction

00:00:00

Introduction and Course Overview Lesson 9 of "Deep Learning Foundations to Stable Diffusion" is the first lesson of Part 2, which focuses on generative models. The course assumes prior knowledge in deep learning basics and recommends completing Part 1 before starting this course.

Playing with Stable Diffusion The first part of Lesson 9 involves playing around with Stable Diffusion, but details are subject to change due to the rapid pace at which research is progressing. Despite these changes, foundational knowledge remains important for keeping up with new developments in deep learning research.

This course vs DALL-E 2

00:06:38

The course introduces Stable Diffusion, a model similar to Dall-e 2 that allows users to put any object or person into an image using Dreambooth. The instructor acknowledges the contributions of Fast AI alumni in creating detailed educational material about Stable Diffusion and working on its development for medical applications.

How to take full advantage of this course

00:10:38

The course website, course.fast.ai, provides all the necessary materials for each lesson including links to notebooks and details. For further information and discussion forums.fast.ai can be accessed where every lesson has a chat with even more resources available. It is important to utilize these resources in order to fully understand the content provided in the video lectures.

Cloud computing options

00:12:14

The popularity of Stable Diffusion has led to rapidly changing compute options, with Colab now charging by the hour for most usage. Other recommended cloud computing providers include Paperspace Gradient, Lambda Labs and Jarvis Labs. However, GPU prices have come down in late 2022 so buying your own machine may also be a viable option.

Getting started (Github, notebooks to play with, resources)

00:14:58

The author suggests playing around with the notebooks in the "diffusion-nbs" repository and trying out suggested tools from Johno's "suggested_tools.md". They also recommend exploring ready-to-go applications for creating AI artworks like Lexica. The goal is to understand what capabilities and constraints exist within these tools so that one can think about potential research opportunities.

Diffusion notebook from Hugging Face

00:20:48

The notebook is built using the library called Diffusers by Hugging Face, which is recommended for doing Stable Diffusion. The basic idea of any library looks pretty similar and pipelines are used in particular the Stable Diffusion Pipeline. To get started playing with this you will need to log in to Hugging Face and create a username there and a password then login. Once you've done it once it'll save on your computer so that you won't have to log in again, also we can save our own pipelines up into the cloud onto Hub for other people's use as well as download many gigabytes of data from internet first time running this code every time when using Colab everything gets thrown away start from scratch but if we use something like Paperspace or Lambda Labs all things going be saved automatically after downloading them at first run.

How stable diffusion works

00:26:59

Stable diffusion models start with random noise and try to make it slightly less noisy and more like the desired output in multiple steps. Doing it in one go doesn't work well, but recent advancements have reduced the number of required steps from 51 to 3-4.

Diffusion notebook (guidance scale, negative prompts, init image, textual inversion, Dreambooth)

00:30:06

Creating Images with Diffusion Notebook The guidance scale parameter in the pipeline determines how much focus is given to specific captions versus creating an image. Negative prompts can be used to subtract one prompt from another, resulting in a non-blue "Labrador in the style of Vermeer". The initial image can also be passed through an eye-to-eye image pipeline for better results.

Fine-Tuning and Textual Inversion Fine-tuning models using datasets like Pokémon images and their corresponding captions allows for more accurate responses to prompts. Textual inversion involves training embeddings for a single token based on example pictures, while Dreambooth fine-tunes tokens that are not commonly used.

Understanding Machine Learning Training This chapter requires prior understanding of machine learning model training. It delves into why certain problems arise when trying to generate specific images or captions using Stable Diffusion's methods such as textual inversion or fine-tuning with datasets.

Stable diffusion explained

00:45:00

Introduction to Stable Diffusion The traditional way of explaining Stable Diffusion is through a mathematical derivation, but this course will teach a new and simpler conceptual approach. The function "f" behind the web API can be used to generate handwritten digits by adjusting pixel values one at a time.

Calculating Gradient for Handwritten Digits Adjusting each pixel value in an image and passing it through the "f" function allows us to calculate the gradient of probability that X3 is a handwritten digit with respect to each individual pixel. This results in 784 values for every input image passed into the system.

Math notation correction

00:53:04

The process involves changing the pixels of an image according to its gradient, which is obtained by calculating derivatives using finite differencing or analytic derivatives. By modifying each pixel one at a time and checking how it changes the probability that an input is a digit, we can create a Neural Net that tells us which pixels to change in order to make any arbitrary noisy input look like a valid handwritten digit.

Creating a neural network to predict noise in an image

01:14:37

Creating a Neural Network to Predict Noise in an Image The author explains how they create training data by adding random noise on top of handwritten digits, and then use this data to train a neural network that predicts the amount of noise added. The output is used as input for removing the noise from noisy images.

Using U-Net for Stable Diffusion The author introduces U-Net, which takes somewhat noisy images as inputs and outputs the corresponding noises such that subtracting them from inputs results in unnoisy or approximated image. They also mention that there are several components involved in stable diffusion but details about their names don't matter much yet.

Working with images and compressing the data with autoencoders

01:27:46

Working with Images and Compressing Data The author explains that storing the exact pixel value of every single pixel in an image is not efficient. Instead, compressing images using autoencoders can decrease the number of pixels by 48 times while still retaining all important information.

The Autoencoder Model as a Compression Algorithm Autoencoder models give back what they are given, making them useful for compression algorithms. The encoder half of an autoencoder model can be used to create compressed versions (16,384 bytes) of images which can then be decoded into their original form using the decoder half. This creates a powerful compression algorithm that works extremely well on millions and millions of images trained through neural networks.

Explaining latents that will be input into the unet

01:40:12

Instead of inputting the actual images into the U-Net, we use their encoded version called "Latents". These Latents are passed through the auto encoder's decoder to get an image. The VAE is optional but saves time and money by reducing compute usage.

Adding text as one hot encoded input to the noise and drawing (aka guidance)

01:43:54

The model can be given guidance by passing in a one-hot encoded version of what digit it is, along with noisy input. This helps the Neural Net learn how to predict noise better by taking advantage of knowing what actual input was, which guides it as to what image we're trying to create.

How to represent numbers vs text embeddings in our model with CLIP encoders

01:47:06

To represent text embeddings in a model, we cannot create one-hot encoded vectors for every possible sentence. Instead, we can use a text encoder and an image encoder to generate random features that will be trained using inputs and outputs until they produce meaningful representations of images and texts. These models can then be used to match images with their corresponding descriptions or tags.

CLIP encoder loss function

01:53:13

The CLIP model aims to create embeddings that are a good match for the input text or image by taking dot products of their features and adding them up, resulting in a contrastive loss function. The CLIP text encoder takes some text as input and outputs an embedding where similar sets of texts will give us similar embeddings.

Caveat regarding "time steps"

02:00:55

Caveat regarding "time steps" The language used around the concept of “time steps” in image denoising is confusing and unnecessary. It refers to a schedule for varying levels of noise that can be picked randomly during training, but nowadays it's more common to use Beta as a measure of standard deviation instead. During inference time, the model predicts what the noise is and subtracts it from the noisy image with some constant multiplication factor applied.

Why don’t we do this all in one step?

02:07:04

Why don't we do this all in one step? The reason for not jumping to the best image is that it never appeared in our training set, and so our model has no idea what to do with it. The process repeats a bunch of times, and questions like "what do we use for C?" are decided in the actual sampler.

Thinking about diffusion models as optimizers Diffusion-based models came from differential equations world where they take “t” as an input; however, passing t might be unnecessary since figuring out how noisy something is straightforward. Once you stop thinking about them as differential equations and worry more about math (gaussians), things start looking more like optimizers. Using sophisticated loss functions such as Perceptual Loss or using noise directly instead of putting back can become possible when thinking of this problem optimization rather than solving a differential equation problem.