A Keras / Tensorflow implementation of Stable Diffusion.
The weights were ported from the original implementation.
The easiest way to try it out is to use one of the Colab notebooks:
Install using pip with the git repo:
pip install git+https://github.com/divamgupta/stable-diffusion-tensorflow
Download the repo, either by downloading the zip file or by cloning the repo with git:
git clone git@github.com:divamgupta/stable-diffusion-tensorflow.git
Install dependencies using the requirements.txt file or the requirements_m1.txt file,:
pip install -r requirements.txt
Create your virtual environment for python3:
python3 -m venv venv
Activate your virtualenv:
source venv/bin/activate
Install dependencies using the requirements.txt file or the requirements_m1.txt file,:
pip install -r requirements.txt
If you installed the package, you can use it as follows:
from stable_diffusion_tf.stable_diffusion import StableDiffusion
from PIL import Image
generator = StableDiffusion(
img_height=512,
img_width=512,
jit_compile=False,
)
img = generator.generate(
"An astronaut riding a horse",
num_steps=50,
unconditional_guidance_scale=7.5,
temperature=1,
batch_size=1,
)
# for image to image :
img = generator.generate(
"A Halloween bedroom",
num_steps=50,
unconditional_guidance_scale=7.5,
temperature=1,
batch_size=1,
input_image="/path/to/img.png"
)
Image.fromarray(img[0]).save("output.png")
text2image.py from the git repoAssuming you have installed the required packages, you can generate images from a text prompt using:
python text2image.py --prompt="An astronaut riding a horse"
The generated image will be named output.png on the root of the repo.
If you want to use a different name, use the --output flag.
python text2image.py --prompt="An astronaut riding a horse" --output="my_image.png"
Check out the text2image.py file for more options, including image size, number of steps, etc.
img2img.py from the git repoAssuming you have installed the required packages, you can modify images from a text prompt using:
python img2img.py --prompt="a high quality sketch of people standing with sun and grass , watercolor , pencil color" --input="img.jpeg"
The generated image will be named img2img-out.jpeg by default on the root of the repo.
If you want to use a different name, use the --output flag.
Check out the img2img.py file for more options, including the number of steps.
The following outputs have been generated using this implementation:




114 followers · starred Sep 2022
1,108 followers · starred Sep 2022
61 followers · starred Sep 2022
205 followers · starred Oct 2022
A Keras / Tensorflow implementation of Stable Diffusion.
The weights were ported from the original implementation.
The easiest way to try it out is to use one of the Colab notebooks:
Install using pip with the git repo:
pip install git+https://github.com/divamgupta/stable-diffusion-tensorflow
Download the repo, either by downloading the zip file or by cloning the repo with git:
git clone git@github.com:divamgupta/stable-diffusion-tensorflow.git
Install dependencies using the requirements.txt file or the requirements_m1.txt file,:
pip install -r requirements.txt
Create your virtual environment for python3:
python3 -m venv venv
Activate your virtualenv:
source venv/bin/activate
Install dependencies using the requirements.txt file or the requirements_m1.txt file,:
pip install -r requirements.txt
If you installed the package, you can use it as follows:
from stable_diffusion_tf.stable_diffusion import StableDiffusion
from PIL import Image
generator = StableDiffusion(
img_height=512,
img_width=512,
jit_compile=False,
)
img = generator.generate(
"An astronaut riding a horse",
num_steps=50,
unconditional_guidance_scale=7.5,
temperature=1,
batch_size=1,
)
# for image to image :
img = generator.generate(
"A Halloween bedroom",
num_steps=50,
unconditional_guidance_scale=7.5,
temperature=1,
batch_size=1,
input_image="/path/to/img.png"
)
Image.fromarray(img[0]).save("output.png")
text2image.py from the git repoAssuming you have installed the required packages, you can generate images from a text prompt using:
python text2image.py --prompt="An astronaut riding a horse"
The generated image will be named output.png on the root of the repo.
If you want to use a different name, use the --output flag.
python text2image.py --prompt="An astronaut riding a horse" --output="my_image.png"
Check out the text2image.py file for more options, including image size, number of steps, etc.
img2img.py from the git repoAssuming you have installed the required packages, you can modify images from a text prompt using:
python img2img.py --prompt="a high quality sketch of people standing with sun and grass , watercolor , pencil color" --input="img.jpeg"
The generated image will be named img2img-out.jpeg by default on the root of the repo.
If you want to use a different name, use the --output flag.
Check out the img2img.py file for more options, including the number of steps.
The following outputs have been generated using this implementation:




114 followers · starred Sep 2022
1,108 followers · starred Sep 2022
61 followers · starred Sep 2022
205 followers · starred Oct 2022