mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2025-12-13 05:48:40 +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 VaePath { get; set; } = string.Empty;
|
||||||
public string ControlNetPath { get; set; } = string.Empty;
|
public string ControlNetPath { get; set; } = string.Empty;
|
||||||
public string EmbeddingsDirectory { 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 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
|
//TODO DarthAffe 01.01.2024: K-Quants doesn't seem to work so far
|
||||||
public Quantization Quantization { get; set; } = Quantization.F16;
|
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 control_net_path_c_str,
|
||||||
[MarshalAs(UnmanagedType.LPStr)] string lora_model_dir,
|
[MarshalAs(UnmanagedType.LPStr)] string lora_model_dir,
|
||||||
[MarshalAs(UnmanagedType.LPStr)] string embed_dir_c_str,
|
[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_decode_only,
|
||||||
[MarshalAs(UnmanagedType.I1)] bool vae_tiling,
|
[MarshalAs(UnmanagedType.I1)] bool vae_tiling,
|
||||||
[MarshalAs(UnmanagedType.I1)] bool free_params_immediately,
|
[MarshalAs(UnmanagedType.I1)] bool free_params_immediately,
|
||||||
@ -62,7 +63,9 @@ internal unsafe partial class Native
|
|||||||
sd_type_t wtype,
|
sd_type_t wtype,
|
||||||
rng_type_t rng_type,
|
rng_type_t rng_type,
|
||||||
schedule_t s,
|
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")]
|
[LibraryImport(LIB_NAME, EntryPoint = "free_sd_ctx")]
|
||||||
internal static partial void free_sd_ctx(sd_ctx_t* 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,
|
long seed,
|
||||||
int batch_count,
|
int batch_count,
|
||||||
sd_image_t* control_cond,
|
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")]
|
[LibraryImport(LIB_NAME, EntryPoint = "img2img")]
|
||||||
internal static partial sd_image_t* img2img(sd_ctx_t* sd_ctx,
|
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.ControlNetPath,
|
||||||
_parameter.LoraModelDir,
|
_parameter.LoraModelDir,
|
||||||
_parameter.EmbeddingsDirectory,
|
_parameter.EmbeddingsDirectory,
|
||||||
|
_parameter.StackedIdEmbeddingsDirectory,
|
||||||
_parameter.VaeDecodeOnly,
|
_parameter.VaeDecodeOnly,
|
||||||
_parameter.VaeTiling,
|
_parameter.VaeTiling,
|
||||||
false,
|
false,
|
||||||
@ -63,7 +64,9 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
|||||||
_parameter.Quantization,
|
_parameter.Quantization,
|
||||||
_parameter.RngType,
|
_parameter.RngType,
|
||||||
_parameter.Schedule,
|
_parameter.Schedule,
|
||||||
_parameter.KeepControlNetOnCPU);
|
_parameter.KeepClipOnCPU,
|
||||||
|
_parameter.KeepControlNetOnCPU,
|
||||||
|
_parameter.KeepVaeOnCPU);
|
||||||
if (_ctx == null) throw new NullReferenceException("Failed to initialize Stable Diffusion");
|
if (_ctx == null) throw new NullReferenceException("Failed to initialize Stable Diffusion");
|
||||||
|
|
||||||
if (_upscalerParameter != null)
|
if (_upscalerParameter != null)
|
||||||
@ -114,7 +117,10 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
|||||||
parameter.Seed,
|
parameter.Seed,
|
||||||
1,
|
1,
|
||||||
&controlNetImage,
|
&controlNetImage,
|
||||||
parameter.ControlNet.Strength);
|
parameter.ControlNet.Strength,
|
||||||
|
parameter.PhotoMaker.StyleRatio,
|
||||||
|
parameter.PhotoMaker.NormalizeInput,
|
||||||
|
parameter.PhotoMaker.InputIdImageDirectory);
|
||||||
|
|
||||||
Marshal.FreeHGlobal((nint)controlNetImage.data);
|
Marshal.FreeHGlobal((nint)controlNetImage.data);
|
||||||
}
|
}
|
||||||
@ -140,7 +146,10 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
|||||||
parameter.Seed,
|
parameter.Seed,
|
||||||
1,
|
1,
|
||||||
&controlNetImage,
|
&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,
|
parameter.Seed,
|
||||||
1,
|
1,
|
||||||
null,
|
null,
|
||||||
0);
|
0,
|
||||||
|
parameter.PhotoMaker.StyleRatio,
|
||||||
|
parameter.PhotoMaker.NormalizeInput,
|
||||||
|
parameter.PhotoMaker.InputIdImageDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new StableDiffusionImage(result);
|
return new StableDiffusionImage(result);
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public sealed class StableDiffusionParameter
|
|||||||
public int ClipSkip { get; set; } = -1;
|
public int ClipSkip { get; set; } = -1;
|
||||||
|
|
||||||
public StableDiffusionControlNetParameter ControlNet { get; } = new();
|
public StableDiffusionControlNetParameter ControlNet { get; } = new();
|
||||||
|
public PhotoMakerParameter PhotoMaker { get; } = new();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@ -31,4 +32,11 @@ public sealed class StableDiffusionControlNetParameter
|
|||||||
public float CannyWeak { get; set; } = 0.8f;
|
public float CannyWeak { get; set; } = 0.8f;
|
||||||
public float CannyStrong { get; set; } = 1.0f;
|
public float CannyStrong { get; set; } = 1.0f;
|
||||||
public bool CannyInverse { get; set; } = false;
|
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;
|
||||||
}
|
}
|
||||||
@ -4,7 +4,7 @@ if not exist stable-diffusion.cpp (
|
|||||||
|
|
||||||
cd stable-diffusion.cpp
|
cd stable-diffusion.cpp
|
||||||
git fetch
|
git fetch
|
||||||
git checkout 1ce9470f27d480c6aa5d43c0af5b60db99454252
|
git checkout a469688e30122d3b6c1faa5b36ffc3261e6deb82
|
||||||
git submodule init
|
git submodule init
|
||||||
git submodule update
|
git submodule update
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user