From 83b9eb82af1adc4a9e6456518757eb27ebd5cccf Mon Sep 17 00:00:00 2001 From: Eli Belash Date: Tue, 10 Sep 2019 16:14:34 +0300 Subject: [PATCH] MultithreadingTests.cs: Added unit-test for case #380 --- .../MultithreadingTests.cs | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/test/TensorFlowNET.UnitTest/MultithreadingTests.cs b/test/TensorFlowNET.UnitTest/MultithreadingTests.cs index b8b88c9c..1e4d829c 100644 --- a/test/TensorFlowNET.UnitTest/MultithreadingTests.cs +++ b/test/TensorFlowNET.UnitTest/MultithreadingTests.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Runtime.InteropServices; using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; +using NumSharp; using Tensorflow; using Tensorflow.Util; using static Tensorflow.Binding; @@ -260,7 +263,7 @@ namespace TensorFlowNET.UnitTest } } - + [TestMethod] public void TF_GraphOperationByName() { @@ -280,5 +283,46 @@ namespace TensorFlowNET.UnitTest } } } + + private static string modelPath = "./model/"; + + [TestMethod] + public void TF_GraphOperationByName_FromModel() + { + MultiThreadedUnitTestExecuter.Run(8, Core); + + //the core method + void Core(int tid) + { + Console.WriteLine(); + for (int j = 0; j < 100; j++) + { + var sess = Session.LoadFromSavedModel(modelPath).as_default(); + var inputs = new[] {"sp", "fuel"}; + + var inp = inputs.Select(name => sess.graph.OperationByName(name).output).ToArray(); + var outp = sess.graph.OperationByName("softmax_tensor").output; + + for (var i = 0; i < 100; i++) + { + { + var data = new float[96]; + FeedItem[] feeds = new FeedItem[2]; + + for (int f = 0; f < 2; f++) + feeds[f] = new FeedItem(inp[f], new NDArray(data)); + + try + { + sess.run(outp, feeds); + } catch (Exception ex) + { + Console.WriteLine(ex); + } + } + } + } + } + } } } \ No newline at end of file