mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2025-12-12 13:28:35 +00:00
Updated stablediffussion.cpp to a469688
This commit is contained in:
parent
64fd98643b
commit
631c8ca180
@ -13,7 +13,10 @@ public class ModelParameter
|
||||
public string VaePath { get; set; } = string.Empty;
|
||||
public string ControlNetPath { get; set; } = string.Empty;
|
||||
public string EmbeddingsDirectory { get; set; } = string.Empty;
|
||||
public string StackedIdEmbeddingsDirectory { get; set; } = string.Empty;
|
||||
public bool KeepControlNetOnCPU { get; set; } = false;
|
||||
public bool KeepClipOnCPU { get; set; } = false;
|
||||
public bool KeepVaeOnCPU { get; set; } = false;
|
||||
|
||||
//TODO DarthAffe 01.01.2024: K-Quants doesn't seem to work so far
|
||||
public Quantization Quantization { get; set; } = Quantization.F16;
|
||||
|
||||
@ -55,6 +55,7 @@ internal unsafe partial class Native
|
||||
[MarshalAs(UnmanagedType.LPStr)] string control_net_path_c_str,
|
||||
[MarshalAs(UnmanagedType.LPStr)] string lora_model_dir,
|
||||
[MarshalAs(UnmanagedType.LPStr)] string embed_dir_c_str,
|
||||
[MarshalAs(UnmanagedType.LPStr)] string stacked_id_embed_dir_c_str,
|
||||
[MarshalAs(UnmanagedType.I1)] bool vae_decode_only,
|
||||
[MarshalAs(UnmanagedType.I1)] bool vae_tiling,
|
||||
[MarshalAs(UnmanagedType.I1)] bool free_params_immediately,
|
||||
@ -62,7 +63,9 @@ internal unsafe partial class Native
|
||||
sd_type_t wtype,
|
||||
rng_type_t rng_type,
|
||||
schedule_t s,
|
||||
[MarshalAs(UnmanagedType.I1)] bool keep_control_net_cpu);
|
||||
[MarshalAs(UnmanagedType.I1)] bool keep_clip_on_cpu,
|
||||
[MarshalAs(UnmanagedType.I1)] bool keep_control_net_cpu,
|
||||
[MarshalAs(UnmanagedType.I1)] bool keep_vae_on_cpu);
|
||||
|
||||
[LibraryImport(LIB_NAME, EntryPoint = "free_sd_ctx")]
|
||||
internal static partial void free_sd_ctx(sd_ctx_t* sd_ctx);
|
||||
@ -80,7 +83,10 @@ internal unsafe partial class Native
|
||||
long seed,
|
||||
int batch_count,
|
||||
sd_image_t* control_cond,
|
||||
float control_strength);
|
||||
float control_strength,
|
||||
float style_strength,
|
||||
[MarshalAs(UnmanagedType.I1)] bool normalize_input,
|
||||
[MarshalAs(UnmanagedType.LPStr)] string input_id_images_path);
|
||||
|
||||
[LibraryImport(LIB_NAME, EntryPoint = "img2img")]
|
||||
internal static partial sd_image_t* img2img(sd_ctx_t* sd_ctx,
|
||||
|
||||
@ -56,6 +56,7 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
||||
_parameter.ControlNetPath,
|
||||
_parameter.LoraModelDir,
|
||||
_parameter.EmbeddingsDirectory,
|
||||
_parameter.StackedIdEmbeddingsDirectory,
|
||||
_parameter.VaeDecodeOnly,
|
||||
_parameter.VaeTiling,
|
||||
false,
|
||||
@ -63,7 +64,9 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
||||
_parameter.Quantization,
|
||||
_parameter.RngType,
|
||||
_parameter.Schedule,
|
||||
_parameter.KeepControlNetOnCPU);
|
||||
_parameter.KeepClipOnCPU,
|
||||
_parameter.KeepControlNetOnCPU,
|
||||
_parameter.KeepVaeOnCPU);
|
||||
if (_ctx == null) throw new NullReferenceException("Failed to initialize Stable Diffusion");
|
||||
|
||||
if (_upscalerParameter != null)
|
||||
@ -114,7 +117,10 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
||||
parameter.Seed,
|
||||
1,
|
||||
&controlNetImage,
|
||||
parameter.ControlNet.Strength);
|
||||
parameter.ControlNet.Strength,
|
||||
parameter.PhotoMaker.StyleRatio,
|
||||
parameter.PhotoMaker.NormalizeInput,
|
||||
parameter.PhotoMaker.InputIdImageDirectory);
|
||||
|
||||
Marshal.FreeHGlobal((nint)controlNetImage.data);
|
||||
}
|
||||
@ -140,7 +146,10 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
||||
parameter.Seed,
|
||||
1,
|
||||
&controlNetImage,
|
||||
parameter.ControlNet.Strength);
|
||||
parameter.ControlNet.Strength,
|
||||
parameter.PhotoMaker.StyleRatio,
|
||||
parameter.PhotoMaker.NormalizeInput,
|
||||
parameter.PhotoMaker.InputIdImageDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -158,7 +167,10 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
||||
parameter.Seed,
|
||||
1,
|
||||
null,
|
||||
0);
|
||||
0,
|
||||
parameter.PhotoMaker.StyleRatio,
|
||||
parameter.PhotoMaker.NormalizeInput,
|
||||
parameter.PhotoMaker.InputIdImageDirectory);
|
||||
}
|
||||
|
||||
return new StableDiffusionImage(result);
|
||||
|
||||
@ -15,6 +15,7 @@ public sealed class StableDiffusionParameter
|
||||
public int ClipSkip { get; set; } = -1;
|
||||
|
||||
public StableDiffusionControlNetParameter ControlNet { get; } = new();
|
||||
public PhotoMakerParameter PhotoMaker { get; } = new();
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -31,4 +32,11 @@ public sealed class StableDiffusionControlNetParameter
|
||||
public float CannyWeak { get; set; } = 0.8f;
|
||||
public float CannyStrong { get; set; } = 1.0f;
|
||||
public bool CannyInverse { get; set; } = false;
|
||||
}
|
||||
|
||||
public sealed class PhotoMakerParameter
|
||||
{
|
||||
public string InputIdImageDirectory { get; set; } = string.Empty;
|
||||
public float StyleRatio { get; set; } = 20f;
|
||||
public bool NormalizeInput { get; set; } = false;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user