@@ -32,6 +32,7 @@ public class TextClassificationTrain : IExample
3232 public string model_name = "vd_cnn" ; // word_cnn | char_cnn | vd_cnn | word_rnn | att_rnn | rcnn
3333
3434 private const int CHAR_MAX_LEN = 1014 ;
35+ private const int WORD_MAX_LEN = 1014 ;
3536 private const int NUM_CLASS = 2 ;
3637 private const int BATCH_SIZE = 64 ;
3738 private const int NUM_EPOCHS = 10 ;
@@ -58,6 +59,8 @@ protected virtual bool RunWithImportedGraph(Session sess, Graph graph)
5859 Console . WriteLine ( "\t DONE " ) ;
5960
6061 var ( train_x , valid_x , train_y , valid_y ) = train_test_split ( x , y , test_size : 0.15f ) ;
62+ Console . WriteLine ( "Training set size: " + train_x . shape [ 0 ] ) ;
63+ Console . WriteLine ( "Test set size: " + valid_x . shape [ 0 ] ) ;
6164
6265 Console . WriteLine ( "Import graph..." ) ;
6366 var meta_file = model_name + ".meta" ;
@@ -74,7 +77,6 @@ protected virtual bool RunWithImportedGraph(Session sess, Graph graph)
7477 Tensor model_x = graph . get_operation_by_name ( "x" ) ;
7578 Tensor model_y = graph . get_operation_by_name ( "y" ) ;
7679 Tensor loss = graph . get_operation_by_name ( "loss/value" ) ;
77- //var optimizer_nodes = graph._nodes_by_name.Keys.Where(key => key.Contains("optimizer")).ToArray();
7880 Tensor optimizer = graph . get_operation_by_name ( "loss/optimizer" ) ;
7981 Tensor global_step = graph . get_operation_by_name ( "global_step" ) ;
8082 Tensor accuracy = graph . get_operation_by_name ( "accuracy/value" ) ;
@@ -92,7 +94,7 @@ protected virtual bool RunWithImportedGraph(Session sess, Graph graph)
9294 // original python:
9395 //_, step, loss = sess.run([model.optimizer, model.global_step, model.loss], feed_dict = train_feed_dict)
9496 var result = sess . run ( new ITensorOrOperation [ ] { optimizer , global_step , loss } , train_feed_dict ) ;
95- // loss_value = result[2];
97+ loss_value = result [ 2 ] ;
9698 var step = result [ 1 ] ;
9799 if ( step % 10 == 0 )
98100 {
@@ -177,7 +179,7 @@ protected virtual bool RunWithBuiltGraph(Session session, Graph graph)
177179
178180 private IEnumerable < ( NDArray , NDArray , int ) > batch_iter ( NDArray inputs , NDArray outputs , int batch_size , int num_epochs )
179181 {
180- var num_batches_per_epoch = ( len ( inputs ) - 1 ) / batch_size ;
182+ var num_batches_per_epoch = ( len ( inputs ) - 1 ) / batch_size + 1 ;
181183 var total_batches = num_batches_per_epoch * num_epochs ;
182184 foreach ( var epoch in range ( num_epochs ) )
183185 {
@@ -202,8 +204,13 @@ public void PrepareData()
202204 {
203205 // download graph meta data
204206 var meta_file = model_name + ".meta" ;
205- if ( File . GetLastWriteTime ( meta_file ) < new DateTime ( 2019 , 05 , 11 ) ) // delete old cached file which contains errors
206- File . Delete ( meta_file ) ;
207+ var meta_path = Path . Combine ( "graph" , meta_file ) ;
208+ if ( File . GetLastWriteTime ( meta_path ) < new DateTime ( 2019 , 05 , 11 ) )
209+ {
210+ // delete old cached file which contains errors
211+ Console . WriteLine ( "Discarding cached file: " + meta_path ) ;
212+ File . Delete ( meta_path ) ;
213+ }
207214 url = "https://raw.githubusercontent.com/SciSharp/TensorFlow.NET/master/graph/" + meta_file ;
208215 Web . Download ( url , "graph" , meta_file ) ;
209216 }
0 commit comments