Unify seed type to UInt32.

Otherwise the app may crash when attempting to use a random Int as a seed.
pull/58/head
Pedro Cuenca 3 years ago
parent 583cc04ece
commit 616255f8e3

@ -68,7 +68,7 @@ public struct StableDiffusionPipeline {
prompt: String,
imageCount: Int = 1,
stepCount: Int = 50,
seed: Int = 0,
seed: UInt32 = 0,
disableSafety: Bool = false,
progressHandler: (Progress) -> Bool = { _ in true }
) throws -> [CGImage?] {
@ -140,11 +140,11 @@ public struct StableDiffusionPipeline {
return try decodeToImages(latents, disableSafety: disableSafety)
}
func generateLatentSamples(_ count: Int, stdev: Float, seed: Int) -> [MLShapedArray<Float32>] {
func generateLatentSamples(_ count: Int, stdev: Float, seed: UInt32) -> [MLShapedArray<Float32>] {
var sampleShape = unet.latentSampleShape
sampleShape[0] = 1
var random = NumPyRandomSource(seed: UInt32(seed))
var random = NumPyRandomSource(seed: seed)
let samples = (0..<count).map { _ in
MLShapedArray<Float32>(
converting: random.normalShapedArray(sampleShape, mean: 0.0, stdev: Double(stdev)))

@ -47,7 +47,7 @@ struct StableDiffusionSample: ParsableCommand {
var outputPath: String = "./"
@Option(help: "Random seed")
var seed: Int = 93
var seed: UInt32 = 93
@Option(help: "Compute units to load model with {all,cpuOnly,cpuAndGPU,cpuAndNeuralEngine}")
var computeUnits: ComputeUnits = .all

Loading…
Cancel
Save