Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 82cd4aa

Browse files
author
James Tayler
committed
Merge branch 'master' into add_tests
2 parents 775d92d + bb5ed73 commit 82cd4aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1747
-812
lines changed
595 KB
Loading
424 KB
Loading
483 KB
Loading
464 KB
Loading
497 KB
Loading
531 KB
Loading
426 KB
Loading
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"Name": "Deliberate V3",
3+
"Description": "",
4+
"Author": "TheyCallMeHex",
5+
"Repository": "https://huggingface.co/TheyCallMeHex/Deliberate-V3-ONNX",
6+
"ImageIcon": "https://raw.githubusercontent.com/saddam213/OnnxStack/master/Assets/Templates/Deliberate-V3/Icon.png",
7+
"Status": "Active",
8+
"PadTokenId": 49407,
9+
"BlankTokenId": 49407,
10+
"TokenizerLimit": 77,
11+
"EmbeddingsLength": 768,
12+
"ScaleFactor": 0.18215,
13+
"PipelineType": "StableDiffusion",
14+
"Diffusers": [
15+
"TextToImage",
16+
"ImageToImage",
17+
"ImageInpaintLegacy"
18+
],
19+
"ModelFiles": [
20+
"https://huggingface.co/TheyCallMeHex/Deliberate-V3-ONNX/resolve/main/tokenizer/model.onnx",
21+
"https://huggingface.co/TheyCallMeHex/Deliberate-V3-ONNX/resolve/main/unet/model.onnx",
22+
"https://huggingface.co/TheyCallMeHex/Deliberate-V3-ONNX/resolve/main/unet/model.onnx_data",
23+
"https://huggingface.co/TheyCallMeHex/Deliberate-V3-ONNX/resolve/main/text_encoder/model.onnx",
24+
"https://huggingface.co/TheyCallMeHex/Deliberate-V3-ONNX/resolve/main/vae_decoder/model.onnx",
25+
"https://huggingface.co/TheyCallMeHex/Deliberate-V3-ONNX/resolve/main/vae_encoder/model.onnx"
26+
],
27+
"Images": [
28+
"https://raw.githubusercontent.com/saddam213/OnnxStack/master/Assets/Templates/Deliberate-V3/Preview1.png",
29+
"https://raw.githubusercontent.com/saddam213/OnnxStack/master/Assets/Templates/Deliberate-V3/Preview2.png",
30+
"https://raw.githubusercontent.com/saddam213/OnnxStack/master/Assets/Templates/Deliberate-V3/Preview3.png",
31+
"https://raw.githubusercontent.com/saddam213/OnnxStack/master/Assets/Templates/Deliberate-V3/Preview4.png",
32+
"https://raw.githubusercontent.com/saddam213/OnnxStack/master/Assets/Templates/Deliberate-V3/Preview5.png",
33+
"https://raw.githubusercontent.com/saddam213/OnnxStack/master/Assets/Templates/Deliberate-V3/Preview6.png"
34+
]
35+
}

OnnxStack.Console/Examples/StableDebug.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using OnnxStack.StableDiffusion.Common;
1+
using OnnxStack.StableDiffusion;
2+
using OnnxStack.StableDiffusion.Common;
23
using OnnxStack.StableDiffusion.Config;
34
using OnnxStack.StableDiffusion.Enums;
4-
using OnnxStack.StableDiffusion.Services;
55
using SixLabors.ImageSharp;
66
using System.Diagnostics;
77

@@ -37,11 +37,11 @@ public async Task RunAsync()
3737
{
3838
Prompt = prompt,
3939
NegativePrompt = negativePrompt,
40-
SchedulerType = SchedulerType.LMS
4140
};
4241

