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