Skip to content

Commit 04c80f3

Browse files
committed
DigitRecognitionNN works, but the accuracy is only 92% after 10 epochs, it's supposed to be 97%.
1 parent 5ff096c commit 04c80f3

File tree

19 files changed

+171
-37
lines changed

19 files changed

+171
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ Example runner will download all the required files like training data and model
142142
* [Logistic Regression](test/TensorFlowNET.Examples/BasicModels/LogisticRegression.cs)
143143
* [Nearest Neighbor](test/TensorFlowNET.Examples/BasicModels/NearestNeighbor.cs)
144144
* [Naive Bayes Classification](test/TensorFlowNET.Examples/BasicModels/NaiveBayesClassifier.cs)
145+
* [Full Connected Neural Network](test/TensorFlowNET.Examples/ImageProcess/DigitRecognitionNN.cs)
145146
* [Image Recognition](test/TensorFlowNET.Examples/ImageProcess)
146147
* [K-means Clustering](test/TensorFlowNET.Examples/BasicModels/KMeansClustering.cs)
147148
* [NN XOR](test/TensorFlowNET.Examples/BasicModels/NeuralNetXor.cs)
148149
* [Object Detection](test/TensorFlowNET.Examples/ImageProcess/ObjectDetection.cs)
149150
* [Text Classification](test/TensorFlowNET.Examples/TextProcess/BinaryTextClassification.cs)
150151
* [CNN Text Classification](test/TensorFlowNET.Examples/TextProcess/cnn_models/VdCnn.cs)
151-
152152
* [Named Entity Recognition](test/TensorFlowNET.Examples/TextProcess/NER)
153153
* [Transfer Learning for Image Classification in InceptionV3](test/TensorFlowNET.Examples/ImageProcess/RetrainImageClassifier.cs)
154154

src/KerasNET.Core/Layers/Dense.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Tensor __call__(Tensor x)
4040
var dot = tf.matmul(x, W);
4141
if (this.activation != null)
4242
dot = activation.Activate(dot);
43-
Console.WriteLine("Calling Layer \"" + name + "(" + np.array(dot.GetShape().Dimensions).ToString() + ")\" ...");
43+
Console.WriteLine("Calling Layer \"" + name + "(" + np.array(dot.TensorShape.Dimensions).ToString() + ")\" ...");
4444
return dot;
4545
}
4646
public TensorShape __shape__()

src/KerasNET.Core/Model.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public Tensor getFlow()
6565
#endregion
6666

6767
#region Model Graph Form Layer Stack
68-
var flow_shape = features.GetShape();
68+
var flow_shape = features.TensorShape;
6969
Flow = features;
7070
for (int i = 0; i < layer_stack.Count; i++)
7171
{

src/TensorFlowNET.Core/Framework/common_shapes.py.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static Tensor _broadcast_shape_helper(Tensor shape_x, Tensor shape_y)
3737

3838
public static bool has_fully_defined_shape(Tensor tensor)
3939
{
40-
return tensor.GetShape().is_fully_defined();
40+
return tensor.TensorShape.is_fully_defined();
4141
}
4242
}
4343
}

src/TensorFlowNET.Core/Keras/Layers/Layer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected void _maybe_build(Tensor input)
161161
if (_dtype == TF_DataType.DtInvalid)
162162
_dtype = input.dtype;
163163

164-
var input_shapes = input.GetShape();
164+
var input_shapes = input.TensorShape;
165165
build(input_shapes);
166166
built = true;
167167
}

