Skip to content

Commit

Permalink
Basic Stable-Cascade example
Browse files Browse the repository at this point in the history
  • Loading branch information
saddam213 committed Apr 30, 2024
1 parent e3ce080 commit dfda689
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
39 changes: 10 additions & 29 deletions OnnxStack.Console/Examples/StableCascadeExample.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using OnnxStack.Core.Image;
using OnnxStack.StableDiffusion.Config;
using OnnxStack.StableDiffusion.Enums;
using OnnxStack.StableDiffusion.Pipelines;
using SixLabors.ImageSharp;
using System.Diagnostics;
Expand All @@ -15,6 +16,7 @@ public StableCascadeExample(StableDiffusionConfig configuration)
{
_configuration = configuration;
_outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Examples", nameof(StableCascadeExample));
Directory.CreateDirectory(_outputDirectory);
}

public int Index => 20;
Expand All @@ -28,46 +30,25 @@ public StableCascadeExample(StableDiffusionConfig configuration)
/// </summary>
public async Task RunAsync()
{
Directory.CreateDirectory(_outputDirectory);


var prompt = "photo of a cat";
// Prompt
var promptOptions = new PromptOptions
{
Prompt = prompt
Prompt = "an image of a cat, donning a spacesuit and helmet",
DiffuserType = DiffuserType.TextToImage,
//InputImage = await OnnxImage.FromFileAsync("Input.png"),
};

// Create Pipeline
var pipeline = StableCascadePipeline.CreatePipeline("D:\\Repositories\\stable-cascade-onnx", memoryMode: StableDiffusion.Enums.MemoryModeType.Minimum);

// Preload Models (optional)
await pipeline.LoadAsync();


// Loop through schedulers
var schedulerOptions = pipeline.DefaultSchedulerOptions with
{
SchedulerType = StableDiffusion.Enums.SchedulerType.DDPM,
GuidanceScale =4f,
InferenceSteps = 20,
Width = 1024,
Height = 1024
};

var timestamp = Stopwatch.GetTimestamp();

var pipeline = StableCascadePipeline.CreatePipeline("D:\\Models\\stable-cascade-onnx", memoryMode: MemoryModeType.Minimum);

// Run pipeline
var result = await pipeline.RunAsync(promptOptions, schedulerOptions, progressCallback: OutputHelpers.ProgressCallback);

var image = new OnnxImage(result);
var result = await pipeline.GenerateImageAsync(promptOptions, progressCallback: OutputHelpers.ProgressCallback);

// Save Image File
await image.SaveAsync(Path.Combine(_outputDirectory, $"output.png"));
await result.SaveAsync(Path.Combine(_outputDirectory, $"output.png"));

// Unload
await pipeline.UnloadAsync();


}
}
}
2 changes: 2 additions & 0 deletions OnnxStack.StableDiffusion/Pipelines/StableCascadePipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public StableCascadePipeline(PipelineOptions pipelineOptions, TokenizerModel tok
Height = 1024,
InferenceSteps = 20,
GuidanceScale = 4f,
GuidanceScale2 = 0f,
InferenceSteps2 = 10,
SchedulerType = SchedulerType.DDPMWuerstchen
};
}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ __________________________
* StableDiffusion 1.5
* StableDiffusion Inpaint
* StableDiffusion ControlNet
* Stable-Cascade
* SDXL
* SDXL Inpaint
* SDXL-Turbo
Expand Down

0 comments on commit dfda689

Please sign in to comment.