4342
var schedulerOptions = new SchedulerOptions
4443
{
44+
SchedulerType = SchedulerType.LMS,
4545
Seed = 624461087,
4646
//Seed = Random.Shared.Next(),
4747
GuidanceScale = 8,
@@ -54,9 +54,9 @@ public async Task RunAsync()
5454
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
5555
await _stableDiffusionService.LoadModel(model);
5656

57-
foreach (var schedulerType in Helpers.GetPipelineSchedulers(model.PipelineType))
57+
foreach (var schedulerType in model.PipelineType.GetSchedulerTypes())
5858
{
59-
promptOptions.SchedulerType = schedulerType;
59+
schedulerOptions.SchedulerType = schedulerType;
6060
OutputHelpers.WriteConsole($"Generating {schedulerType} Image...", ConsoleColor.Green);
6161
await GenerateImage(model, promptOptions, schedulerOptions);
6262
}
@@ -72,12 +72,12 @@ public async Task RunAsync()
7272
private async Task<bool> GenerateImage(ModelOptions model, PromptOptions prompt, SchedulerOptions options)
7373
{
7474
var timestamp = Stopwatch.GetTimestamp();
75-
var outputFilename = Path.Combine(_outputDirectory, $"{options.Seed}_{prompt.SchedulerType}.png");
75+
var outputFilename = Path.Combine(_outputDirectory, $"{options.Seed}_{options.SchedulerType}.png");
7676
var result = await _stableDiffusionService.GenerateAsImageAsync(model, prompt, options);
7777
if (result is not null)
7878
{
7979
await result.SaveAsPngAsync(outputFilename);
80-
OutputHelpers.WriteConsole($"{prompt.SchedulerType} Image Created: {Path.GetFileName(outputFilename)}", ConsoleColor.Green);
80+
OutputHelpers.WriteConsole($"{options.SchedulerType} Image Created: {Path.GetFileName(outputFilename)}", ConsoleColor.Green);
8181
OutputHelpers.WriteConsole($"Elapsed: {Stopwatch.GetElapsedTime(timestamp)}ms", ConsoleColor.Yellow);
8282
return true;
8383
}
Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using OnnxStack.Core;
2-
using OnnxStack.StableDiffusion.Common;
1+
using OnnxStack.StableDiffusion.Common;
32
using OnnxStack.StableDiffusion.Config;
43
using OnnxStack.StableDiffusion.Enums;
5-
using OnnxStack.StableDiffusion.Helpers;
4+
using OnnxStack.StableDiffusion;
65
using SixLabors.ImageSharp;
6+
using OnnxStack.StableDiffusion.Helpers;
77

88
namespace OnnxStack.Console.Runner
99
{
@@ -31,68 +31,50 @@ public async Task RunAsync()
3131

3232
while (true)
3333
{
34-
OutputHelpers.WriteConsole("Please type a prompt and press ENTER", ConsoleColor.Yellow);
35-
var prompt = OutputHelpers.ReadConsole(ConsoleColor.Cyan);
36-
37-
OutputHelpers.WriteConsole("Please type a negative prompt and press ENTER (optional)", ConsoleColor.Yellow);
38-
var negativePrompt = OutputHelpers.ReadConsole(ConsoleColor.Cyan);
39-
40-
OutputHelpers.WriteConsole("Please enter a batch count and press ENTER", ConsoleColor.Yellow);
41-
var batch = OutputHelpers.ReadConsole(ConsoleColor.Cyan);
42-
int.TryParse(batch, out var batchCount);
43-
batchCount = Math.Max(1, batchCount);
4434

4535
var promptOptions = new PromptOptions
4636
{
47-
Prompt = prompt,
48-
NegativePrompt = negativePrompt,
49-
BatchCount = batchCount
37+
Prompt = "Photo of a cat"
5038
};
5139

5240
var schedulerOptions = new SchedulerOptions
5341
{
5442
Seed = Random.Shared.Next(),
5543

5644
GuidanceScale = 8,
57-
InferenceSteps = 22,
45+
InferenceSteps = 20,
5846
Strength = 0.6f
5947
};
6048

49+
var batchOptions = new BatchOptions
50+
{
51+
BatchType = BatchOptionType.Scheduler
52+
};
53+
6154
foreach (var model in _stableDiffusionService.Models)
6255
{
6356
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
6457
await _stableDiffusionService.LoadModel(model);
6558

66-
foreach (var schedulerType in Helpers.GetPipelineSchedulers(model.PipelineType))
59+
var batchIndex = 0;
60+
var callback = (int batch, int batchCount, int step, int steps) =>
61+
{
62+
batchIndex = batch;
63+
OutputHelpers.WriteConsole($"Image: {batch}/{batchCount} - Step: {step}/{steps}", ConsoleColor.Cyan);
64+
};
65+
66+
await foreach (var result in _stableDiffusionService.GenerateBatchAsync(model, promptOptions, schedulerOptions, batchOptions, callback))
6767
{
68-
promptOptions.SchedulerType = schedulerType;
69-
OutputHelpers.WriteConsole($"Generating {schedulerType} Image...", ConsoleColor.Green);
70-
await GenerateImage(model, promptOptions, schedulerOptions);
68+
var outputFilename = Path.Combine(_outputDirectory, $"{batchIndex}_{result.SchedulerOptions.Seed}.png");
69+
var image = result.ImageResult.ToImage();
70+
await image.SaveAsPngAsync(outputFilename);
71+
OutputHelpers.WriteConsole($"Image Created: {Path.GetFileName(outputFilename)}", ConsoleColor.Green);
7172
}
7273

7374
OutputHelpers.WriteConsole($"Unloading Model `{model.Name}`...", ConsoleColor.Green);
7475
await _stableDiffusionService.UnloadModel(model);
7576
}
7677
}
7778
}
78-
79-
private async Task<bool> GenerateImage(ModelOptions model, PromptOptions prompt, SchedulerOptions options)
80-
{
81-
82-
var result = await _stableDiffusionService.GenerateAsync(model, prompt, options);
83-
if (result == null)
84-
return false;
85-
86-
var imageTensors = result.Split(prompt.BatchCount);
87-
for (int i = 0; i < imageTensors.Length; i++)
88-
{
89-
var outputFilename = Path.Combine(_outputDirectory, $"{options.Seed}_{prompt.SchedulerType}_{i}.png");
90-
var image = imageTensors[i].ToImage();
91-
await image.SaveAsPngAsync(outputFilename);
92-
OutputHelpers.WriteConsole($"{prompt.SchedulerType} Image Created: {Path.GetFileName(outputFilename)}", ConsoleColor.Green);
93-
}
94-
95-
return true;
96-
}
9779
}
9880
}

0 commit comments

Comments
 (0)