From 3f9b0b19ab6034dbbc65cdbbfd5f43bdf0dd5fd3 Mon Sep 17 00:00:00 2001 From: Oceania2018 Date: Mon, 29 Jul 2019 07:31:03 -0500 Subject: [PATCH] 2st stage --- src/TensorFlowNET.Core/Sessions/_FetchHandler.cs | 8 +++++--- src/TensorFlowNET.Core/Tensors/tensor_util.cs | 4 ++-- src/TensorFlowNET.Core/Train/Saving/Saver.cs | 8 ++++---- .../ImageProcessing/DigitRecognitionCNN.cs | 2 +- .../ImageProcessing/DigitRecognitionNN.cs | 2 +- .../ImageProcessing/DigitRecognitionRNN.cs | 2 +- .../ImageProcessing/ObjectDetection.cs | 8 ++++---- .../TextProcessing/BinaryTextClassification.cs | 2 +- .../TextProcessing/CnnTextClassification.cs | 4 ++-- test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs | 2 +- 10 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/TensorFlowNET.Core/Sessions/_FetchHandler.cs b/src/TensorFlowNET.Core/Sessions/_FetchHandler.cs index 9b09cd20..babd1dda 100644 --- a/src/TensorFlowNET.Core/Sessions/_FetchHandler.cs +++ b/src/TensorFlowNET.Core/Sessions/_FetchHandler.cs @@ -111,9 +111,11 @@ namespace Tensorflow case "Double": full_values.Add(value.Data()[0]); break; - case "String": - full_values.Add(value.Data()[0]); - break; + /*case "String": + full_values.Add(value.Data()[0]); + break;*/ + default: + throw new NotImplementedException($"build_results tensor_values[0] {tensor_values[0].dtype.Name}"); } } else diff --git a/src/TensorFlowNET.Core/Tensors/tensor_util.cs b/src/TensorFlowNET.Core/Tensors/tensor_util.cs index d55b4175..7dbc2213 100644 --- a/src/TensorFlowNET.Core/Tensors/tensor_util.cs +++ b/src/TensorFlowNET.Core/Tensors/tensor_util.cs @@ -296,9 +296,9 @@ namespace Tensorflow case "Double": tensor_proto.DoubleVal.AddRange(proto_values.Data()); break; - case "String": + /*case "String": tensor_proto.StringVal.AddRange(proto_values.Data().Select(x => Google.Protobuf.ByteString.CopyFromUtf8(x.ToString()))); - break; + break;*/ default: throw new Exception("make_tensor_proto Not Implemented"); } diff --git a/src/TensorFlowNET.Core/Train/Saving/Saver.cs b/src/TensorFlowNET.Core/Train/Saving/Saver.cs index 25adcb5b..781c6461 100644 --- a/src/TensorFlowNET.Core/Train/Saving/Saver.cs +++ b/src/TensorFlowNET.Core/Train/Saving/Saver.cs @@ -170,7 +170,7 @@ namespace Tensorflow { if (string.IsNullOrEmpty(latest_filename)) latest_filename = "checkpoint"; - string model_checkpoint_path = ""; + object model_checkpoint_path = ""; string checkpoint_file = ""; if (global_step > 0) @@ -188,10 +188,10 @@ namespace Tensorflow if (write_state) { - _RecordLastCheckpoint(model_checkpoint_path); + _RecordLastCheckpoint(model_checkpoint_path.ToString()); checkpoint_management.update_checkpoint_state_internal( save_dir: save_path_parent, - model_checkpoint_path: model_checkpoint_path, + model_checkpoint_path: model_checkpoint_path.ToString(), all_model_checkpoint_paths: _last_checkpoints.Keys.Select(x => x).ToList(), latest_filename: latest_filename, save_relative_paths: _save_relative_paths); @@ -205,7 +205,7 @@ namespace Tensorflow export_meta_graph(meta_graph_filename, strip_default_attrs: strip_default_attrs, save_debug_info: save_debug_info); } - return _is_empty ? string.Empty : model_checkpoint_path; + return _is_empty ? string.Empty : model_checkpoint_path.ToString(); } public (Saver, object) import_meta_graph(string meta_graph_or_file, diff --git a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs index b2b90e79..9756db61 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionCNN.cs @@ -136,7 +136,7 @@ namespace TensorFlowNET.Examples.ImageProcess public void Train(Session sess) { // Number of training iterations in each epoch - var num_tr_iter = y_train.len / batch_size; + var num_tr_iter = y_train.shape[0] / batch_size; var init = tf.global_variables_initializer(); sess.run(init); diff --git a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs index 09fdc818..49183987 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionNN.cs @@ -127,7 +127,7 @@ namespace TensorFlowNET.Examples.ImageProcess public void Train(Session sess) { // Number of training iterations in each epoch - var num_tr_iter = mnist.train.labels.len / batch_size; + var num_tr_iter = mnist.train.labels.shape[0] / batch_size; var init = tf.global_variables_initializer(); sess.run(init); diff --git a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs index d51ca9ad..f95e0041 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/DigitRecognitionRNN.cs @@ -88,7 +88,7 @@ namespace TensorFlowNET.Examples.ImageProcess public void Train(Session sess) { // Number of training iterations in each epoch - var num_tr_iter = y_train.len / batch_size; + var num_tr_iter = y_train.shape[0] / batch_size; var init = tf.global_variables_initializer(); sess.run(init); diff --git a/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs b/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs index f40be91f..e37843c8 100644 --- a/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs +++ b/test/TensorFlowNET.Examples/ImageProcessing/ObjectDetection.cs @@ -77,7 +77,7 @@ namespace TensorFlowNET.Examples var results = sess.run(outTensorArr, new FeedItem(imgTensor, imgArr)); - NDArray[] resultArr = results.Data(); + NDArray[] resultArr = results.GetNDArrays(); buildOutputImage(resultArr); } @@ -119,14 +119,14 @@ namespace TensorFlowNET.Examples // get bitmap Bitmap bitmap = new Bitmap(Path.Join(imageDir, "input.jpg")); - float[] scores = resultArr[2].Data(); + float[] scores = resultArr[2].GetData().ToArray(); for (int i=0; i MIN_SCORE) { - float[] boxes = resultArr[1].Data(); + float[] boxes = resultArr[1].GetData().ToArray(); float top = boxes[i * 4] * bitmap.Height; float left = boxes[i * 4 + 1] * bitmap.Width; float bottom = boxes[i * 4 + 2] * bitmap.Height; @@ -140,7 +140,7 @@ namespace TensorFlowNET.Examples Height = (int)(bottom - top) }; - float[] ids = resultArr[3].Data(); + float[] ids = resultArr[3].GetData().ToArray(); string name = pbTxtItems.items.Where(w => w.id == (int)ids[i]).Select(s=>s.display_name).FirstOrDefault(); diff --git a/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs b/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs index 701b97fd..12cc3166 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/BinaryTextClassification.cs @@ -27,7 +27,7 @@ namespace TensorFlowNET.Examples { PrepareData(); - Console.WriteLine($"Training entries: {train_data.len}, labels: {train_labels.len}"); + Console.WriteLine($"Training entries: {train_data.shape[0]}, labels: {train_labels.shape[0]}"); // A dictionary mapping words to an integer index var word_index = GetWordIndex(); diff --git a/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs b/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs index a2afe43d..bbefde5f 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/CnnTextClassification.cs @@ -147,8 +147,8 @@ namespace TensorFlowNET.Examples Console.WriteLine("\tDONE "); var (train_x, valid_x, train_y, valid_y) = train_test_split(x, y, test_size: 0.15f); - Console.WriteLine("Training set size: " + train_x.len); - Console.WriteLine("Test set size: " + valid_x.len); + Console.WriteLine("Training set size: " + train_x.shape[0]); + Console.WriteLine("Test set size: " + valid_x.shape[0]); } public Graph ImportGraph() diff --git a/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs b/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs index ce6628e3..4fc6c652 100644 --- a/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs +++ b/test/TensorFlowNET.Examples/TextProcessing/Word2Vec.cs @@ -120,7 +120,7 @@ namespace TensorFlowNET.Examples // Generate training batch for the skip-gram model private (NDArray, NDArray) next_batch(int batch_size, int num_skips, int skip_window) { - var batch = np.ndarray((batch_size), dtype: np.int32); + var batch = np.ndarray(new Shape(batch_size), dtype: np.int32); var labels = np.ndarray((batch_size, 1), dtype: np.int32); // get window size (words left and right + current one) int span = 2 * skip_window + 1;