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

Commit a4cd36f

Browse files
authored
Merge pull request #61 from saddam213/Upscaler
Image Upscale Project
2 parents 030c8b8 + 9c8dd6d commit a4cd36f

27 files changed

+986
-205
lines changed

OnnxStack.Console/Examples/StableDiffusionGif.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using OnnxStack.StableDiffusion;
1+
using OnnxStack.Core.Image;
2+
using OnnxStack.StableDiffusion;
23
using OnnxStack.StableDiffusion.Common;
34
using OnnxStack.StableDiffusion.Config;
45
using OnnxStack.StableDiffusion.Enums;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using OnnxStack.Core.Image;
2+
using OnnxStack.ImageUpscaler.Services;
3+
using SixLabors.ImageSharp;
4+
using SixLabors.ImageSharp.PixelFormats;
5+
6+
namespace OnnxStack.Console.Runner
7+
{
8+
public sealed class UpscaleExample : IExampleRunner
9+
{
10+
private readonly string _outputDirectory;
11+
private readonly IUpscaleService _imageUpscaleService;
12+
13+
14+
public UpscaleExample(IUpscaleService imageUpscaleService)
15+
{
16+
_imageUpscaleService = imageUpscaleService;
17+
_outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Examples", nameof(UpscaleExample));
18+
Directory.CreateDirectory(_outputDirectory);
19+
}
20+
21+
public string Name => "Image Upscale Demo";
22+
23+
public string Description => "Upscales images";
24+
25+
public async Task RunAsync()
26+
{
27+
var modelSet = _imageUpscaleService.ModelSets.FirstOrDefault(x => x.Name == "RealSR BSRGAN x4");
28+
29+
30+
31+
OutputHelpers.WriteConsole("Enter Image Path", ConsoleColor.Yellow);
32+
var imageFile = OutputHelpers.ReadConsole(ConsoleColor.Gray);
33+
if (!File.Exists(imageFile))
34+
{
35+
OutputHelpers.WriteConsole("File not found!", ConsoleColor.Red);
36+
return;
37+
}
38+
39+
OutputHelpers.WriteConsole("Loading Model...", ConsoleColor.Cyan);
40+
await _imageUpscaleService.LoadModelAsync(modelSet);
41+
OutputHelpers.WriteConsole("Model Loaded.", ConsoleColor.Cyan);
42+
43+
var inputImage = await Image.LoadAsync<Rgba32>(imageFile);
44+
45+
OutputHelpers.WriteConsole("Upscaling Image...", ConsoleColor.Cyan);
46+
var result = await _imageUpscaleService.GenerateAsImageAsync(modelSet, new InputImage(inputImage));
47+
await result.SaveAsPngAsync(Path.Combine(_outputDirectory, "Result.png"));
48+
OutputHelpers.WriteConsole("Upscaling Complete.", ConsoleColor.Cyan);
49+
}
50+
51+
}
52+
}

OnnxStack.Console/OnnxStack.Console.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18+
<ProjectReference Include="..\OnnxStack.ImageUpscaler\OnnxStack.ImageUpscaler.csproj" />
1819
<ProjectReference Include="..\OnnxStack.StableDiffusion\OnnxStack.StableDiffusion.csproj" />
1920
</ItemGroup>
2021

OnnxStack.Console/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using Microsoft.Extensions.Hosting;
33
using Microsoft.Extensions.Logging;
44
using OnnxStack.Core;
5+
using OnnxStack.ImageUpscaler;
6+
using OnnxStack.ImageUpscaler.Config;
57
using System.Reflection;
68

79
namespace OnnxStack.Console
@@ -17,6 +19,7 @@ static async Task Main(string[] _)
1719
// Add OnnxStack
1820
builder.Services.AddOnnxStack();
1921
builder.Services.AddOnnxStackStableDiffusion();
22+
builder.Services.AddOnnxStackImageUpscaler();
2023

2124
// Add AppService
2225
builder.Services.AddHostedService<AppService>();

0 commit comments

Comments
 (0)