|
| 1 | +using OnnxStack.Core.Image; |
| 2 | +using OnnxStack.StableDiffusion.Config; |
| 3 | +using OnnxStack.StableDiffusion.Enums; |
| 4 | +using OnnxStack.StableDiffusion.Pipelines; |
| 5 | + |
| 6 | +namespace OnnxStack.Console.Runner |
| 7 | +{ |
| 8 | + public sealed class ModelDebug : IExampleRunner |
| 9 | + { |
| 10 | + private readonly string _outputDirectory; |
| 11 | + private readonly StableDiffusionConfig _configuration; |
| 12 | + |
| 13 | + public ModelDebug(StableDiffusionConfig configuration) |
| 14 | + { |
| 15 | + _configuration = configuration; |
| 16 | + _outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Examples", nameof(ModelDebug)); |
| 17 | + Directory.CreateDirectory(_outputDirectory); |
| 18 | + } |
| 19 | + |
| 20 | + public int Index => 1; |
| 21 | + |
| 22 | + public string Name => "Model Debug"; |
| 23 | + |
| 24 | + public string Description => "Model Debug"; |
| 25 | + |
| 26 | + public async Task RunAsync() |
| 27 | + { |
| 28 | + // Create Pipeline |
| 29 | + // var pipeline = InstaFlowPipeline.CreatePipeline("D:\\Repositories\\Instaflow-onnx"); |
| 30 | + // var pipeline = LatentConsistencyPipeline.CreatePipeline("D:\\Repositories\\LCM_Dreamshaper_v7-onnx"); |
| 31 | + // var pipeline = LatentConsistencyXLPipeline.CreatePipeline("D:\\Repositories\\Latent-Consistency-xl-Olive-Onnx"); |
| 32 | + // var pipeline = StableDiffusionPipeline.CreatePipeline("D:\\Repositories\\stable-diffusion-v1-5"); |
| 33 | + var pipeline = StableDiffusionXLPipeline.CreatePipeline("D:\\Repositories\\Hyper-SD-onnx"); |
| 34 | + |
| 35 | + // Prompt |
| 36 | + var promptOptions = new PromptOptions |
| 37 | + { |
| 38 | + Prompt = "a photo of a cat drinking at a bar with a penguin" |
| 39 | + }; |
| 40 | + |
| 41 | + // Scheduler |
| 42 | + var schedulerOptions = pipeline.DefaultSchedulerOptions with |
| 43 | + { |
| 44 | + InferenceSteps = 1, |
| 45 | + GuidanceScale = 0, |
| 46 | + SchedulerType = SchedulerType.DDIM, |
| 47 | + Timesteps = new List<int> { 800 } |
| 48 | + }; |
| 49 | + |
| 50 | + // Run pipeline |
| 51 | + var result = await pipeline.RunAsync(promptOptions, schedulerOptions, progressCallback: OutputHelpers.ProgressCallback); |
| 52 | + |
| 53 | + // Create Image from Tensor result |
| 54 | + var image = new OnnxImage(result); |
| 55 | + |
| 56 | + // Save Image File |
| 57 | + await image.SaveAsync(Path.Combine(_outputDirectory, $"{pipeline.GetType().Name}-{schedulerOptions.Seed}.png")); |
| 58 | + |
| 59 | + //Unload |
| 60 | + await pipeline.UnloadAsync(); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
0 commit comments