1
1
using OnnxStack . Core . Image ;
2
2
using OnnxStack . StableDiffusion . Config ;
3
+ using OnnxStack . StableDiffusion . Enums ;
3
4
using OnnxStack . StableDiffusion . Pipelines ;
4
5
using SixLabors . ImageSharp ;
5
6
using System . Diagnostics ;
@@ -15,6 +16,7 @@ public StableCascadeExample(StableDiffusionConfig configuration)
15
16
{
16
17
_configuration = configuration ;
17
18
_outputDirectory = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Examples" , nameof ( StableCascadeExample ) ) ;
19
+ Directory . CreateDirectory ( _outputDirectory ) ;
18
20
}
19
21
20
22
public int Index => 20 ;
@@ -28,46 +30,25 @@ public StableCascadeExample(StableDiffusionConfig configuration)
28
30
/// </summary>
29
31
public async Task RunAsync ( )
30
32
{
31
- Directory . CreateDirectory ( _outputDirectory ) ;
32
-
33
-
34
- var prompt = "photo of a cat" ;
33
+ // Prompt
35
34
var promptOptions = new PromptOptions
36
35
{
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"),
38
39
} ;
39
40
40
41
// 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 ) ;
59
43
60
44
// 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 ) ;
64
46
65
47
// Save Image File
66
- await image . SaveAsync ( Path . Combine ( _outputDirectory , $ "output.png") ) ;
48
+ await result . SaveAsync ( Path . Combine ( _outputDirectory , $ "output.png") ) ;
67
49
50
+ // Unload
68
51
await pipeline . UnloadAsync ( ) ;
69
-
70
-
71
52
}
72
53
}
73
54
}
0 commit comments