Generate Images using AI – Stable Diffusion

Wouldn’t it would be great if we can use an AI program to generate images? As I have embarked on a journey to understand AI & machine learning, wanted to share a quick and fun project that you can run on your local system which can translate your language and generate images accordingly.

Do you know, that the image in my previous post is generated by AI that we would be talking about in this post?

Recently stable diffusion announced its AI module’s public release to be used by developers around the world. In this post, we would be using the same distribution.

Step 1: Prerequisite

  • Install Anaconda distribution from here
  • Make sure you have Git installed as well

Step 2: Download the latest model weights

Visit this URL, you would need to sign up at huggingface to access these files.

Get the latest distribution as shown in the below image

Now navigate to the “Files & Versions” tab and download the latest ckpt distribution

Step 3: Download Git repository

Use this link to download this repository on your local system.

Step 4: Copy ckpt file

Make sure you are in folder Stable-Diffusion, run below command to create a folder.

mkdir -p models/ldm/stable-diffusion-v1/

Now, rename ckpt file downloaded in step 3 and place in above folder created.

Step 5: Activate the environment

Run below command in terminal

conda env create -f environment-mac.yaml

If you get error like below

`CondaValueError: prefix already exists: /opt/anaconda3/envs/ldm`

then run below command with –force parameter like

conda env create -f environment-mac.yaml --force

Now run the command

conda activate ldm

it could take some time depending on your system capacity and internet speed.

Step 5: load Machine learning models needed by stable diffusion

python scripts/

Step 6: Fun time

You can use the below command to generate images

python scripts/orig_scripts/ --prompt "a photograph of an astronaut riding a horse" --plms

Sample images would be created in the outputs folder.

Few Sample Images created by AI

painting of robots constructing sky scrappers, tallest buildings, sand storm
painting of sky scrappers construction, tallest buildings, sand storm
Ganesh god in temple
Ganesh God in Temple
Health checkup of Cloud
Health checkup of Cloud
Painting of House in Forest & Water
Painting of House in Forest & Water

There are some issues for Mac users, make sure to keep reading this post for the latest updates.




Related Posts


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading