Skip to content

Commit 83b9eb8

Browse files
committed
MultithreadingTests.cs: Added unit-test for case SciSharp#380
1 parent d23eed0 commit 83b9eb8

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

test/TensorFlowNET.UnitTest/MultithreadingTests.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
35
using System.Runtime.InteropServices;
46
using FluentAssertions;
57
using Microsoft.VisualStudio.TestTools.UnitTesting;
8+
using NumSharp;
69
using Tensorflow;
710
using Tensorflow.Util;
811
using static Tensorflow.Binding;
@@ -260,7 +263,7 @@ void Core(int tid)
260263
}
261264
}
262265

263-
266+
264267
[TestMethod]
265268
public void TF_GraphOperationByName()
266269
{
@@ -280,5 +283,46 @@ void Core(int tid)
280283
}
281284
}
282285
}
286+
287+
private static string modelPath = "./model/";
288+
289+
[TestMethod]
290+
public void TF_GraphOperationByName_FromModel()
291+
{
292+
MultiThreadedUnitTestExecuter.Run(8, Core);
293+
294+
//the core method
295+
void Core(int tid)
296+
{
297+
Console.WriteLine();
298+
for (int j = 0; j < 100; j++)
299+
{
300+
var sess = Session.LoadFromSavedModel(modelPath).as_default();
301+
var inputs = new[] {"sp", "fuel"};
302+
303+
var inp = inputs.Select(name => sess.graph.OperationByName(name).output).ToArray();
304+
var outp = sess.graph.OperationByName("softmax_tensor").output;
305+
306+
for (var i = 0; i < 100; i++)
307+
{
308+
{
309+
var data = new float[96];
310+
FeedItem[] feeds = new FeedItem[2];
311+
312+
for (int f = 0; f < 2; f++)
313+
feeds[f] = new FeedItem(inp[f], new NDArray(data));
314+
315+
try
316+
{
317+
sess.run(outp, feeds);
318+
} catch (Exception ex)
319+
{
320+
Console.WriteLine(ex);
321+
}
322+
}
323+
}
324+
}
325+
}
326+
}
283327
}
284328
}

0 commit comments

Comments
 (0)