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

Commit 5eb45d8

Browse files
committed
Upscale/FeatureExtractor progress callback
1 parent 2dcd76f commit 5eb45d8

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

OnnxStack.Core/Model/OnnxModelSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class OnnxModelSession : IDisposable
2525
public OnnxModelSession(OnnxModelConfig configuration)
2626
{
2727
if (!File.Exists(configuration.OnnxModelPath))
28-
throw new FileNotFoundException("Onnx model file not found", configuration.OnnxModelPath);
28+
throw new FileNotFoundException($"Onnx model file not found, Path: {configuration.OnnxModelPath}", configuration.OnnxModelPath);
2929

3030
_configuration = configuration;
3131
_options = configuration.GetSessionOptions();

OnnxStack.FeatureExtractor/Pipelines/FeatureExtractorPipeline.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using OnnxStack.Core.Model;
77
using OnnxStack.Core.Video;
88
using OnnxStack.FeatureExtractor.Common;
9+
using System;
910
using System.Collections.Generic;
1011
using System.IO;
1112
using System.Linq;
@@ -95,13 +96,15 @@ public async Task<OnnxImage> RunAsync(OnnxImage inputImage, CancellationToken ca
9596
/// </summary>
9697
/// <param name="videoFrames">The input video.</param>
9798
/// <returns></returns>
98-
public async Task<OnnxVideo> RunAsync(OnnxVideo video, CancellationToken cancellationToken = default)
99+
public async Task<OnnxVideo> RunAsync(OnnxVideo video, Action<OnnxImage, OnnxImage> progressCallback = default, CancellationToken cancellationToken = default)
99100
{
100101
var timestamp = _logger?.LogBegin("Extracting OnnxVideo features...");
101102
var featureFrames = new List<OnnxImage>();
102103
foreach (var videoFrame in video.Frames)
103104
{
104-
featureFrames.Add(await RunAsync(videoFrame, cancellationToken));
105+
var result = await RunAsync(videoFrame, cancellationToken);
106+
featureFrames.Add(result);
107+
progressCallback?.Invoke(videoFrame, result);
105108
}
106109
_logger?.LogEnd("Extracting OnnxVideo features complete.", timestamp);
107110
return new OnnxVideo(video.Info, featureFrames);

OnnxStack.ImageUpscaler/Pipelines/ImageUpscalePipeline.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,15 @@ public async Task<OnnxImage> RunAsync(OnnxImage inputImage, CancellationToken ca
9999
/// <param name="inputVideo">The input video.</param>
100100
/// <param name="cancellationToken">The cancellation token.</param>
101101
/// <returns></returns>
102-
public async Task<OnnxVideo> RunAsync(OnnxVideo inputVideo, CancellationToken cancellationToken = default)
102+
public async Task<OnnxVideo> RunAsync(OnnxVideo inputVideo, Action<OnnxImage, OnnxImage> progressCallback = default, CancellationToken cancellationToken = default)
103103
{
104104
var timestamp = _logger?.LogBegin("Upscale OnnxVideo..");
105105
var upscaledFrames = new List<OnnxImage>();
106106
foreach (var videoFrame in inputVideo.Frames)
107107
{
108-
upscaledFrames.Add(await UpscaleImageAsync(videoFrame, cancellationToken));
108+
var result = await UpscaleImageAsync(videoFrame, cancellationToken);
109+
upscaledFrames.Add(result);
110+
progressCallback?.Invoke(videoFrame, result);
109111
}
110112

111113
var firstFrame = upscaledFrames.First();

OnnxStack.UI/Services/FeatureExtractorService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public async Task<OnnxVideo> GenerateAsync(FeatureExtractorModelSet model, OnnxV
102102
if (!_pipelines.TryGetValue(model, out var pipeline))
103103
throw new Exception("Pipeline not found or is unsupported");
104104

105-
return await pipeline.RunAsync(inputVideo, cancellationToken);
105+
return await pipeline.RunAsync(inputVideo, cancellationToken: cancellationToken);
106106
}
107107

108108

OnnxStack.UI/Services/UpscaleService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public async Task<OnnxVideo> GenerateAsync(UpscaleModelSet model, OnnxVideo inpu
102102
if (!_pipelines.TryGetValue(model, out var pipeline))
103103
throw new Exception("Pipeline not found or is unsupported");
104104

105-
return await pipeline.RunAsync(inputVideo, cancellationToken);
105+
return await pipeline.RunAsync(inputVideo, cancellationToken: cancellationToken);
106106
}
107107

108108

0 commit comments

Comments
 (0)