Friday, March 29, 2024
HomeHow ToHow to use stable Diffusion to generate AI images on your computer

How to use stable Diffusion to generate AI images on your computer


Artificial Intelligence is a hot topic right now, however most AI image creators work in the cloud. Stable Diffusion is different — you can run it on your very own PC and generate as many images as you want. Here’s how you can install and use Stable Diffusion on windows.

Stable diffusion:

Stable Diffusion is an open-source machine learning model that can generate images from text, modify images based on text, or fill in details on low-resolution or low-detail images. It has been trained on billions of images and can produce results that are comparable to the ones you’d get from DALL-E 2 and MidJourney. It’s developed by Stability AI It was also the first publicly released On August 22, 2022

Stable Diffusion doesn’t have a tidy user interface (yet) like some AI image generators, but it has an extremely permissive license, and — best of all — it is completely free To use on your PC (or Mac.

Update, 9/16/22: Do you prefer a graphic interface? Check out our guide on how to run stable diffusion with a GUI from your computer.

Don’t be intimidated by the fact that Stable Diffusion currently runs in a command-line interface (CLI). The process of getting it started is very straightforward. You can get it to run in minutes if you are able to double-click an executable.

What do You Need for Stable Diffusion to Work on Your Computer?

Stable Diffusion won’t run on your phone, or most laptops, but it will run on the average gaming PC in 2022. These are the minimum requirements.

If you don’t have the hardware, consider using a web-based AI image generator. You can even run a demo of Stable Diffusion The web.

How to Setup and Use Stable Diffusion windows

You will need Git or Miniconda.

Note: Miniconda3 is a safe program that has been produced by well-respected organizations. You don’t need to worry about malware with them provided that you download them from the official sources linked in this article. 

Git Installation

Git is a tool that allows developers to manage different versions of the software they’re developing. They can maintain multiple versions of the software they’re working on in a central repository simultaneously and allow other developers to contribute to the project.

RELATED: How to install Git windows

If you’re not a developer, Git provides a convenient way to access and download these projects, and that’s how we’ll use it in this case. Download the windows Installer x64 Start the Git website and then execute it to install Git.

There are several options you’ll be prompted to select while the installer runs — leave them on their default settings. One option page, “Adjusting Your PATH Environment,” is particularly important. It must be set to “Git From The Command Line And Also From 3rd-Party Software.”

Make sure that "Git From The Command Line And Also From 3rd-Party Software" is selected.

Miniconda3 installation

Stable Diffusion relies on many different sources Python libraries. If you don’t know much about Python, don’t worry too about this — suffice it to say, the libraries are just software packages that your computer can use to perform specific functions, like transform an image, or do complex math.

RELATED: What Is Python?

Miniconda3 is basically a convenience tool. It lets you download, install, and manage all of the libraries required for Stable Diffusion to function without very much manual intervention. It’ll also be how we actually use Stable Diffusion.

Head over to the Miniconda3 download page and click “Miniconda3 windows 64-bit” to get the latest installer.

Double-click the downloaded executable to begin the installation. Miniconda3’s installation involves less clicking through pages than Git did, but you need to watch out for this option:

Tick the box that says "All Users."

Make sure that you select “All Users” before clicking next and finishing up the installation.

You’ll be prompted to restart your computer after installing Git and Miniconda3. We didn’t find it to be necessary, but it won’t hurt if you do.

Get the Stable Diffusion GitHub repository and the latest Checkpoint

Now that we’ve installed the pre-requisite software, we’re ready to download and install Stable Diffusion.

Download the latest checkpoint first — version 1.4 is nearly 5GB, so it might take a while. For the download of the checkpoint, you need to make an account. However, they just require your email address and a name. All other information is optional.

Note: Version 1.4 is the current version at the moment of writing, September 2, 2022. Download the most recent version instead.

Click “sd-v1-4.ckpt” to start the download.

Note: The other file, “sd-v1-4-full-ema.ckpt”, Might However, it produces more results and is approximately twice as big. Either can be used. 

Next, you will need to download Stable Diffusion GitHub Click on the green “Code” button, then click “Download ZIP.” Alternatively, you can use this direct download link.

Now we need to prepare a few folders where we’ll unpack all of Stable Diffusion’s files. Click the Start button and type “miniconda3” into the Start Menu search bar, then click “Open” or hit Enter.

We’re going to create a folder named “stable-diffusion” using the command line. After copying the code, paste it into Miniconda3 and then hit Enter.

cdC:/
mkdir stable-diffusion
Cd stable-diffusion

Note: To execute the final command, you must hit Enter after you have pasted a block code in a terminal like Miniconda3.

If everything went well, you’ll see something like this:

Minoconda3 terminal showing commands executing successfully.

Keep the Miniconda3 window open, we’ll need it again in a minute.

Open up the ZIP file, “stable-diffusion-main.zip,” that you downloaded from GitHub in your favourite file archiving program. Alternatively, windows can also open ZIP files by itself if you don’t have one. Keep the ZIP file open in one window, then open another File Explorer window and navigate to the “C:stable-diffusion” folder we just made.

RELATED: File Explorer Support windows 10

Drag and drop the folder in the ZIP file, “stable-diffusion-main,” into the “stable-diffusion” folder.

Drag and drop the contents of the ZIP file into the stable-diffusion folder.

Now go back to Miniconda3. Copy and paste these commands into your window.

cd C:stable-diffusionstable-diffusion-main
conda env create -f environment.yaml
conda activate ldm
mkdir modelsldmstable-diffusion-v1

Wait for the download to finish.

Don’t interrupt this process. It may take some time to download files that are more than one gigabyte in size. If you do interrupt the process accidentally, you’ll need to delete the environment folder and run conda env create -f environment.yaml again. If that happens, navigate to “C:Users(Your User Account).condaenvs” and delete the “ldm” folder, then run the previous command.

Note: Now, let’s see what we did. Python lets you sort coding projects into “Environments.” Each environment is separate from other environments, so you can load different Python libraries into different environments without having to worry about conflicting versions. It is invaluable if you’re working on multiple projects on one PC.

The lines we ran created a new environment named “ldm,” downloaded and installed all of the necessary Python libraries for Stable Diffusion to workAfter activating the ldm environment was done, change the directory to a different folder.

We’re on the last step of the installation. Navigate to “C:stable-diffusionstable-diffusion-mainmodelsldmstable-diffusion-v1” in File Explorer, then copy and paste the checkpoint file (sd-v1-4.ckpt) into the folder.

Copy the model file into the stable-diffuse-v1 folder.

Wait for the file to finish transferring, right-click “sd-v1-4.ckpt” and then click “Rename.” Type “model.ckpt” into the highlighted box, then hit Enter to change the file name.

Note: If you’re running windows 11, you won’t see “rename” in the right-click context menu. Instead, there is an icon that looks more like a small text field.

RELATED: windows 11. 11 Context-Minimalist Menu Buttons will Confuse You

Rename the model file "model.ckpt"

And that’s it — we’re done. Now we are all set to use Stable Diffusion.

How to use stable diffusion

You must activate the ldm environment that we have created whenever you use Stable Diffusion. Click here to enter conda activate ldm into the Miniconda3 window and hit “Enter.” The (ldm) on the left-hand side indicates that the ldm environment is active.

Note: Miniconda3 will automatically open this command. You can keep the ldm window open and it will continue to work.

Activate the ldm environment.

We then need to modify the directory (hence the command).Cd) to “C:stable-diffusionstable-diffusion-main” before we can generate any images. Paste cd C:stable-diffusionstable-diffusion-main Input into the command line

