1- using OnnxStack . Core ;
2- using OnnxStack . Core . Config ;
3- using OnnxStack . Core . Services ;
4- using OnnxStack . ImageUpscaler . Services ;
1+ using OnnxStack . ImageUpscaler . Services ;
52using SixLabors . ImageSharp ;
63using 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 }
0 commit comments