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

Commit 8abd309

Browse files
committed
UpscaleModelSet Load/Unload
1 parent c80f7bd commit 8abd309

File tree

13 files changed

+464
-247
lines changed

13 files changed

+464
-247
lines changed

OnnxStack.Console/Examples/UpscaleExample.cs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using OnnxStack.Core;
2-
using OnnxStack.Core.Config;
3-
using OnnxStack.Core.Services;
4-
using OnnxStack.ImageUpscaler.Services;
1+
using OnnxStack.ImageUpscaler.Services;
52
using SixLabors.ImageSharp;
63
using SixLabors.ImageSharp.PixelFormats;
74

@@ -10,13 +7,11 @@ namespace OnnxStack.Console.Runner
107
public sealed class UpscaleExample : IExampleRunner
118
{
129
private readonly string _outputDirectory;
13-
private readonly IOnnxModelService _modelService;
1410
private readonly IUpscaleService _imageUpscaleService;
15-
1611

17-
public UpscaleExample(IOnnxModelService modelService, IUpscaleService imageUpscaleService)
12+
13+
public UpscaleExample(IUpscaleService imageUpscaleService)
1814
{
19-
_modelService = modelService;
2015
_imageUpscaleService = imageUpscaleService;
2116
_outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Examples", nameof(UpscaleExample));
2217
Directory.CreateDirectory(_outputDirectory);
@@ -28,23 +23,9 @@ public UpscaleExample(IOnnxModelService modelService, IUpscaleService imageUpsca
2823

2924
public async Task RunAsync()
3025
{
26+
var modelSet = _imageUpscaleService.ModelSets.FirstOrDefault(x => x.Name == "RealSR BSRGAN x4");
27+
3128

32-
var modelset = new OnnxModelSetConfig
33-
{
34-
Name = "Upscaler",
35-
IsEnabled = true,
36-
ExecutionProvider = ExecutionProvider.DirectML,
37-
ModelConfigurations = new List<OnnxModelSessionConfig>
38-
{
39-
new OnnxModelSessionConfig
40-
{
41-
Type = OnnxModelType.Upscaler,
42-
OnnxModelPath = "D:\\Repositories\\upscaler\\SwinIR\\003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.onnx"
43-
}
44-
}
45-
};
46-
modelset.ApplyConfigurationOverrides();
47-
_modelService.UpdateModelSet(modelset);
4829

4930
OutputHelpers.WriteConsole("Enter Image Path", ConsoleColor.Yellow);
5031
var imageFile = OutputHelpers.ReadConsole(ConsoleColor.Gray);
@@ -55,13 +36,13 @@ public async Task RunAsync()
5536
}
5637

5738
OutputHelpers.WriteConsole("Loading Model...", ConsoleColor.Cyan);
58-
await _modelService.LoadModelAsync(modelset);
39+
await _imageUpscaleService.LoadModelAsync(modelSet);
5940
OutputHelpers.WriteConsole("Model Loaded.", ConsoleColor.Cyan);
6041

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

6344
OutputHelpers.WriteConsole("Upscaling Image...", ConsoleColor.Cyan);
64-
var result = await _imageUpscaleService.GenerateAsync(modelset, inputImage);
45+
var result = await _imageUpscaleService.GenerateAsync(modelSet, inputImage);
6546
await result.SaveAsPngAsync(Path.Combine(_outputDirectory, "Result.png"));
6647
OutputHelpers.WriteConsole("Upscaling Complete.", ConsoleColor.Cyan);
6748
}

OnnxStack.Console/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static async Task Main(string[] _)
1919
// Add OnnxStack
2020
builder.Services.AddOnnxStack();
2121
builder.Services.AddOnnxStackStableDiffusion();
22-
builder.Services.AddOnnxStackImageUpscaler(new ImageUpscalerConfig());
22+
builder.Services.AddOnnxStackImageUpscaler();
2323

2424
// Add AppService
2525
builder.Services.AddHostedService<AppService>();

0 commit comments

Comments
 (0)