11using OnnxStack . Core . Image ;
22using OnnxStack . StableDiffusion . Config ;
3+ using OnnxStack . StableDiffusion . Enums ;
34using OnnxStack . StableDiffusion . Pipelines ;
45using SixLabors . ImageSharp ;
56using 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}
0 commit comments