From dc2ed2f310e678bbe1ae362fa1535ded178e71dc Mon Sep 17 00:00:00 2001 From: sa_ddam213 Date: Wed, 24 Apr 2024 10:57:11 +1200 Subject: [PATCH] ModelDebug runner --- OnnxStack.Console/Examples/ModelDebug.cs | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 OnnxStack.Console/Examples/ModelDebug.cs diff --git a/OnnxStack.Console/Examples/ModelDebug.cs b/OnnxStack.Console/Examples/ModelDebug.cs new file mode 100644 index 0000000..b6e3bc4 --- /dev/null +++ b/OnnxStack.Console/Examples/ModelDebug.cs @@ -0,0 +1,63 @@ +using OnnxStack.Core.Image; +using OnnxStack.StableDiffusion.Config; +using OnnxStack.StableDiffusion.Enums; +using OnnxStack.StableDiffusion.Pipelines; + +namespace OnnxStack.Console.Runner +{ + public sealed class ModelDebug : IExampleRunner + { + private readonly string _outputDirectory; + private readonly StableDiffusionConfig _configuration; + + public ModelDebug(StableDiffusionConfig configuration) + { + _configuration = configuration; + _outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Examples", nameof(ModelDebug)); + Directory.CreateDirectory(_outputDirectory); + } + + public int Index => 1; + + public string Name => "Model Debug"; + + public string Description => "Model Debug"; + + public async Task RunAsync() + { + // Create Pipeline + // var pipeline = InstaFlowPipeline.CreatePipeline("D:\\Repositories\\Instaflow-onnx"); + // var pipeline = LatentConsistencyPipeline.CreatePipeline("D:\\Repositories\\LCM_Dreamshaper_v7-onnx"); + // var pipeline = LatentConsistencyXLPipeline.CreatePipeline("D:\\Repositories\\Latent-Consistency-xl-Olive-Onnx"); + // var pipeline = StableDiffusionPipeline.CreatePipeline("D:\\Repositories\\stable-diffusion-v1-5"); + var pipeline = StableDiffusionXLPipeline.CreatePipeline("D:\\Repositories\\Hyper-SD-onnx"); + + // Prompt + var promptOptions = new PromptOptions + { + Prompt = "a photo of a cat drinking at a bar with a penguin" + }; + + // Scheduler + var schedulerOptions = pipeline.DefaultSchedulerOptions with + { + InferenceSteps = 1, + GuidanceScale = 0, + SchedulerType = SchedulerType.DDIM, + Timesteps = new List { 800 } + }; + + // Run pipeline + var result = await pipeline.RunAsync(promptOptions, schedulerOptions, progressCallback: OutputHelpers.ProgressCallback); + + // Create Image from Tensor result + var image = new OnnxImage(result); + + // Save Image File + await image.SaveAsync(Path.Combine(_outputDirectory, $"{pipeline.GetType().Name}-{schedulerOptions.Seed}.png")); + + //Unload + await pipeline.UnloadAsync(); + } + } +}