Skip to content

Commit 5b690a0

Browse files
committed
CnnTextClassification debugging
1 parent 16da1c2 commit 5b690a0

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎src/TensorFlowNET.Core/Train/AdamOptimizer.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,12 @@ private Operation _apply_sparse_shared(Tensor grad, RefVariable var, Tensor indi
7070
return (_get_non_slot_variable("beta1_power", graph: graph),
7171
_get_non_slot_variable("beta2_power", graph: graph));
7272
}
73+
74+
public override void _prepare()
75+
{
76+
//copied from GradientDescentOptimizer
77+
LearningRate = _call_if_callable(LearningRate);
78+
LearningRateTensor = ops.convert_to_tensor(LearningRate, name: "learning_rate");
79+
}
7380
}
7481
}

‎test/TensorFlowNET.Examples/TextProcess/CnnTextClassification.cs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public bool Run()
5757
//int classes = y.Data<int>().Distinct().Count();
5858
//int samples = len / classes;
5959
int train_size = (int)Math.Round(len * (1 - test_size));
60-
var train_x = x[new Slice(stop: train_size), new Slice()];
61-
var valid_x = x[new Slice(start: train_size), new Slice()];
62-
var train_y = y[new Slice(stop: train_size)];
63-
var valid_y = y[new Slice(start: train_size)];
60+
train_x = x[new Slice(stop: train_size), new Slice()];
61+
valid_x = x[new Slice(start: train_size), new Slice()];
62+
train_y = y[new Slice(stop: train_size)];
63+
valid_y = y[new Slice(start: train_size)];
6464
Console.WriteLine("\tDONE");
6565
return (train_x, valid_x, train_y, valid_y);
6666
}
@@ -135,7 +135,8 @@ public Graph ImportGraph()
135135
{
136136
// delete old cached file which contains errors
137137
Console.WriteLine("Discarding cached file: " + meta_path);
138-
File.Delete(meta_path);
138+
if(File.Exists(meta_path))
139+
File.Delete(meta_path);
139140
}
140141
var url = "https://raw.githubusercontent.com/SciSharp/TensorFlow.NET/master/graph/" + meta_file;
141142
Web.Download(url, "graph", meta_file);

‎test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ public void TextClassificationTrain()
9191
new TextClassificationTrain() { Enabled = true, DataLimit=100 }.Run();
9292
}
9393

94+
95+
[TestMethod]
96+
public void CnnTextClassificationTrain()
97+
{
98+
tf.Graph().as_default();
99+
new CnnTextClassification() { Enabled = true, IsImportingGraph = false }.Run();
100+
}
101+
102+
94103
[Ignore]
95104
[TestMethod]
96105
public void TextClassificationWithMovieReviews()

0 commit comments

Comments
 (0)