1
1
using Microsoft . VisualStudio . TestTools . UnitTesting ;
2
2
using System . Collections . Generic ;
3
- using System . Diagnostics ;
4
3
using Tensorflow ;
5
4
using Tensorflow . Keras ;
6
5
using Tensorflow . Keras . Engine ;
7
- using Tensorflow . Keras . Losses ;
8
6
using Tensorflow . Keras . Optimizers ;
9
7
using Tensorflow . Keras . UnitTest . Helpers ;
10
8
using static Tensorflow . Binding ;
@@ -18,15 +16,15 @@ public class SequentialModelSave
18
16
[ TestMethod ]
19
17
public void SimpleModelFromAutoCompile ( )
20
18
{
21
- var inputs = keras . layers . Input ( ( 28 , 28 , 1 ) ) ;
22
- var x = keras . layers . Flatten ( ) . Apply ( inputs ) ;
23
- x = keras . layers . Dense ( 100 , activation : tf . nn . relu ) . Apply ( x ) ;
24
- x = keras . layers . Dense ( units : 10 ) . Apply ( x ) ;
25
- var outputs = keras . layers . Softmax ( axis : 1 ) . Apply ( x ) ;
26
- var model = keras . Model ( inputs , outputs ) ;
27
-
28
- model . compile ( new Adam ( 0.001f ) ,
29
- keras . losses . SparseCategoricalCrossentropy ( ) ,
19
+ var inputs = tf . keras . layers . Input ( ( 28 , 28 , 1 ) ) ;
20
+ var x = tf . keras . layers . Flatten ( ) . Apply ( inputs ) ;
21
+ x = tf . keras . layers . Dense ( 100 , activation : tf . nn . relu ) . Apply ( x ) ;
22
+ x = tf . keras . layers . Dense ( units : 10 ) . Apply ( x ) ;
23
+ var outputs = tf . keras . layers . Softmax ( axis : 1 ) . Apply ( x ) ;
24
+ var model = tf . keras . Model ( inputs , outputs ) ;
25
+
26
+ model . compile ( new Adam ( 0.001f ) ,
27
+ tf . keras . losses . SparseCategoricalCrossentropy ( ) ,
30
28
new string [ ] { "accuracy" } ) ;
31
29
32
30
var data_loader = new MnistModelLoader ( ) ;
@@ -48,18 +46,18 @@ public void SimpleModelFromAutoCompile()
48
46
[ TestMethod ]
49
47
public void SimpleModelFromSequential ( )
50
48
{
51
- Model model = KerasApi . keras . Sequential ( new List < ILayer > ( )
49
+ Model model = keras . Sequential ( new List < ILayer > ( )
52
50
{
53
- keras . layers . InputLayer ( ( 28 , 28 , 1 ) ) ,
54
- keras . layers . Flatten ( ) ,
55
- keras . layers . Dense ( 100 , "relu" ) ,
56
- keras . layers . Dense ( 10 ) ,
57
- keras . layers . Softmax ( )
51
+ tf . keras . layers . InputLayer ( ( 28 , 28 , 1 ) ) ,
52
+ tf . keras . layers . Flatten ( ) ,
53
+ tf . keras . layers . Dense ( 100 , "relu" ) ,
54
+ tf . keras . layers . Dense ( 10 ) ,
55
+ tf . keras . layers . Softmax ( )
58
56
} ) ;
59
57
60
58
model . summary ( ) ;
61
59
62
- model . compile ( new Adam ( 0.001f ) , new LossesApi ( ) . SparseCategoricalCrossentropy ( ) , new string [ ] { "accuracy" } ) ;
60
+ model . compile ( new Adam ( 0.001f ) , tf . keras . losses . SparseCategoricalCrossentropy ( ) , new string [ ] { "accuracy" } ) ;
63
61
64
62
var data_loader = new MnistModelLoader ( ) ;
65
63
var num_epochs = 1 ;
@@ -80,39 +78,39 @@ public void SimpleModelFromSequential()
80
78
[ TestMethod ]
81
79
public void AlexnetFromSequential ( )
82
80
{
83
- Model model = KerasApi . keras . Sequential ( new List < ILayer > ( )
81
+ Model model = keras . Sequential ( new List < ILayer > ( )
84
82
{
85
- keras . layers . InputLayer ( ( 227 , 227 , 3 ) ) ,
86
- keras . layers . Conv2D ( 96 , ( 11 , 11 ) , ( 4 , 4 ) , activation : "relu" , padding : "valid" ) ,
87
- keras . layers . BatchNormalization ( ) ,
88
- keras . layers . MaxPooling2D ( ( 3 , 3 ) , strides : ( 2 , 2 ) ) ,
83
+ tf . keras . layers . InputLayer ( ( 227 , 227 , 3 ) ) ,
84
+ tf . keras . layers . Conv2D ( 96 , ( 11 , 11 ) , ( 4 , 4 ) , activation : "relu" , padding : "valid" ) ,
85
+ tf . keras . layers . BatchNormalization ( ) ,
86
+ tf . keras . layers . MaxPooling2D ( ( 3 , 3 ) , strides : ( 2 , 2 ) ) ,
89
87
90
- keras . layers . Conv2D ( 256 , ( 5 , 5 ) , ( 1 , 1 ) , "same" , activation : "relu" ) ,
91
- keras . layers . BatchNormalization ( ) ,
92
- keras . layers . MaxPooling2D ( ( 3 , 3 ) , ( 2 , 2 ) ) ,
88
+ tf . keras . layers . Conv2D ( 256 , ( 5 , 5 ) , ( 1 , 1 ) , "same" , activation : "relu" ) ,
89
+ tf . keras . layers . BatchNormalization ( ) ,
90
+ tf . keras . layers . MaxPooling2D ( ( 3 , 3 ) , ( 2 , 2 ) ) ,
93
91
94
- keras . layers . Conv2D ( 384 , ( 3 , 3 ) , ( 1 , 1 ) , "same" , activation : "relu" ) ,
95
- keras . layers . BatchNormalization ( ) ,
92
+ tf . keras . layers . Conv2D ( 384 , ( 3 , 3 ) , ( 1 , 1 ) , "same" , activation : "relu" ) ,
93
+ tf . keras . layers . BatchNormalization ( ) ,
96
94
97
- keras . layers . Conv2D ( 384 , ( 3 , 3 ) , ( 1 , 1 ) , "same" , activation : "relu" ) ,
98
- keras . layers . BatchNormalization ( ) ,
95
+ tf . keras . layers . Conv2D ( 384 , ( 3 , 3 ) , ( 1 , 1 ) , "same" , activation : "relu" ) ,
96
+ tf . keras . layers . BatchNormalization ( ) ,
99
97
100
- keras . layers . Conv2D ( 256 , ( 3 , 3 ) , ( 1 , 1 ) , "same" , activation : "relu" ) ,
101
- keras . layers . BatchNormalization ( ) ,
102
- keras . layers . MaxPooling2D ( ( 3 , 3 ) , ( 2 , 2 ) ) ,
98
+ tf . keras . layers . Conv2D ( 256 , ( 3 , 3 ) , ( 1 , 1 ) , "same" , activation : "relu" ) ,
99
+ tf . keras . layers . BatchNormalization ( ) ,
100
+ tf . keras . layers . MaxPooling2D ( ( 3 , 3 ) , ( 2 , 2 ) ) ,
103
101
104
- keras . layers . Flatten ( ) ,
105
- keras . layers . Dense ( 4096 , activation : "relu" ) ,
106
- keras . layers . Dropout ( 0.5f ) ,
102
+ tf . keras . layers . Flatten ( ) ,
103
+ tf . keras . layers . Dense ( 4096 , activation : "relu" ) ,
104
+ tf . keras . layers . Dropout ( 0.5f ) ,
107
105
108
- keras . layers . Dense ( 4096 , activation : "relu" ) ,
109
- keras . layers . Dropout ( 0.5f ) ,
106
+ tf . keras . layers . Dense ( 4096 , activation : "relu" ) ,
107
+ tf . keras . layers . Dropout ( 0.5f ) ,
110
108
111
- keras . layers . Dense ( 1000 , activation : "linear" ) ,
112
- keras . layers . Softmax ( 1 )
109
+ tf . keras . layers . Dense ( 1000 , activation : "linear" ) ,
110
+ tf . keras . layers . Softmax ( 1 )
113
111
} ) ;
114
112
115
- model . compile ( new Adam ( 0.001f ) , new LossesApi ( ) . SparseCategoricalCrossentropy ( from_logits : true ) , new string [ ] { "accuracy" } ) ;
113
+ model . compile ( new Adam ( 0.001f ) , tf . keras . losses . SparseCategoricalCrossentropy ( from_logits : true ) , new string [ ] { "accuracy" } ) ;
116
114
117
115
var num_epochs = 1 ;
118
116
var batch_size = 8 ;
0 commit comments