Git Product home page Git Product logo

stablediffusion's Introduction

Inference Stable Diffusion with C# and ONNX Runtime

This repo contains the logic to do inferencing for the popular Stable Diffusion deep learning model in C#. Stable Diffusion models take a text prompt and create an image that represents the text.

For the below example sentence the CLIP model creates a text embedding that connects text to image. A random noise image is created and then denoised with the unet model and scheduler algorithm to create an image that represents the text prompt. Lastly the decoder model vae_decoder is used to create a final image that is the result of the text prompt and the latent image.

"make a picture of green tree with flowers around it and a red sky" 
Auto Generated Random Latent Seed Input Resulting image output
Image of browser inferencing on sample images. Image of browser inferencing on sample images.

More Images Created with this Repo:

| Image of browser inferencing on sample images. | Image of browser inferencing on sample images. |

| Image of browser inferencing on sample images. | Image of browser inferencing on sample images. |

Prerequisites

git clone https://github.com/cassiebreviu/StableDiffusion.git

Use Hugging Face to download the Stable Diffusion models

Download the ONNX Stable Diffusion models from Hugging Face.

Once you have selected a model version repo, click Files and Versions, then select the ONNX branch. If there isn't an ONNX model branch available, use the main branch and convert it to ONNX. See the ONNX conversion tutorial for PyTorch for more information.

  • Clone the model repo:
git lfs install
git clone https://huggingface.co/CompVis/stable-diffusion-v1-4 -b onnx
  • Copy the folders with the ONNX files to the C# project folder \StableDiffusion\StableDiffusion. The folders to copy are: unet, vae_decoder, text_encoder, safety_checker.

  • Set Build for x64

  • Hit F5 to run the project in Visual Studio or dotnet run in the terminal to run the project in VS Code.


Follow the full Stable Diffusion C# Tutorial for this Repo here


Resources

stablediffusion's People

Contributors

cassiebreviu avatar jlami avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.