src/TensorFlowNET.Core/Operations/Losses/losses_impl.py.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public Tensor sparse_softmax_cross_entropy(Tensor labels,
118118
if(weights > 0)
119119
{
120120
var weights_tensor = ops.convert_to_tensor(weights);
121-
var labels_rank = labels.GetShape().NDim;
122-
var weights_shape = weights_tensor.GetShape();
121+
var labels_rank = labels.TensorShape.NDim;
122+
var weights_shape = weights_tensor.TensorShape;
123123
var weights_rank = weights_shape.NDim;
124124

125125
if (labels_rank > -1 && weights_rank > -1)

src/TensorFlowNET.Core/Operations/NnOps/_WithSpaceToBatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public _WithSpaceToBatch(TensorShape input_shape,
1818
string data_format = null)
1919
{
2020
var dilation_rate_tensor = ops.convert_to_tensor(dilation_rate, TF_DataType.TF_INT32, name: "dilation_rate");
21-
var rate_shape = dilation_rate_tensor.GetShape();
21+
var rate_shape = dilation_rate_tensor.TensorShape;
2222
var num_spatial_dims = rate_shape.Dimensions[0];
2323
int starting_spatial_dim = -1;
2424
if (!string.IsNullOrEmpty(data_format) && data_format.StartsWith("NC"))

src/TensorFlowNET.Core/Operations/confusion_matrix.py.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public static (Tensor, Tensor) remove_squeezable_dimensions(Tensor labels,
2424
{
2525
predictions = ops.convert_to_tensor(predictions);
2626
labels = ops.convert_to_tensor(labels);
27-
var predictions_shape = predictions.GetShape();
27+
var predictions_shape = predictions.TensorShape;
2828
var predictions_rank = predictions_shape.NDim;
29-
var labels_shape = labels.GetShape();
29+
var labels_shape = labels.TensorShape;
3030
var labels_rank = labels_shape.NDim;
3131
if(labels_rank > -1 && predictions_rank > -1)
3232
{

src/TensorFlowNET.Core/Operations/nn_ops.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static Tensor dropout_v2(Tensor x, Tensor rate, Tensor noise_shape = null
8383
// float to be selected, hence we use a >= comparison.
8484
var keep_mask = random_tensor >= rate;
8585
var ret = x * scale * math_ops.cast(keep_mask, x.dtype);
86-
ret.SetShape(x.GetShape());
86+
ret.SetShape(x.TensorShape);
8787
return ret;
8888
});
8989
}
@@ -131,14 +131,14 @@ public static Tensor sparse_softmax_cross_entropy_with_logits(Tensor labels = nu
131131
var precise_logits = logits.dtype == TF_DataType.TF_HALF ? math_ops.cast(logits, dtypes.float32) : logits;
132132

133133
// Store label shape for result later.
134-
var labels_static_shape = labels.GetShape();
134+
var labels_static_shape = labels.TensorShape;
135135
var labels_shape = array_ops.shape(labels);
136136
/*bool static_shapes_fully_defined = (
137137
labels_static_shape.is_fully_defined() &&
138138
logits.get_shape()[:-1].is_fully_defined());*/
139139

140140
// Check if no reshapes are required.
141-
if(logits.GetShape().NDim == 2)
141+
if(logits.TensorShape.NDim == 2)
142142
{
143143
var (cost, _) = gen_nn_ops.sparse_softmax_cross_entropy_with_logits(
144144
precise_logits, labels, name: name);
@@ -163,7 +163,7 @@ public static Tensor softmax_cross_entropy_with_logits_v2_helper(Tensor labels,
163163
{
164164
var precise_logits = logits;
165165
var input_rank = array_ops.rank(precise_logits);
166-
var shape = logits.GetShape();
166+
var shape = logits.TensorShape;
167167

168168
if (axis != -1)
169169
throw new NotImplementedException("softmax_cross_entropy_with_logits_v2_helper axis != -1");

src/TensorFlowNET.Core/Operations/weights_broadcast_ops.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public static Tensor broadcast_weights(Tensor weights, Tensor values)
1616
weights, dtype: values.dtype.as_base_dtype(), name: "weights");
1717

1818
// Try static check for exact match.
19-
var weights_shape = weights.GetShape();
20-
var values_shape = values.GetShape();
19+
var weights_shape = weights.TensorShape;
20+
var values_shape = values.TensorShape;
2121
if (weights_shape.is_fully_defined() &&
2222
values_shape.is_fully_defined())
2323
return weights;

0 commit comments

Comments
 (0)