• Stars
    star
    221
  • Rank 178,989 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 1 year ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Inference Stable Diffusion with C# and ONNX Runtime

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

More Repositories

1

cpp-onnxruntime-resnet-console-app

Simple console app that implements ONNX Runtime and ResNet in C++
C++
43
star
2

SnakeVR

WebVR Game with BabylonJS
TypeScript
27
star
3

unreal-onnxruntime-nni-example

C++
25
star
4

wine-quality-azure-ml-visual-interface

Is that wine good or bad? A beginner tutorial on how to build a binary classification machine learning model with no code using Azure Machine Learning Visual Interface
Jupyter Notebook
15
star
5

Build-First-Web-VR-Game-Absolute-Beginner

This is source and tutorial for building your first website and first web vr game - all in one!
JavaScript
13
star
6

Use-ML-To-Classify-Yoga-Poses

This tutorial will go over how to use Azure Cognitive Services to get an image dataset and train a Custom Vision model. The repository has a simple nodejs console app that uses Bing Image Search to scrape images to a local directory based on search term(s). Then use the images scraped to create a Custom Vision model with Azure Cognitive Services.
JavaScript
12
star
7

onnx-csharp-serverless

Build a model with python, save it to onnx format, run it with csharp with the onnxruntime and deploy to a serverless Azure Function
Jupyter Notebook
7
star
8

PowerAppsComponent

Resources: Learn how to build a custom Power Apps component, create a code component solution package, and then test and debug a code component.
TypeScript
7
star
9

HackResourceList

Link and resources for Hack Workshops on Azure
6
star
10

onnxruntime-raspberrypi

Python
5
star
11

WebVR-ExploadingSpheres-Babylonjs

TypeScript
5
star
12

intro-nlp-wine-reviews

A project to introduce you to a simple Bag of Words NLP using SciKit Learn and Python.
Jupyter Notebook
5
star
13

bert-excel-addin-ort-web

TypeScript
5
star
14

FormRecognizer

Form Recognizer
Jupyter Notebook
3
star
15

TimeSeriesForecasting-ML-Designer

Build a model from start to finish to project sales using a Time Series Forecasting Regression model. Sample code to process data in c# or python and then build the build with no code Azure Machine Learning Designer.
C#
3
star
16

MachineLearningWorkshop

2
star
17

ImageScraperAndCustomVisionMagic

Scrape Images using NodeJS and Bing Search Cognitive Service. Then script the upload to Azure Custom Vision Cognitive Service with Python Jupyter Notebook
Jupyter Notebook
2
star
18

whisper_quant

Python
1
star
19

Xamarin-ml-onnx-runtime

C#
1
star
20

ilta-ai-webinar

1
star
21

babylonjs-webpack-typescript-starter-project

Starter project using babylonjs, webpack, and typescript.
TypeScript
1
star
22

onnxruntime-azure-function

Python
1
star