mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2025-12-13 05:48:40 +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.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public static class Backends
|
public static class Backends
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
using System;
|
using JetBrains.Annotations;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public class CpuBackend : IBackend
|
public class CpuBackend : IBackend
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|||||||
@ -5,9 +5,11 @@ using System;
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public partial class CudaBackend : IBackend
|
public partial class CudaBackend : IBackend
|
||||||
{
|
{
|
||||||
#region Constants
|
#region Constants
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
namespace StableDiffusion.NET;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public interface IBackend
|
public interface IBackend
|
||||||
{
|
{
|
||||||
bool IsEnabled { get; set; }
|
bool IsEnabled { get; set; }
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using StableDiffusion.NET.Helper;
|
using StableDiffusion.NET.Helper;
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public partial class RocmBackend : IBackend
|
public partial class RocmBackend : IBackend
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
namespace StableDiffusion.NET;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public class ModelParameter
|
public class ModelParameter
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|||||||
@ -101,7 +101,12 @@ internal unsafe partial class Native
|
|||||||
int sample_steps,
|
int sample_steps,
|
||||||
float strength,
|
float strength,
|
||||||
long seed,
|
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")]
|
[LibraryImport(LIB_NAME, EntryPoint = "img2vid")]
|
||||||
internal static partial sd_image_t* img2vid(sd_ctx_t* sd_ctx,
|
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="\" />
|
<Content Include="sd_net.png" Link="sd_net.png" Pack="true" PackagePath="\" />
|
||||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
using System;
|
using JetBrains.Annotations;
|
||||||
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public sealed unsafe class StableDiffusionImage : IDisposable
|
public sealed unsafe class StableDiffusionImage : IDisposable
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace StableDiffusion.NET;
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public sealed unsafe class StableDiffusionModel : IDisposable
|
public sealed unsafe class StableDiffusionModel : IDisposable
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
@ -206,7 +208,30 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
|||||||
{
|
{
|
||||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||||
|
|
||||||
Native.sd_image_t* result = Native.img2img(_ctx,
|
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,
|
image,
|
||||||
prompt,
|
prompt,
|
||||||
parameter.NegativePrompt,
|
parameter.NegativePrompt,
|
||||||
@ -218,8 +243,67 @@ public sealed unsafe class StableDiffusionModel : IDisposable
|
|||||||
parameter.SampleSteps,
|
parameter.SampleSteps,
|
||||||
parameter.Strength,
|
parameter.Strength,
|
||||||
parameter.Seed,
|
parameter.Seed,
|
||||||
1);
|
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);
|
return new StableDiffusionImage(result);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
namespace StableDiffusion.NET;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public sealed class StableDiffusionParameter
|
public sealed class StableDiffusionParameter
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
@ -20,6 +23,7 @@ public sealed class StableDiffusionParameter
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public sealed class StableDiffusionControlNetParameter
|
public sealed class StableDiffusionControlNetParameter
|
||||||
{
|
{
|
||||||
public bool IsEnabled => Image?.Length > 0;
|
public bool IsEnabled => Image?.Length > 0;
|
||||||
@ -34,6 +38,7 @@ public sealed class StableDiffusionControlNetParameter
|
|||||||
public bool CannyInverse { get; set; } = false;
|
public bool CannyInverse { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public sealed class PhotoMakerParameter
|
public sealed class PhotoMakerParameter
|
||||||
{
|
{
|
||||||
public string InputIdImageDirectory { get; set; } = string.Empty;
|
public string InputIdImageDirectory { get; set; } = string.Empty;
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
namespace StableDiffusion.NET;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
namespace StableDiffusion.NET;
|
||||||
|
|
||||||
|
[PublicAPI]
|
||||||
public class UpscalerModelParameter
|
public class UpscalerModelParameter
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|||||||
@ -4,7 +4,7 @@ if not exist stable-diffusion.cpp (
|
|||||||
|
|
||||||
cd stable-diffusion.cpp
|
cd stable-diffusion.cpp
|
||||||
git fetch
|
git fetch
|
||||||
git checkout 48bcce493f45a11d9d5a4c69943d03ff919d748f
|
git checkout ec82d5279ab7d3b20d95bf1e803c78306030e6b1
|
||||||
git submodule init
|
git submodule init
|
||||||
git submodule update
|
git submodule update
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user