11using Microsoft . VisualStudio . TestTools . UnitTesting ;
2+ using System ;
23using static Tensorflow . Binding ;
4+ using static Tensorflow . KerasApi ;
35
46namespace Tensorflow . Keras . UnitTest . Model
57{
@@ -14,24 +16,47 @@ public void DenseBuild()
1416 var dense = tf . keras . layers . Dense ( 64 ) ;
1517 var output = dense . Apply ( input ) ;
1618 var model = tf . keras . Model ( input , output ) ;
19+ model . compile ( tf . keras . optimizers . Adam ( ) , tf . keras . losses . CategoricalCrossentropy ( ) ) ;
1720
1821 // one dimensions input with unknown batchsize
1922 var input_2 = tf . keras . layers . Input ( ( 60 ) ) ;
2023 var dense_2 = tf . keras . layers . Dense ( 64 ) ;
21- var output_2 = dense . Apply ( input_2 ) ;
24+ var output_2 = dense_2 . Apply ( input_2 ) ;
2225 var model_2 = tf . keras . Model ( input_2 , output_2 ) ;
26+ model_2 . compile ( tf . keras . optimizers . Adam ( ) , tf . keras . losses . CategoricalCrossentropy ( ) ) ;
2327
2428 // two dimensions input with specified batchsize
2529 var input_3 = tf . keras . layers . Input ( ( 17 , 60 ) , 8 ) ;
2630 var dense_3 = tf . keras . layers . Dense ( 64 ) ;
27- var output_3 = dense . Apply ( input_3 ) ;
31+ var output_3 = dense_3 . Apply ( input_3 ) ;
2832 var model_3 = tf . keras . Model ( input_3 , output_3 ) ;
33+ model_3 . compile ( tf . keras . optimizers . Adam ( ) , tf . keras . losses . CategoricalCrossentropy ( ) ) ;
2934
3035 // one dimensions input with specified batchsize
3136 var input_4 = tf . keras . layers . Input ( ( 60 ) , 8 ) ;
3237 var dense_4 = tf . keras . layers . Dense ( 64 ) ;
33- var output_4 = dense . Apply ( input_4 ) ;
38+ var output_4 = dense_4 . Apply ( input_4 ) ;
3439 var model_4 = tf . keras . Model ( input_4 , output_4 ) ;
40+ model_4 . compile ( tf . keras . optimizers . Adam ( ) , tf . keras . losses . CategoricalCrossentropy ( ) ) ;
41+ }
42+
43+ [ TestMethod ]
44+ public void NestedSequential ( )
45+ {
46+ var block1 = keras . Sequential ( new [ ] {
47+ keras . layers . InputLayer ( ( 3 , 3 ) ) ,
48+ keras . Sequential ( new [ ]
49+ {
50+ keras . layers . Flatten ( ) ,
51+ keras . layers . Dense ( 5 )
52+ }
53+ )
54+ } ) ;
55+ block1 . compile ( tf . keras . optimizers . Adam ( ) , tf . keras . losses . CategoricalCrossentropy ( ) ) ;
56+
57+ var x = tf . ones ( ( 1 , 3 , 3 ) ) ;
58+ var y = block1 . predict ( x ) ;
59+ Console . WriteLine ( y ) ;
3560 }
3661 }
3762}
0 commit comments