Stable Diffusion in TensorFlow / Keras
Ports Stable Diffusion weights to TensorFlow/Keras and provides Python and CLI interfaces for text-to-image generation.
What this file does
Ports Stable Diffusion weights to TensorFlow/Keras and provides Python and CLI interfaces for text-to-image generation.
When to use it
- You want to run Stable Diffusion without PyTorch
- You need a TensorFlow-native implementation for integration
- You prefer Colab notebooks for quick experimentation
- You want to generate images from text prompts via command line
Assumes this stack
Stable Diffusion in TensorFlow / Keras
A Keras / Tensorflow implementation of Stable Diffusion.
The weights were ported from the original implementation.
Colab Notebooks
The easiest way to try it out is to use one of the Colab notebooks:
- GPU Colab
- GPU Colab + Mixed Precision
- ~10s generation time per image (512x512) on default Colab GPU without drop in quality (source)
- TPU Colab.
- Slower than GPU for single-image generation, faster for large batch of 8+ images (source).
- GPU Colab with Gradio
Installation
Install as a python package
Install using pip with the git repo:
pip install git+https://github.com/divamgupta/stable-diffusion-tensorflow
Installing using the repo
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
Using pip without a virtual environment
Install dependencies using the requirements.txt file or the requirements_m1.txt file,:
pip install -r requirements.txt
Using a virtual environment with virtualenv
-
Create your virtual environment for
python3:python3 -m venv venv -
Activate your virtualenv:
source venv/bin/activate -
Install dependencies using the
requirements.txtfile or therequirements_m1.txtfile,:pip install -r requirements.txt
Usage
Using the Python interface
If you installed the package, you can use it as follows:
from stable_diffusion_tf.stable_diffusion import Text2Image
from PIL import Image
generator = Text2Image(
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,
)
Image.fromarray(img[0]).save("output.png")
Using text2image.py from the git repo
Assuming 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.
Example outputs
The following outputs have been generated using this implementation:
- A epic and beautiful rococo werewolf drinking coffee, in a burning coffee shop. ultra-detailed. anime, pixiv, uhd 8k cryengine, octane render

- Spider-Gwen Gwen-Stacy Skyscraper Pink White Pink-White Spiderman Photo-realistic 4K

- A vision of paradise, Unreal Engine

References
What's inside
Installation instructions, Python API, CLI usage, 3 Colab notebook links, 3 example outputs, and 2 references.
Change this for your project
- Replace
stable_diffusion_tf.stable_diffusionwith your installed package name if different - Replace
https://github.com/divamgupta/stable-diffusion-tensorflowwith your own repo URL - Replace
output.pngwith your desired output filename
Where it goes
Keep in docs/ or alongside the feature. Agents read it to implement against a defined contract.
Worth borrowing
- Provide both Python API and CLI for the same functionality
- Offer multiple Colab notebooks targeting different hardware (GPU, TPU, Gradio)
Related Documents
GPU Selection Guide for Large Language Models (LLMs)
Guides GPU selection for LLM inference, fine-tuning, and training by mapping model sizes, precision levels, and budgets to VRAM requirements.
Community AI Agent Skills Discovery Sources
Catalogs 50+ platforms, repositories, directories, and communities for discovering and sharing AI agent skills across multiple coding tools.
ReleaseKit - Technical Requirements Document
Specifies a Go library and CLI for release automation with conventional commit parsing, validation checks, and workflow orchestration.
api_llm Specification
Defines a workspace of thin HTTP API clients for major LLM providers with no abstraction layer and explicit developer control.