@@ -62,6 +62,9 @@ struct StableDiffusionSample: ParsableCommand {
62
62
@Flag ( help: " Reduce memory usage " )
63
63
var reduceMemory : Bool = false
64
64
65
+ @Flag ( help: " Increse random seed by 1 for each image " )
66
+ var incrementSeed : Bool = false
67
+
65
68
mutating func run( ) throws {
66
69
guard FileManager . default. fileExists ( atPath: resourcePath) else {
67
70
throw RunError . resources ( " Resource path does not exist \( resourcePath) " )
@@ -83,22 +86,36 @@ struct StableDiffusionSample: ParsableCommand {
83
86
let sampleTimer = SampleTimer ( )
84
87
sampleTimer. start ( )
85
88
86
- let images = try pipeline. generateImages (
87
- prompt: prompt,
88
- imageCount: imageCount,
89
- stepCount: stepCount,
90
- seed: seed,
91
- scheduler: scheduler. stableDiffusionScheduler
92
- ) { progress in
93
- sampleTimer. stop ( )
94
- handleProgress ( progress, sampleTimer)
95
- if progress. stepCount != progress. step {
96
- sampleTimer. start ( )
89
+ let loops = incrementSeed ? imageCount : 1
90
+ let imageCountPerBatch = incrementSeed ? 1 : imageCount
91
+
92
+ for i in 0 ..< loops {
93
+ if ( incrementSeed) {
94
+ log ( " Generating image \( i+ 1 ) of \( imageCount) with seed \( seed) \n " )
95
+ log ( " \n " )
97
96
}
98
- return true
99
- }
100
97
101
- _ = try saveImages ( images, logNames: true )
98
+ let images = try pipeline. generateImages (
99
+ prompt: prompt,
100
+ imageCount: imageCountPerBatch,
101
+ stepCount: stepCount,
102
+ seed: seed,
103
+ scheduler: scheduler. stableDiffusionScheduler
104
+ ) { progress in
105
+ sampleTimer. stop ( )
106
+ handleProgress ( progress, sampleTimer)
107
+ if progress. stepCount != progress. step {
108
+ sampleTimer. start ( )
109
+ }
110
+ return true
111
+ }
112
+
113
+ _ = try saveImages ( images, logNames: true )
114
+
115
+ if ( incrementSeed) {
116
+ seed += 1
117
+ }
118
+ }
102
119
}
103
120
104
121
func handleProgress(
0 commit comments