Jignparm/csharp test difftypes (#122)

* Added tests for C# types

* added multithread c# test
This commit is contained in:
jignparm 2018-12-07 05:17:31 +00:00 committed by GitHub
parent 830c341c19
commit 9b9cb32f88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 249 additions and 226 deletions

View file

@ -7,6 +7,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics.Tensors;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Microsoft.ML.OnnxRuntime;
@ -73,7 +75,6 @@ namespace Microsoft.ML.OnnxRuntime.Tests
Assert.Equal(1, results.Count);
float[] expectedOutput = LoadTensorFromFile(@"bench.expected_out");
float errorMargin = 1e-6F;
// validate the results
foreach (var r in results)
{
@ -91,17 +92,11 @@ namespace Microsoft.ML.OnnxRuntime.Tests
var resultArray = r.AsTensor<float>().ToArray();
Assert.Equal(expectedOutput.Length, resultArray.Length);
for (int i = 0; i < expectedOutput.Length; i++)
{
Assert.InRange<float>(resultArray[i], expectedOutput[i] - errorMargin, expectedOutput[i] + errorMargin);
}
Assert.Equal(expectedOutput, resultArray, new floatComparer());
}
}
}
[Fact]
private void ThrowWrongInputName()
{
@ -184,226 +179,241 @@ namespace Microsoft.ML.OnnxRuntime.Tests
}
[Fact]
private void Yunsong()
private void TestMultiThreads()
{
var session = new InferenceSession(@"model_181031_12.onnx");
float[] zerof = new float[] { 0 };
long[] zerol = new long[] { 1 };
var data = new List<NamedOnnxValue>() {
NamedOnnxValue.CreateFromTensor<float>("input_0_0", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_0_1", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_1_0", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_1_1", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_1_2", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_1_3", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_1_4", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_2_0", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_2_1", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_2_2", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_2_3", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_2_4", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_2_5", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_3_0", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_3_1", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_0", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_1", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_2", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_3", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_4", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_5", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_6", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_7", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_8", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_9", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_10", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_11", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_12", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_13", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_14", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_15", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_16", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_17", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_18", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_19", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_20", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_21", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_22", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_23", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_24", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_25", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_26", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_27", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_28", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_29", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_30", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_31", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_32", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_33", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_34", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_35", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_36", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_37", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_38", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_39", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_40", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_41", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_42", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_43", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_44", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_45", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_46", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_47", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_48", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_49", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_50", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_51", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_52", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_53", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_54", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_55", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_56", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_57", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_58", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_59", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_60", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_61", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_62", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_63", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_64", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_65", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_66", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_67", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_68", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_69", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_70", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_71", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_72", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_73", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_74", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_75", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_76", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_77", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_78", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_79", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_80", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_81", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_82", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_83", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_84", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_85", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_86", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_87", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_88", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_89", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_90", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_91", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_92", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_93", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_94", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_95", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_96", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_97", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_98", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_99", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_100", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_101", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_102", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_103", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_104", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_105", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_106", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_107", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_108", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_109", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_110", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_111", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_112", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_113", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_114", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_115", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_116", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_117", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_118", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_119", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_120", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_121", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_122", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_123", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_124", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_125", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_126", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_127", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_128", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_129", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_130", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_131", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_132", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_133", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_134", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_135", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_136", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_137", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_138", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_139", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_140", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_141", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_142", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_143", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_144", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_145", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_146", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<float>("input_4_147", new DenseTensor<float>(zerof, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_0", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_1", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_2", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_3", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_4", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_5", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_6", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_7", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_8", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_9", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_10", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_11", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_12", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_13", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_14", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_15", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_16", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_17", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_18", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_19", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_20", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_21", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_22", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_23", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_24", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_25", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_26", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_27", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_28", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_29", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_30", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_31", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_32", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_33", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_34", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_35", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_36", new DenseTensor<long>(zerol, new int[] { 1 })),
NamedOnnxValue.CreateFromTensor<long>("input_5_37", new DenseTensor<long>(zerol, new int[] { 1 })),
};
var result = session.Run(data);
Assert.NotNull(result);
Assert.Equal(1, result.Count);
var value = result.First<NamedOnnxValue>();
Assert.Equal("label", value.Name);
Assert.NotNull(value.AsTensor<long>());
Assert.Equal(1, value.AsTensor<long>().Length);
var numThreads = 10;
var loop = 10;
var tuple = OpenSessionSqueezeNet();
var session = tuple.Item1;
var inputData = tuple.Item2;
var tensor = tuple.Item3;
var expectedOut = tuple.Item4;
var inputMeta = session.InputMetadata;
var container = new List<NamedOnnxValue>();
container.Add(NamedOnnxValue.CreateFromTensor<float>("data_0", tensor));
var tasks = new Task[numThreads];
for (int i = 0; i < numThreads; i++)
{
tasks[i] = Task.Factory.StartNew(() =>
{
for (int j = 0; j < loop; j++)
{
var resnov = session.Run(container);
var res = resnov.ToArray()[0].AsTensor<float>().ToArray<float>();
Assert.Equal(res, expectedOut, new floatComparer());
}
});
};
Task.WaitAll(tasks);
session.Dispose();
}
[Fact]
private void TestModelInputFloat()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_FLOAT.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<float>(new float[] { 1.0f, 2.0f, -3.0f, float.MinValue, float.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<float>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact(Skip = "Boolean tensor not supported yet")]
private void TestModelInputBOOL()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_BOOL.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<bool>(new bool[] { true, false, true, false, true }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<bool>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact]
private void TestModelInputINT32()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_INT32.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<int>(new int[] { 1, -2, -3, int.MinValue, int.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<int>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact]
private void TestModelInputDOUBLE()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_DOUBLE.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<double>(new double[] { 1.0, 2.0, -3.0, 5, 5 }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<double>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact(Skip = "String tensor not supported yet")]
private void TestModelInputSTRING()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_STRING.onnx";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<string>(new string[] { "a", "c", "d", "z", "f" }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<string>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact(Skip = "Int8 not supported yet")]
private void TestModelInputINT8()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_INT8.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<sbyte>(new sbyte[] { 1, 2, -3, sbyte.MinValue, sbyte.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<sbyte>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact]
private void TestModelInputUINT8()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_UINT8.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<byte>(new byte[] { 1, 2, 3, byte.MinValue, byte.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<byte>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact]
private void TestModelInputUINT16()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_UINT16.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<UInt16>(new UInt16[] { 1, 2, 3, UInt16.MinValue, UInt16.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<UInt16>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact]
private void TestModelInputINT16()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_INT16.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<Int16>(new Int16[] { 1, 2, 3, Int16.MinValue, Int16.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<Int16>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact]
private void TestModelInputINT64()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_INT64.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<Int64>(new Int64[] { 1, 2, -3, Int64.MinValue, Int64.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<Int64>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact]
private void TestModelInputUINT32()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_UINT32.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<UInt32>(new UInt32[] { 1, 2, 3, UInt32.MinValue, UInt32.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<UInt32>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact]
private void TestModelInputUINT64()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_UINT64.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<UInt64>(new UInt64[] { 1, 2, 3, UInt64.MinValue, UInt64.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<UInt64>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
[Fact(Skip = "Boolean FLOAT16 not available in C#")]
private void TestModelInputFLOAT16()
{
// model takes 1x5 input of fixed type, echoes back
string modelPath = Directory.GetCurrentDirectory() + @"\test_types_FLOAT16.pb";
var session = new InferenceSession(modelPath);
var container = new List<NamedOnnxValue>();
var tensorIn = new DenseTensor<float>(new float[] { 1.0f, 2.0f, -3.0f, float.MinValue, float.MaxValue }, new int[] { 1, 5 });
var nov = NamedOnnxValue.CreateFromTensor("input", tensorIn);
container.Add(nov);
var res = session.Run(container);
var tensorOut = res.First().AsTensor<float>();
Assert.True(tensorOut.SequenceEqual(tensorIn));
session.Dispose();
}
static float[] LoadTensorFromFile(string filename)
{
@ -423,15 +433,28 @@ namespace Microsoft.ML.OnnxRuntime.Tests
return tensorData.ToArray();
}
static Tuple<InferenceSession, float[], DenseTensor<float>> OpenSessionSqueezeNet()
static Tuple<InferenceSession, float[], DenseTensor<float>, float[]> OpenSessionSqueezeNet()
{
string modelPath = Directory.GetCurrentDirectory() + @"\squeezenet.onnx";
var session = new InferenceSession(modelPath);
float[] inputData = LoadTensorFromFile(@"bench.in");
float[] expectedOutput = LoadTensorFromFile(@"bench.expected_out");
var inputMeta = session.InputMetadata;
var tensor = new DenseTensor<float>(inputData, inputMeta["data_0"].Dimensions);
return new Tuple<InferenceSession, float[], DenseTensor<float>>(session, inputData, tensor);
return new Tuple<InferenceSession, float[], DenseTensor<float>, float[]>(session, inputData, tensor, expectedOutput);
}
class floatComparer : IEqualityComparer<float>
{
private float tol = 1e-7f;
public bool Equals(float x, float y)
{
return (Math.Abs(x - y) < tol) ? true : false;
}
public int GetHashCode(float x)
{
return 0;
}
}
}
}

BIN
csharp/testdata/test_types_BOOL.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_DOUBLE.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_FLOAT.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_FLOAT16.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_INT16.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_INT32.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_INT64.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_INT8.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_STRING.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_UINT16.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_UINT32.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_UINT64.pb vendored Normal file

Binary file not shown.

BIN
csharp/testdata/test_types_UINT8.pb vendored Normal file

Binary file not shown.