@@ -89,20 +89,20 @@ public static Graph build(String optimizerName) {
89
89
Placeholder <TUint8 > labels = tf .withName (TARGET ).placeholder (TUint8 .DTYPE );
90
90
91
91
// Scaling the features
92
- Constant <TFloat32 > centeringFactor = tf .val (PIXEL_DEPTH / 2.0f );
93
- Constant <TFloat32 > scalingFactor = tf .val ((float ) PIXEL_DEPTH );
92
+ Constant <TFloat32 > centeringFactor = tf .constant (PIXEL_DEPTH / 2.0f );
93
+ Constant <TFloat32 > scalingFactor = tf .constant ((float ) PIXEL_DEPTH );
94
94
Operand <TFloat32 > scaledInput = tf .math
95
95
.div (tf .math .sub (tf .dtypes .cast (input_reshaped , TFloat32 .DTYPE ), centeringFactor ),
96
96
scalingFactor );
97
97
98
98
// First conv layer
99
99
Variable <TFloat32 > conv1Weights = tf .variable (tf .math .mul (tf .random
100
100
.truncatedNormal (tf .array (5 , 5 , NUM_CHANNELS , 32 ), TFloat32 .DTYPE ,
101
- TruncatedNormal .seed (SEED )), tf .val (0.1f )));
101
+ TruncatedNormal .seed (SEED )), tf .constant (0.1f )));
102
102
Conv2d <TFloat32 > conv1 = tf .nn
103
103
.conv2d (scaledInput , conv1Weights , Arrays .asList (1L , 1L , 1L , 1L ), PADDING_TYPE );
104
104
Variable <TFloat32 > conv1Biases = tf
105
- .variable (tf .fill (tf .array (new int []{32 }), tf .val (0.0f )));
105
+ .variable (tf .fill (tf .array (new int []{32 }), tf .constant (0.0f )));
106
106
Relu <TFloat32 > relu1 = tf .nn .relu (tf .nn .biasAdd (conv1 , conv1Biases ));
107
107
108
108
// First pooling layer
@@ -113,11 +113,11 @@ public static Graph build(String optimizerName) {
113
113
// Second conv layer
114
114
Variable <TFloat32 > conv2Weights = tf .variable (tf .math .mul (tf .random
115
115
.truncatedNormal (tf .array (5 , 5 , 32 , 64 ), TFloat32 .DTYPE ,
116
- TruncatedNormal .seed (SEED )), tf .val (0.1f )));
116
+ TruncatedNormal .seed (SEED )), tf .constant (0.1f )));
117
117
Conv2d <TFloat32 > conv2 = tf .nn
118
118
.conv2d (pool1 , conv2Weights , Arrays .asList (1L , 1L , 1L , 1L ), PADDING_TYPE );
119
119
Variable <TFloat32 > conv2Biases = tf
120
- .variable (tf .fill (tf .array (new int []{64 }), tf .val (0.1f )));
120
+ .variable (tf .fill (tf .array (new int []{64 }), tf .constant (0.1f )));
121
121
Relu <TFloat32 > relu2 = tf .nn .relu (tf .nn .biasAdd (conv2 , conv2Biases ));
122
122
123
123
// Second pooling layer
@@ -128,23 +128,23 @@ public static Graph build(String optimizerName) {
128
128
// Flatten inputs
129
129
Reshape <TFloat32 > flatten = tf .reshape (pool2 , tf .concat (Arrays
130
130
.asList (tf .slice (tf .shape (pool2 ), tf .array (new int []{0 }), tf .array (new int []{1 })),
131
- tf .array (new int []{-1 })), tf .val (0 )));
131
+ tf .array (new int []{-1 })), tf .constant (0 )));
132
132
133
133
// Fully connected layer
134
134
Variable <TFloat32 > fc1Weights = tf .variable (tf .math .mul (tf .random
135
135
.truncatedNormal (tf .array (IMAGE_SIZE * IMAGE_SIZE * 4 , 512 ), TFloat32 .DTYPE ,
136
- TruncatedNormal .seed (SEED )), tf .val (0.1f )));
136
+ TruncatedNormal .seed (SEED )), tf .constant (0.1f )));
137
137
Variable <TFloat32 > fc1Biases = tf
138
- .variable (tf .fill (tf .array (new int []{512 }), tf .val (0.1f )));
138
+ .variable (tf .fill (tf .array (new int []{512 }), tf .constant (0.1f )));
139
139
Relu <TFloat32 > relu3 = tf .nn
140
140
.relu (tf .math .add (tf .linalg .matMul (flatten , fc1Weights ), fc1Biases ));
141
141
142
142
// Softmax layer
143
143
Variable <TFloat32 > fc2Weights = tf .variable (tf .math .mul (tf .random
144
144
.truncatedNormal (tf .array (512 , NUM_LABELS ), TFloat32 .DTYPE ,
145
- TruncatedNormal .seed (SEED )), tf .val (0.1f )));
145
+ TruncatedNormal .seed (SEED )), tf .constant (0.1f )));
146
146
Variable <TFloat32 > fc2Biases = tf
147
- .variable (tf .fill (tf .array (new int []{NUM_LABELS }), tf .val (0.1f )));
147
+ .variable (tf .fill (tf .array (new int []{NUM_LABELS }), tf .constant (0.1f )));
148
148
149
149
Add <TFloat32 > logits = tf .math .add (tf .linalg .matMul (relu3 , fc2Weights ), fc2Biases );
150
150
@@ -153,15 +153,15 @@ public static Graph build(String optimizerName) {
153
153
154
154
// Loss function & regularization
155
155
OneHot <TFloat32 > oneHot = tf
156
- .oneHot (labels , tf .val (10 ), tf .val (1.0f ), tf .val (0.0f ));
156
+ .oneHot (labels , tf .constant (10 ), tf .constant (1.0f ), tf .constant (0.0f ));
157
157
SoftmaxCrossEntropyWithLogits <TFloat32 > batchLoss = tf .nn
158
158
.softmaxCrossEntropyWithLogits (logits , oneHot );
159
- Mean <TFloat32 > labelLoss = tf .math .mean (batchLoss .loss (), tf .val (0 ));
159
+ Mean <TFloat32 > labelLoss = tf .math .mean (batchLoss .loss (), tf .constant (0 ));
160
160
Add <TFloat32 > regularizers = tf .math .add (tf .nn .l2Loss (fc1Weights ), tf .math
161
161
.add (tf .nn .l2Loss (fc1Biases ),
162
162
tf .math .add (tf .nn .l2Loss (fc2Weights ), tf .nn .l2Loss (fc2Biases ))));
163
163
Add <TFloat32 > loss = tf .withName (TRAINING_LOSS ).math
164
- .add (labelLoss , tf .math .mul (regularizers , tf .val (5e-4f )));
164
+ .add (labelLoss , tf .math .mul (regularizers , tf .constant (5e-4f )));
165
165
166
166
String lcOptimizerName = optimizerName .toLowerCase ();
167
167
// Optimizer
@@ -194,7 +194,7 @@ public static Graph build(String optimizerName) {
194
194
logger .info ("Optimizer = " + optimizer .toString ());
195
195
Op minimize = optimizer .minimize (loss , TRAIN );
196
196
197
- Op init = graph . variablesInitializer ();
197
+ tf . init ();
198
198
199
199
return graph ;
200
200
}
0 commit comments