Remove unnecessary encoding step

This commit is contained in:
Brian Popow 2021-04-17 17:01:18 +02:00 committed by Changming Sun
parent 65b2b87f83
commit aa1ce726aa
2 changed files with 3 additions and 9 deletions

View file

@ -22,13 +22,11 @@ namespace Microsoft.ML.OnnxRuntime.FasterRcnnSample
string outImageFilePath = args[2];
// Read image
using Image<Rgb24> image = Image.Load<Rgb24>(imageFilePath, out IImageFormat format);
using Image<Rgb24> image = Image.Load<Rgb24>(imageFilePath);
// Resize image
float ratio = 800f / Math.Min(image.Width, image.Height);
using Stream imageStream = new MemoryStream();
image.Mutate(x => x.Resize((int)(ratio * image.Width), (int)(ratio * image.Height)));
image.Save(imageStream, format);
// Preprocess image
var paddedHeight = (int)(Math.Ceiling(image.Height / 32f) * 32f);
@ -101,7 +99,7 @@ namespace Microsoft.ML.OnnxRuntime.FasterRcnnSample
x.DrawText($"{p.Label}, {p.Confidence:0.00}", font, Color.White, new PointF(p.Box.Xmin, p.Box.Ymin));
});
}
image.Save(outputImage, format);
image.SaveAsJpeg(outputImage);
}
}
}

View file

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.ML.OnnxRuntime.Tensors;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
@ -19,10 +17,9 @@ namespace Microsoft.ML.OnnxRuntime.ResNet50v2Sample
string imageFilePath = args[1];
// Read image
using Image<Rgb24> image = Image.Load<Rgb24>(imageFilePath, out IImageFormat format);
using Image<Rgb24> image = Image.Load<Rgb24>(imageFilePath);
// Resize image
using Stream imageStream = new MemoryStream();
image.Mutate(x =>
{
x.Resize(new ResizeOptions
@ -31,7 +28,6 @@ namespace Microsoft.ML.OnnxRuntime.ResNet50v2Sample
Mode = ResizeMode.Crop
});
});
image.Save(imageStream, format);
// Preprocess image
Tensor<float> input = new DenseTensor<float>(new[] { 1, 3, 224, 224 });