1
- using OnnxStack . Core ;
2
- using OnnxStack . Core . Config ;
3
- using OnnxStack . Core . Services ;
4
- using OnnxStack . ImageUpscaler . Services ;
1
+ using OnnxStack . ImageUpscaler . Services ;
5
2
using SixLabors . ImageSharp ;
6
3
using SixLabors . ImageSharp . PixelFormats ;
7
4
@@ -10,13 +7,11 @@ namespace OnnxStack.Console.Runner
10
7
public sealed class UpscaleExample : IExampleRunner
11
8
{
12
9
private readonly string _outputDirectory ;
13
- private readonly IOnnxModelService _modelService ;
14
10
private readonly IUpscaleService _imageUpscaleService ;
15
-
16
11
17
- public UpscaleExample ( IOnnxModelService modelService , IUpscaleService imageUpscaleService )
12
+
13
+ public UpscaleExample ( IUpscaleService imageUpscaleService )
18
14
{
19
- _modelService = modelService ;
20
15
_imageUpscaleService = imageUpscaleService ;
21
16
_outputDirectory = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Examples" , nameof ( UpscaleExample ) ) ;
22
17
Directory . CreateDirectory ( _outputDirectory ) ;
@@ -28,23 +23,9 @@ public UpscaleExample(IOnnxModelService modelService, IUpscaleService imageUpsca
28
23
29
24
public async Task RunAsync ( )
30
25
{
26
+ var modelSet = _imageUpscaleService . ModelSets . FirstOrDefault ( x => x . Name == "RealSR BSRGAN x4" ) ;
27
+
31
28
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 ) ;
48
29
49
30
OutputHelpers . WriteConsole ( "Enter Image Path" , ConsoleColor . Yellow ) ;
50
31
var imageFile = OutputHelpers . ReadConsole ( ConsoleColor . Gray ) ;
@@ -55,13 +36,13 @@ public async Task RunAsync()
55
36
}
56
37
57
38
OutputHelpers . WriteConsole ( "Loading Model..." , ConsoleColor . Cyan ) ;
58
- await _modelService . LoadModelAsync ( modelset ) ;
39
+ await _imageUpscaleService . LoadModelAsync ( modelSet ) ;
59
40
OutputHelpers . WriteConsole ( "Model Loaded." , ConsoleColor . Cyan ) ;
60
41
61
42
var inputImage = await Image . LoadAsync < Rgba32 > ( imageFile ) ;
62
43
63
44
OutputHelpers . WriteConsole ( "Upscaling Image..." , ConsoleColor . Cyan ) ;
64
- var result = await _imageUpscaleService . GenerateAsync ( modelset , inputImage ) ;
45
+ var result = await _imageUpscaleService . GenerateAsync ( modelSet , inputImage ) ;
65
46
await result . SaveAsPngAsync ( Path . Combine ( _outputDirectory , "Result.png" ) ) ;
66
47
OutputHelpers . WriteConsole ( "Upscaling Complete." , ConsoleColor . Cyan ) ;
67
48
}
0 commit comments