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

Commit f1b6c58

Browse files
committed
Support for byte tensors
1 parent 6ae4eee commit f1b6c58

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

OnnxStack.Core/Extensions/OrtValueExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ public static OrtValue ToOrtValue(this DenseTensor<bool> tensor, OnnxNamedMetada
8484
}
8585

8686

87+
/// <summary>
88+
/// Converts DenseTensor<bool> to OrtValue.
89+
/// </summary>
90+
/// <param name="tensor">The tensor.</param>
91+
/// <param name="metadata">The metadata.</param>
92+
/// <returns></returns>
93+
public static OrtValue ToOrtValue(this DenseTensor<byte> tensor, OnnxNamedMetadata metadata)
94+
{
95+
return OrtValue.CreateTensorValueFromMemory(OrtMemoryInfo.DefaultInstance, tensor.Buffer, tensor.Dimensions.ToLong());
96+
}
97+
98+
8799
/// <summary>
88100
/// Creates and allocates the output tensors buffer.
89101
/// </summary>

OnnxStack.Core/Image/Extensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ private static DenseTensor<float> SplitImageTile(DenseTensor<float> source, int
8888
var splitTensor = new DenseTensor<float>(new[] { 1, channels, height, width });
8989
Parallel.For(0, channels, (c) =>
9090
{
91-
Parallel.For(0, height, (i) =>
91+
for (int i = 0; i < height; i++)
9292
{
93-
Parallel.For(0, width, (j) =>
93+
for (int j = 0; j < width; j++)
9494
{
9595
splitTensor[0, c, i, j] = source[0, c, startRow + i, startCol + j];
96-
});
97-
});
96+
}
97+
}
9898
});
9999
return splitTensor;
100100
}
@@ -135,9 +135,9 @@ private static void JoinImageTile(DenseTensor<float> destination, DenseTensor<fl
135135
int channels = tile.Dimensions[1];
136136
Parallel.For(0, channels, (c) =>
137137
{
138-
Parallel.For(0, height, (i) =>
138+
for (int i = 0; i < height; i++)
139139
{
140-
Parallel.For(0, width, (j) =>
140+
for (int j = 0; j < width; j++)
141141
{
142142
var value = tile[0, c, i, j];
143143
var existing = destination[0, c, startRow + i, startCol + j];
@@ -147,8 +147,8 @@ private static void JoinImageTile(DenseTensor<float> destination, DenseTensor<fl
147147
value = (existing + value) / 2f;
148148
}
149149
destination[0, c, startRow + i, startCol + j] = value;
150-
});
151-
});
150+
}
151+
}
152152
});
153153
}
154154
}

OnnxStack.Core/Model/OnnxInferenceParameters.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ public void AddInputTensor(DenseTensor<bool> value)
112112
}
113113

114114

115+
/// <summary>
116+
/// Adds the input tensor.
117+
/// </summary>
118+
/// <param name="value">The value.</param>
119+
public void AddInputTensor(DenseTensor<byte> value)
120+
{
121+
var metaData = GetNextInputMetadata();
122+
_inputs.Add(metaData, value.ToOrtValue(metaData));
123+
}
124+
125+
115126
/// <summary>
116127
/// Adds an output parameter with known output size.
117128
/// </summary>

0 commit comments

Comments
 (0)