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

Commit dfda689

Browse files
committed
Basic Stable-Cascade example
1 parent e3ce080 commit dfda689

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using OnnxStack.Core.Image;
22
using OnnxStack.StableDiffusion.Config;
3+
using OnnxStack.StableDiffusion.Enums;
34
using OnnxStack.StableDiffusion.Pipelines;
45
using SixLabors.ImageSharp;
56
using System.Diagnostics;
@@ -15,6 +16,7 @@ public StableCascadeExample(StableDiffusionConfig configuration)
1516
{
1617
_configuration = configuration;
1718
_outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Examples", nameof(StableCascadeExample));
19+
Directory.CreateDirectory(_outputDirectory);
1820
}
1921

2022
public int Index => 20;
@@ -28,46 +30,25 @@ public StableCascadeExample(StableDiffusionConfig configuration)
2830
/// </summary>
2931
public async Task RunAsync()
3032
{
31-
Directory.CreateDirectory(_outputDirectory);
32-
33-
34-
var prompt = "photo of a cat";
33+
// Prompt
3534
var promptOptions = new PromptOptions
3635
{
37-
Prompt = prompt
36+
Prompt = "an image of a cat, donning a spacesuit and helmet",
37+
DiffuserType = DiffuserType.TextToImage,
38+
//InputImage = await OnnxImage.FromFileAsync("Input.png"),
3839
};
3940

4041
// Create Pipeline
41-
var pipeline = StableCascadePipeline.CreatePipeline("D:\\Repositories\\stable-cascade-onnx", memoryMode: StableDiffusion.Enums.MemoryModeType.Minimum);
42-
43-
// Preload Models (optional)
44-
await pipeline.LoadAsync();
45-
46-
47-
// Loop through schedulers
48-
var schedulerOptions = pipeline.DefaultSchedulerOptions with
49-
{
50-
SchedulerType = StableDiffusion.Enums.SchedulerType.DDPM,
51-
GuidanceScale =4f,
52-
InferenceSteps = 20,
53-
Width = 1024,
54-
Height = 1024
55-
};
56-
57-
var timestamp = Stopwatch.GetTimestamp();
58-
42+
var pipeline = StableCascadePipeline.CreatePipeline("D:\\Models\\stable-cascade-onnx", memoryMode: MemoryModeType.Minimum);
5943

6044
// Run pipeline
61-
var result = await pipeline.RunAsync(promptOptions, schedulerOptions, progressCallback: OutputHelpers.ProgressCallback);
62-
63-
var image = new OnnxImage(result);
45+
var result = await pipeline.GenerateImageAsync(promptOptions, progressCallback: OutputHelpers.ProgressCallback);
6446

6547
// Save Image File
66-
await image.SaveAsync(Path.Combine(_outputDirectory, $"output.png"));
48+
await result.SaveAsync(Path.Combine(_outputDirectory, $"output.png"));
6749

50+
// Unload
6851
await pipeline.UnloadAsync();
69-
70-
7152
}
7253
}
7354
}

OnnxStack.StableDiffusion/Pipelines/StableCascadePipeline.cs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public StableCascadePipeline(PipelineOptions pipelineOptions, TokenizerModel tok
5454
Height = 1024,
5555
InferenceSteps = 20,
5656
GuidanceScale = 4f,
57+
GuidanceScale2 = 0f,
58+
InferenceSteps2 = 10,
5759
SchedulerType = SchedulerType.DDPMWuerstchen
5860
};
5961
}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ __________________________
5555
* StableDiffusion 1.5
5656
* StableDiffusion Inpaint
5757
* StableDiffusion ControlNet
58+
* Stable-Cascade
5859
* SDXL
5960
* SDXL Inpaint
6061
* SDXL-Turbo

0 commit comments

Comments
 (0)