diff --git a/OnnxStack.Core/Extensions/OrtValueExtensions.cs b/OnnxStack.Core/Extensions/OrtValueExtensions.cs index 95c4fc9..138efc5 100644 --- a/OnnxStack.Core/Extensions/OrtValueExtensions.cs +++ b/OnnxStack.Core/Extensions/OrtValueExtensions.cs @@ -84,6 +84,18 @@ public static OrtValue ToOrtValue(this DenseTensor tensor, OnnxNamedMetada } + /// + /// Converts DenseTensor to OrtValue. + /// + /// The tensor. + /// The metadata. + /// + public static OrtValue ToOrtValue(this DenseTensor tensor, OnnxNamedMetadata metadata) + { + return OrtValue.CreateTensorValueFromMemory(OrtMemoryInfo.DefaultInstance, tensor.Buffer, tensor.Dimensions.ToLong()); + } + + /// /// Creates and allocates the output tensors buffer. /// diff --git a/OnnxStack.Core/Image/Extensions.cs b/OnnxStack.Core/Image/Extensions.cs index ef8fa61..0afcac7 100644 --- a/OnnxStack.Core/Image/Extensions.cs +++ b/OnnxStack.Core/Image/Extensions.cs @@ -88,13 +88,13 @@ private static DenseTensor SplitImageTile(DenseTensor source, int var splitTensor = new DenseTensor(new[] { 1, channels, height, width }); Parallel.For(0, channels, (c) => { - Parallel.For(0, height, (i) => + for (int i = 0; i < height; i++) { - Parallel.For(0, width, (j) => + for (int j = 0; j < width; j++) { splitTensor[0, c, i, j] = source[0, c, startRow + i, startCol + j]; - }); - }); + } + } }); return splitTensor; } @@ -135,9 +135,9 @@ private static void JoinImageTile(DenseTensor destination, DenseTensor { - Parallel.For(0, height, (i) => + for (int i = 0; i < height; i++) { - Parallel.For(0, width, (j) => + for (int j = 0; j < width; j++) { var value = tile[0, c, i, j]; var existing = destination[0, c, startRow + i, startCol + j]; @@ -147,8 +147,8 @@ private static void JoinImageTile(DenseTensor destination, DenseTensor value) } + /// + /// Adds the input tensor. + /// + /// The value. + public void AddInputTensor(DenseTensor value) + { + var metaData = GetNextInputMetadata(); + _inputs.Add(metaData, value.ToOrtValue(metaData)); + } + + /// /// Adds an output parameter with known output size. ///