Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update ImageUpscale to new API format
  • Loading branch information
saddam213 committed Feb 12, 2024
commit 21a1e211433c380bd688889c974fcf7afee039a4
6 changes: 1 addition & 5 deletions OnnxStack.Console/Examples/UpscaleExample.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using OnnxStack.Core.Image;
using OnnxStack.FeatureExtractor.Pipelines;
using OnnxStack.ImageUpscaler.Config;
using SixLabors.ImageSharp;

namespace OnnxStack.Console.Runner
{
public sealed class UpscaleExample : IExampleRunner
{
private readonly string _outputDirectory;
private readonly ImageUpscalerConfig _configuration;

public UpscaleExample(ImageUpscalerConfig configuration)
public UpscaleExample()
{
_configuration = configuration;
_outputDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Examples", nameof(UpscaleExample));
Directory.CreateDirectory(_outputDirectory);
}
Expand Down
1 change: 0 additions & 1 deletion OnnxStack.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ static async Task Main(string[] _)
// Add OnnxStack
builder.Services.AddOnnxStack();
builder.Services.AddOnnxStackConfig<StableDiffusionConfig>();
builder.Services.AddOnnxStackImageUpscaler();

// Add AppService
builder.Services.AddHostedService<AppService>();
Expand Down
16 changes: 0 additions & 16 deletions OnnxStack.ImageUpscaler/Config/ImageUpscalerConfig.cs

This file was deleted.

6 changes: 3 additions & 3 deletions OnnxStack.ImageUpscaler/Extensions/ImageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal static class ImageExtensions
/// <param name="sampleSize">Maximum size of the tile.</param>
/// <param name="scaleFactor">The scale factor.</param>
/// <returns></returns>
public static List<ImageTile> GenerateTiles(this OnnxImage imageSource, int sampleSize, int scaleFactor)
internal static List<ImageTile> GenerateTiles(this OnnxImage imageSource, int sampleSize, int scaleFactor)
{
var tiles = new List<ImageTile>();
var tileSizeX = Math.Min(sampleSize, imageSource.Width);
Expand Down Expand Up @@ -48,7 +48,7 @@ public static List<ImageTile> GenerateTiles(this OnnxImage imageSource, int samp
/// <param name="sourceImage">The source image.</param>
/// <param name="sourceArea">The source area.</param>
/// <returns></returns>
public static OnnxImage ExtractTile(this OnnxImage sourceImage, Rectangle sourceArea)
internal static OnnxImage ExtractTile(this OnnxImage sourceImage, Rectangle sourceArea)
{
var height = sourceArea.Height;
var targetImage = new Image<Rgba32>(sourceArea.Width, sourceArea.Height);
Expand All @@ -65,7 +65,7 @@ public static OnnxImage ExtractTile(this OnnxImage sourceImage, Rectangle source
}


public static void ApplyImageTile(this DenseTensor<float> imageTensor, DenseTensor<float> tileTensor, Rectangle location)
internal static void ApplyImageTile(this DenseTensor<float> imageTensor, DenseTensor<float> tileTensor, Rectangle location)
{
var offsetY = location.Y;
var offsetX = location.X;
Expand Down
2 changes: 1 addition & 1 deletion OnnxStack.ImageUpscaler/Models/ImageTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace OnnxStack.ImageUpscaler.Models
{
public record ImageTile
internal record ImageTile
{
public OnnxImage Image { get; set; }
public Rectangle Destination { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion OnnxStack.ImageUpscaler/Models/UpscaleInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace OnnxStack.ImageUpscaler.Models
{
public record UpscaleInput(List<ImageTile> ImageTiles, int OutputWidth, int OutputHeight);
internal record UpscaleInput(List<ImageTile> ImageTiles, int OutputWidth, int OutputHeight);
}


Expand Down
30 changes: 29 additions & 1 deletion OnnxStack.ImageUpscaler/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# OnnxStack.ImageUpsacler
# OnnxStack.ImageUpscaler

## Upscale Models
https://huggingface.co/wuminghao/swinir
https://huggingface.co/rocca/swin-ir-onnx
https://huggingface.co/Xenova/swin2SR-classical-sr-x2-64
https://huggingface.co/Xenova/swin2SR-classical-sr-x4-64


# Basic Example
```csharp
// Load Input Image
var inputImage = await OnnxImage.FromFileAsync("Input.png");

// Create Pipeline
var pipeline = ImageUpscalePipeline.CreatePipeline("003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.onnx", scaleFactor: 4);

// Run pipeline
var result = await pipeline.RunAsync(inputImage);

// Create Image from Tensor result
var image = new OnnxImage(result, ImageNormalizeType.ZeroToOne);

// Save Image File
await image.SaveAsync("Upscaled.png");

// Unload
await pipeline.UnloadAsync();
```
63 changes: 0 additions & 63 deletions OnnxStack.ImageUpscaler/Registration.cs

This file was deleted.

100 changes: 0 additions & 100 deletions OnnxStack.ImageUpscaler/Services/IUpscaleService.cs

This file was deleted.

Loading