mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2025-12-12 13:28:35 +00:00
Updated stable-diffusion.cpp to ec82d52
This commit is contained in:
parent
9c7daf6e53
commit
78a21e41ba
@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public static class Backends
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public class CpuBackend : IBackend
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@ -5,9 +5,11 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public partial class CudaBackend : IBackend
|
||||
{
|
||||
#region Constants
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
namespace StableDiffusion.NET;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public interface IBackend
|
||||
{
|
||||
bool IsEnabled { get; set; }
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using JetBrains.Annotations;
|
||||
using StableDiffusion.NET.Helper;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public partial class RocmBackend : IBackend
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
namespace StableDiffusion.NET;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public class ModelParameter
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@ -101,7 +101,12 @@ internal unsafe partial class Native
|
||||
int sample_steps,
|
||||
float strength,
|
||||
long seed,
|
||||
int batch_count);
|
||||
int batch_count,
|
||||
sd_image_t* control_cond,
|
||||
float control_strength,
|
||||
float style_strength,
|
||||
[MarshalAs(UnmanagedType.I1)] bool normalize_input,
|
||||
[MarshalAs(UnmanagedType.LPStr)] string input_id_images_path);
|
||||
|
||||
[LibraryImport(LIB_NAME, EntryPoint = "img2vid")]
|
||||
internal static partial sd_image_t* img2vid(sd_ctx_t* sd_ctx,
|
||||
|
||||
@ -53,4 +53,8 @@
|
||||
<Content Include="sd_net.png" Link="sd_net.png" Pack="true" PackagePath="\" />
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public sealed unsafe class StableDiffusionImage : IDisposable
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public sealed unsafe class StableDiffusionModel : IDisposable
|
||||
{
|
||||
#region Properties & Fields
|
||||
@ -206,20 +208,102 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
Native.sd_image_t* result = Native.img2img(_ctx,
|
||||
image,
|
||||
prompt,
|
||||
parameter.NegativePrompt,
|
||||
parameter.ClipSkip,
|
||||
parameter.CfgScale,
|
||||
parameter.Width,
|
||||
parameter.Height,
|
||||
parameter.SampleMethod,
|
||||
parameter.SampleSteps,
|
||||
parameter.Strength,
|
||||
parameter.Seed,
|
||||
1);
|
||||
Native.sd_image_t* result;
|
||||
if (parameter.ControlNet.IsEnabled)
|
||||
{
|
||||
fixed (byte* imagePtr = parameter.ControlNet.Image)
|
||||
{
|
||||
|
||||
if (parameter.ControlNet.CannyPreprocess)
|
||||
{
|
||||
Native.sd_image_t controlNetImage = new()
|
||||
{
|
||||
width = (uint)parameter.Width,
|
||||
height = (uint)parameter.Height,
|
||||
channel = 3,
|
||||
data = Native.preprocess_canny(imagePtr,
|
||||
parameter.Width,
|
||||
parameter.Height,
|
||||
parameter.ControlNet.CannyHighThreshold,
|
||||
parameter.ControlNet.CannyLowThreshold,
|
||||
parameter.ControlNet.CannyWeak,
|
||||
parameter.ControlNet.CannyStrong,
|
||||
parameter.ControlNet.CannyInverse)
|
||||
};
|
||||
|
||||
result = Native.img2img(_ctx,
|
||||
image,
|
||||
prompt,
|
||||
parameter.NegativePrompt,
|
||||
parameter.ClipSkip,
|
||||
parameter.CfgScale,
|
||||
parameter.Width,
|
||||
parameter.Height,
|
||||
parameter.SampleMethod,
|
||||
parameter.SampleSteps,
|
||||
parameter.Strength,
|
||||
parameter.Seed,
|
||||
1,
|
||||
&controlNetImage,
|
||||
parameter.ControlNet.Strength,
|
||||
parameter.PhotoMaker.StyleRatio,
|
||||
parameter.PhotoMaker.NormalizeInput,
|
||||
parameter.PhotoMaker.InputIdImageDirectory);
|
||||
|
||||
Marshal.FreeHGlobal((nint)controlNetImage.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Native.sd_image_t controlNetImage = new()
|
||||
{
|
||||
width = (uint)parameter.Width,
|
||||
height = (uint)parameter.Height,
|
||||
channel = 3,
|
||||
data = imagePtr
|
||||
};
|
||||
|
||||
result = Native.img2img(_ctx,
|
||||
image,
|
||||
prompt,
|
||||
parameter.NegativePrompt,
|
||||
parameter.ClipSkip,
|
||||
parameter.CfgScale,
|
||||
parameter.Width,
|
||||
parameter.Height,
|
||||
parameter.SampleMethod,
|
||||
parameter.SampleSteps,
|
||||
parameter.Strength,
|
||||
parameter.Seed,
|
||||
1,
|
||||
&controlNetImage,
|
||||
parameter.ControlNet.Strength,
|
||||
parameter.PhotoMaker.StyleRatio,
|
||||
parameter.PhotoMaker.NormalizeInput,
|
||||
parameter.PhotoMaker.InputIdImageDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Native.img2img(_ctx,
|
||||
image,
|
||||
prompt,
|
||||
parameter.NegativePrompt,
|
||||
parameter.ClipSkip,
|
||||
parameter.CfgScale,
|
||||
parameter.Width,
|
||||
parameter.Height,
|
||||
parameter.SampleMethod,
|
||||
parameter.SampleSteps,
|
||||
parameter.Strength,
|
||||
parameter.Seed,
|
||||
1,
|
||||
null,
|
||||
0,
|
||||
parameter.PhotoMaker.StyleRatio,
|
||||
parameter.PhotoMaker.NormalizeInput,
|
||||
parameter.PhotoMaker.InputIdImageDirectory);
|
||||
}
|
||||
|
||||
return new StableDiffusionImage(result);
|
||||
}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
namespace StableDiffusion.NET;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public sealed class StableDiffusionParameter
|
||||
{
|
||||
#region Properties & Fields
|
||||
@ -20,6 +23,7 @@ public sealed class StableDiffusionParameter
|
||||
#endregion
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public sealed class StableDiffusionControlNetParameter
|
||||
{
|
||||
public bool IsEnabled => Image?.Length > 0;
|
||||
@ -34,6 +38,7 @@ public sealed class StableDiffusionControlNetParameter
|
||||
public bool CannyInverse { get; set; } = false;
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public sealed class PhotoMakerParameter
|
||||
{
|
||||
public string InputIdImageDirectory { get; set; } = string.Empty;
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
namespace StableDiffusion.NET;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace StableDiffusion.NET;
|
||||
|
||||
[PublicAPI]
|
||||
public class UpscalerModelParameter
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user