pull/73/head
Timothy Kautz 3 years ago
parent 0a1b2b87b3
commit cacf99d130

@ -33,6 +33,12 @@ struct StableDiffusionSample: ParsableCommand {
) )
var resourcePath: String = "./" var resourcePath: String = "./"
@Option(help: "Path to starting image.")
var image: String = "none"
@Option(help: "Strength for image2image.")
var strength: Float = 0.5
@Option(help: "Number of images to sample / generate") @Option(help: "Number of images to sample / generate")
var imageCount: Int = 1 var imageCount: Int = 1
@ -51,7 +57,7 @@ struct StableDiffusionSample: ParsableCommand {
var outputPath: String = "./" var outputPath: String = "./"
@Option(help: "Random seed") @Option(help: "Random seed")
var seed: UInt32 = 93 var seed: UInt32 = UInt32.random(in: 0...UInt32.max)
@Option(help: "Controls the influence of the text prompt on sampling process (0=random images)") @Option(help: "Controls the influence of the text prompt on sampling process (0=random images)")
var guidanceScale: Float = 7.5 var guidanceScale: Float = 7.5
@ -85,6 +91,32 @@ struct StableDiffusionSample: ParsableCommand {
reduceMemory: reduceMemory) reduceMemory: reduceMemory)
try pipeline.loadResources() try pipeline.loadResources()
let startingImage: CGImage?
if image != "none" {
let imageURL = URL(filePath: image)
// if FileManager.default.fileExists(atPath: imageURL.path()) {
// throw RunError.resources("Starting image not found \(imageURL)")
// }
do {
let imageData = try Data(contentsOf: imageURL)
guard
let imgDataProvider = CGDataProvider(data: imageData as CFData),
let loadedImage = CGImage(
pngDataProviderSource: imgDataProvider,
decode: nil, shouldInterpolate: false,
intent: CGColorRenderingIntent.defaultIntent)
else {
throw RunError.resources("Starting Image not available \(resourcePath)")
}
startingImage = loadedImage
} catch let error {
throw RunError.resources("Starting image not found \(imageURL), error: \(error)")
}
} else {
startingImage = nil
}
log("Sampling ...\n") log("Sampling ...\n")
let sampleTimer = SampleTimer() let sampleTimer = SampleTimer()
sampleTimer.start() sampleTimer.start()
@ -92,6 +124,8 @@ struct StableDiffusionSample: ParsableCommand {
let images = try pipeline.generateImages( let images = try pipeline.generateImages(
prompt: prompt, prompt: prompt,
negativePrompt: negativePrompt, negativePrompt: negativePrompt,
startingImage: startingImage,
strength: strength,
imageCount: imageCount, imageCount: imageCount,
stepCount: stepCount, stepCount: stepCount,
seed: seed, seed: seed,
@ -169,6 +203,10 @@ struct StableDiffusionSample: ParsableCommand {
name += ".\(sample)" name += ".\(sample)"
} }
if image != "none" {
name += ".str\(Int(strength * 100))"
}
name += ".\(seed)" name += ".\(seed)"
if let step = step { if let step = step {

Loading…
Cancel
Save