@@ -39,14 +39,15 @@ https://github.com/ffbinaries/ffbinaries-prebuilt/releases/download/v6.1/ffprobe
39
39
40
40
41
41
# C# Stable Diffusion
42
- Example Model: https://huggingface.co/runwayml/stable-diffusion-v1-5 (onnx branch)
43
-
44
42
45
43
## Basic Stable Diffusion Example
46
44
Run a simple Stable Diffusion process with a basic prompt
47
45
``` csharp
46
+ // Model:
47
+ // https://huggingface.co/runwayml/stable-diffusion-v1-5 (onnx branch)
48
+
48
49
// Create Pipeline
49
- var pipeline = StableDiffusionPipeline .CreatePipeline (" D: \\ Repositories \\ stable-diffusion-v1-5" );
50
+ var pipeline = StableDiffusionPipeline .CreatePipeline (" models \\ stable-diffusion-v1-5" );
50
51
51
52
// Set Prompt Options
52
53
var promptOptions = new PromptOptions { Prompt = " Photo of a cute dog." };
@@ -65,8 +66,11 @@ await pipeline.UnloadAsync();
65
66
## Stable Diffusion Batch Example
66
67
Run Stable Diffusion process and return a batch of results
67
68
``` csharp
69
+ // Model:
70
+ // https://huggingface.co/runwayml/stable-diffusion-v1-5 (onnx branch)
71
+
68
72
// Create Pipeline
69
- var pipeline = StableDiffusionPipeline .CreatePipeline (" D: \\ Repositories \\ stable-diffusion-v1-5" );
73
+ var pipeline = StableDiffusionPipeline .CreatePipeline (" models \\ stable-diffusion-v1-5" );
70
74
71
75
// Prompt
72
76
var promptOptions = new PromptOptions { Prompt = " Photo of a cat" };
@@ -83,10 +87,92 @@ await foreach (var result in pipeline.RunBatchAsync(batchOptions, promptOptions)
83
87
{
84
88
// Save Image result
85
89
var image = result .ImageResult .ToImage ();
86
- await image .SaveAsPngAsync ($" D: \\ Results \\ Image_ {result .SchedulerOptions .Seed }.png" );
90
+ await image .SaveAsPngAsync ($" Output_Batch_ {result .SchedulerOptions .Seed }.png" );
87
91
}
88
92
89
93
// Unload Pipleine
90
94
await pipeline .UnloadAsync ();
91
95
92
96
```
97
+
98
+
99
+
100
+ ## Stable Diffusion ImageToImage Example
101
+ Run Stable Diffusion process with an initial image as input
102
+ ``` csharp
103
+ // Model:
104
+ // https://huggingface.co/runwayml/stable-diffusion-v1-5 (onnx branch)
105
+
106
+ // Create Pipeline
107
+ var pipeline = StableDiffusionPipeline .CreatePipeline (" models\\ stable-diffusion-v1-5" );
108
+
109
+ // Load Input Image
110
+ var inputImage = await InputImage .FromFileAsync (" Input.png" );
111
+
112
+ // Set Prompt Options
113
+ var promptOptions = new PromptOptions
114
+ {
115
+ DiffuserType = DiffuserType .ImageToImage ,
116
+ Prompt = " Photo of a cute dog." ,
117
+ InputImage = inputImage
118
+ };
119
+
120
+ // Set Sheduler Options
121
+ var schedulerOptions = pipeline .DefaultSchedulerOptions with
122
+ {
123
+ // How much the output should look like the input
124
+ Strength = 0 . 8 f
125
+ };
126
+
127
+ // Run Pipleine
128
+ var result = await pipeline .RunAsync (promptOptions , schedulerOptions );
129
+
130
+ // Save image result
131
+ var image = result .ToImage ();
132
+ await image .SaveAsPngAsync (" Output_ImageToImage.png" );
133
+
134
+ // Unload Pipleine
135
+ await pipeline .UnloadAsync ();
136
+ ```
137
+ | Input | Output |
138
+ | :--- | :--- |
139
+ <img src =" ../Assets/Samples/Input.png " width =" 256 " /> | <img src =" ../Assets/Samples/Output_ImageToImage.png " width =" 256 " />
140
+
141
+
142
+ ## Stable Diffusion ControlNet Example
143
+ Run Stable Diffusion process with ControlNet depth
144
+ ``` csharp
145
+ // Models:
146
+ // https://huggingface.co/axodoxian/controlnet_onnx
147
+ // https://huggingface.co/axodoxian/stable_diffusion_onnx
148
+
149
+ // Create Pipeline
150
+ var pipeline = StableDiffusionPipeline .CreatePipeline (" models\\ stable_diffusion_onnx" , ModelType .ControlNet );
151
+
152
+ // Load ControlNet Model
153
+ var controlNet = ControlNetModel .Create (" models\\ controlnet_onnx\\ controlnet\\ depth.onnx" );
154
+
155
+ // Load Control Image
156
+ var controlImage = await InputImage .FromFileAsync (" Input_Depth.png" );
157
+
158
+ // Set Prompt Options
159
+ var promptOptions = new PromptOptions
160
+ {
161
+ DiffuserType = DiffuserType .ControlNet ,
162
+ Prompt = " Photo-realistic alien" ,
163
+ InputContolImage = controlImage
164
+ };
165
+
166
+ // Run Pipleine
167
+ var result = await pipeline .RunAsync (promptOptions , controlNet : controlNet ) ;
168
+
169
+ // Save image result
170
+ var image = result .ToImage ();
171
+ await image .SaveAsPngAsync (" Output_ControlNet.png" );
172
+
173
+ // Unload Pipleine
174
+ await pipeline .UnloadAsync ();
175
+ ```
176
+ | Input | Output |
177
+ | :--- | :--- |
178
+ <img src =" ../Assets/Samples/Input_Depth.png " width =" 256 " /> | <img src =" ../Assets/Samples/Input_Depth.png " width =" 256 " />
0 commit comments