Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Image Upscale Project #61

Merged
merged 4 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion OnnxStack.Console/Examples/StableDiffusionGif.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OnnxStack.StableDiffusion;
using OnnxStack.Core.Image;
using OnnxStack.StableDiffusion;
using OnnxStack.StableDiffusion.Common;
using OnnxStack.StableDiffusion.Config;
using OnnxStack.StableDiffusion.Enums;
Expand Down
52 changes: 52 additions & 0 deletions OnnxStack.Console/Examples/UpscaleExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using OnnxStack.Core.Image;
using OnnxStack.ImageUpscaler.Services;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

namespace OnnxStack.Console.Runner
{
public sealed class UpscaleExample : IExampleRunner
{
private readonly string _outputDirectory;
private readonly IUpscaleService _imageUpscaleService;


public UpscaleExample(IUpscaleService imageUpscaleService)
{
_imageUpscaleService = imageUpscaleService;
_outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Examples", nameof(UpscaleExample));
Directory.CreateDirectory(_outputDirectory);
}

public string Name => "Image Upscale Demo";

public string Description => "Upscales images";

public async Task RunAsync()
{
var modelSet = _imageUpscaleService.ModelSets.FirstOrDefault(x => x.Name == "RealSR BSRGAN x4");



OutputHelpers.WriteConsole("Enter Image Path", ConsoleColor.Yellow);
var imageFile = OutputHelpers.ReadConsole(ConsoleColor.Gray);
if (!File.Exists(imageFile))
{
OutputHelpers.WriteConsole("File not found!", ConsoleColor.Red);
return;
}

OutputHelpers.WriteConsole("Loading Model...", ConsoleColor.Cyan);
await _imageUpscaleService.LoadModelAsync(modelSet);
OutputHelpers.WriteConsole("Model Loaded.", ConsoleColor.Cyan);

var inputImage = await Image.LoadAsync<Rgba32>(imageFile);

OutputHelpers.WriteConsole("Upscaling Image...", ConsoleColor.Cyan);
var result = await _imageUpscaleService.GenerateAsImageAsync(modelSet, new InputImage(inputImage));
await result.SaveAsPngAsync(Path.Combine(_outputDirectory, "Result.png"));
OutputHelpers.WriteConsole("Upscaling Complete.", ConsoleColor.Cyan);
}

}
}
1 change: 1 addition & 0 deletions OnnxStack.Console/OnnxStack.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OnnxStack.ImageUpscaler\OnnxStack.ImageUpscaler.csproj" />
<ProjectReference Include="..\OnnxStack.StableDiffusion\OnnxStack.StableDiffusion.csproj" />
</ItemGroup>

Expand Down
3 changes: 3 additions & 0 deletions OnnxStack.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OnnxStack.Core;
using OnnxStack.ImageUpscaler;
using OnnxStack.ImageUpscaler.Config;
using System.Reflection;

namespace OnnxStack.Console
Expand All @@ -17,6 +19,7 @@ static async Task Main(string[] _)
// Add OnnxStack
builder.Services.AddOnnxStack();
builder.Services.AddOnnxStackStableDiffusion();
builder.Services.AddOnnxStackImageUpscaler();

// Add AppService
builder.Services.AddHostedService<AppService>();
Expand Down
Loading