How to make an image with stable diffusion

We’re going to call a script, txt2img.py, that allows us to convert text prompts into 512×512 images. Below is an example. To make sure it all works properly, try this:

pythonScripts/txt2img.py -prompts "a close up portrait of a Cat by Pablo Picasso. Vivid, Abstract Art Colorful, Vibrant" --plms

The progress indicator on your console is displayed as the camera produces pictures.

Stable Diffusion generating images.

That command will produce five cat images, all located at “C:stable-diffusionstable-diffusion-mainoutputstxt2img-samplessamples”.

A cat in the style of Pablo Picasso.

It isn’t perfect, but it distinctly resembles the style of Pablo Picasso, just like we specified in the prompt. You should have similar images, but they shouldn’t necessarily be identical.

You can change the image by simply changing the text in the double quotation marks. --prompt.

Tip: Don’t rewrite the entire line every time. Move the cursor with the arrow keys and then replace the prompt.

python scripts/txt2img.py --prompt "YOUR DESCRIPTIONS, PLEASE GO HERE" --plms --n_iter 5 --n_samples 1

Say we wanted to generate a realistic looking gopher in a magical forest wearing a wizard’s hat. You could also try this command.

pythonScripts/txt2img.py -prompts "a photo of a gopher in a wizard's hat, vivid, photographic, realistic, fantasy, 8K UHD photography," --plms.

A gopher with a purple wizard hat.

It really is that easy — just describe what you want as specifically as you can. Make sure you include the terms that are relevant to photos. You can specify an artist if you wish to be inspired by their style.

Stable Diffusion isn’t limited to portraits and animals either, it can also produce striking landscapes.

A calm lake with mountains around it, and a dramatic sky.

What does the command’s arguments mean?

Stable Diffusion offers a wide range of options and arguments to help you customize your results. This is the minimum required to ensure Stable Diffusion can run on any gaming system.

Stable Diffusion comes with a lot of arguments you can use to modify your results. You can run Python scripts/txt2img.py -help To see a complete list of possible arguments, click here

Although there is much trial and error in the process of getting amazing results, that is only half of it. You should make sure to save or write arguments that yield the results you want. If you don’t want to do all of the experimenting yourself, there are growing communities on Reddit This site is dedicated to the exchange of pictures as well as prompts.

RELATED ARTICLES
Continue to the category
- Advertisment -spot_img

Most Popular

CATEGORIES

Verified by MonsterInsights