File tree Expand file tree Collapse file tree
test/TensorFlowNET.UnitTest Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
4+ using System . Linq ;
35using System . Runtime . InteropServices ;
46using FluentAssertions ;
57using Microsoft . VisualStudio . TestTools . UnitTesting ;
8+ using NumSharp ;
69using Tensorflow ;
710using Tensorflow . Util ;
811using 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}
You can’t perform that action at this time.
0 commit comments