{"id":22745453,"url":"https://github.com/cassiebreviu/stablediffusion","last_synced_at":"2025-04-05T03:10:28.540Z","repository":{"id":108963429,"uuid":"608864750","full_name":"cassiebreviu/StableDiffusion","owner":"cassiebreviu","description":"Inference Stable Diffusion with C# and ONNX Runtime","archived":false,"fork":false,"pushed_at":"2023-10-05T02:20:39.000Z","size":32796,"stargazers_count":233,"open_issues_count":7,"forks_count":51,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-29T02:07:28.448Z","etag":null,"topics":["csharp","onnx","onnxruntime","stable-diffusion"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cassiebreviu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-02T22:28:12.000Z","updated_at":"2025-03-14T05:51:08.000Z","dependencies_parsed_at":"2025-01-01T05:12:05.635Z","dependency_job_id":"1df19df0-f051-48d9-8ef8-e7f9406e1eba","html_url":"https://github.com/cassiebreviu/StableDiffusion","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassiebreviu%2FStableDiffusion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassiebreviu%2FStableDiffusion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassiebreviu%2FStableDiffusion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cassiebreviu%2FStableDiffusion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cassiebreviu","download_url":"https://codeload.github.com/cassiebreviu/StableDiffusion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280272,"owners_count":20912967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","onnx","onnxruntime","stable-diffusion"],"created_at":"2024-12-11T02:06:32.326Z","updated_at":"2025-04-05T03:10:28.521Z","avatar_url":"https://github.com/cassiebreviu.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Inference Stable Diffusion with C# and ONNX Runtime\n\nThis 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.\n\nFor the below example sentence the [CLIP model](https://huggingface.co/docs/transformers/model_doc/clip) 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.\n\n```text\n\"make a picture of green tree with flowers around it and a red sky\" \n```\n| Auto Generated Random Latent Seed Input | Resulting image output|\n| :--- | :--- |\n\u003cimg src=\"images/latent.png\" width=\"256\" height=\"256\" alt=\"Image of browser inferencing on sample images.\"/\u003e | \u003cimg src=\"images/sample-output-stablediff.png\" width=\"256\" height=\"256\" alt=\"Image of browser inferencing on sample images.\"/\u003e |\n\n## More Images Created with this Repo:\n\n| \u003cimg src=\"images/cat-sunglasses.png\" width=\"256\" height=\"256\" alt=\"Image of browser inferencing on sample images.\"/\u003e | \u003cimg src=\"images/dog-beach-sample.png\" width=\"256\" height=\"256\" alt=\"Image of browser inferencing on sample images.\"/\u003e |\n\n| \u003cimg src=\"images/cabin.png\" width=\"256\" height=\"256\" alt=\"Image of browser inferencing on sample images.\"/\u003e | \u003cimg src=\"images/shipwreck.png\" width=\"256\" height=\"256\" alt=\"Image of browser inferencing on sample images.\"/\u003e |\n\n## Prerequisites\n\n- [Visual Studio](https://visualstudio.microsoft.com/downloads/) or [VS Code](https://code.visualstudio.com/Download)\n- A GPU enabled machine with CUDA or DirectML on Windows\n    - Configure CUDA EP.  Follow [this tutorial to configure CUDA and cuDNN for GPU with ONNX Runtime and C# on Windows 11](https://onnxruntime.ai/docs/tutorials/csharp/csharp-gpu.html)\n    - Windows comes with DirectML support. No additional configuration is needed. Be sure to clone the [`direct-ML-EP`](https://github.com/cassiebreviu/StableDiffusion/tree/direct-ML-EP) branch of this repo if you choose this option.\n    - This was built on a GTX 3070 and it has not been tested on anything smaller.\n- Clone this repo\n```git\ngit clone https://github.com/cassiebreviu/StableDiffusion.git\n```\n\n## Use Hugging Face to download the Stable Diffusion models\n\nDownload the [ONNX Stable Diffusion models from Hugging Face](https://huggingface.co/models?sort=downloads\u0026search=Stable+Diffusion).\n\n - [Stable Diffusion Models v1.4](https://huggingface.co/CompVis/stable-diffusion-v1-4/tree/onnx)\n - [Stable Diffusion Models v1.5](https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/onnx)\n\n\nOnce 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](https://learn.microsoft.com/windows/ai/windows-ml/tutorials/pytorch-convert-model) for more information.\n\n- Clone the model repo:\n```text\ngit lfs install\ngit clone https://huggingface.co/CompVis/stable-diffusion-v1-4 -b onnx\n```\n\n- 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`.\n\n- Set Build for x64 \n\n- Hit `F5` to run the project in Visual Studio or `dotnet run` in the terminal to run the project in VS Code.\n\n_____________________\n## Follow the full Stable Diffusion C# Tutorial for this Repo [here](https://onnxruntime.ai/docs/tutorials/csharp/stable-diffusion-csharp.html)\n\n__________________________\n##  Resources\n- [ONNX Runtime C# API Doc](https://onnxruntime.ai/docs/api/csharp/api)\n- [Get Started with C# in ONNX Runtime](https://onnxruntime.ai/docs/get-started/with-csharp.html)\n- [Hugging Face Stable Diffusion Blog](https://huggingface.co/blog/stable_diffusion)\n- [Stable Diffusion C# Tutorial for this Repo](https://onnxruntime.ai/docs/tutorials/csharp/stable-diffusion-csharp.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcassiebreviu%2Fstablediffusion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcassiebreviu%2Fstablediffusion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcassiebreviu%2Fstablediffusion/lists"}