Skip to content

Commit

Permalink
add --increment-seed argument
Browse files Browse the repository at this point in the history
  • Loading branch information
hirakujira committed Dec 16, 2022
1 parent 66dde8d commit 5e9fd04
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions swift/StableDiffusionCLI/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ struct StableDiffusionSample: ParsableCommand {
@Flag(help: "Reduce memory usage")
var reduceMemory: Bool = false

@Flag(help: "Increse random seed by 1 for each image")
var incrementSeed: Bool = false

mutating func run() throws {
guard FileManager.default.fileExists(atPath: resourcePath) else {
throw RunError.resources("Resource path does not exist \(resourcePath)")
Expand All @@ -83,22 +86,36 @@ struct StableDiffusionSample: ParsableCommand {
let sampleTimer = SampleTimer()
sampleTimer.start()

let images = try pipeline.generateImages(
prompt: prompt,
imageCount: imageCount,
stepCount: stepCount,
seed: seed,
scheduler: scheduler.stableDiffusionScheduler
) { progress in
sampleTimer.stop()
handleProgress(progress,sampleTimer)
if progress.stepCount != progress.step {
sampleTimer.start()
let loops = incrementSeed ? imageCount : 1
let imageCountPerBatch = incrementSeed ? 1 : imageCount

for i in 0 ..< loops {
if (incrementSeed) {
log("Generating image \(i+1) of \(imageCount) with seed \(seed)\n")
log("\n")
}
return true
}

_ = try saveImages(images, logNames: true)
let images = try pipeline.generateImages(
prompt: prompt,
imageCount: imageCountPerBatch,
stepCount: stepCount,
seed: seed,
scheduler: scheduler.stableDiffusionScheduler
) { progress in
sampleTimer.stop()
handleProgress(progress,sampleTimer)
if progress.stepCount != progress.step {
sampleTimer.start()
}
return true
}

_ = try saveImages(images, logNames: true)

if (incrementSeed) {
seed += 1
}
}
}

func handleProgress(
Expand Down

0 comments on commit 5e9fd04

Please sign in to comment.