|
7 | 7 | using Newtonsoft.Json; |
8 | 8 | using System.Linq; |
9 | 9 | using Keras; |
| 10 | +using System.Text.RegularExpressions; |
10 | 11 |
|
11 | 12 | namespace TensorFlowNET.Examples |
12 | 13 | { |
@@ -42,27 +43,45 @@ public void Run() |
42 | 43 | Utility.Compress.UnZip(zipFile, dir); |
43 | 44 |
|
44 | 45 | // prepare training dataset |
45 | | - NDArray x_train = File.ReadAllLines(Path.Join(dir, "x_train.txt")); |
46 | | - NDArray labels_train = File.ReadAllLines(Path.Join(dir, "y_train.txt")); |
47 | | - NDArray indices_train = File.ReadAllLines(Path.Join(dir, "indices_train.txt")); |
| 46 | + var x_train = ReadData(Path.Join(dir, "x_train.txt")); |
| 47 | + var labels_train = ReadData(Path.Join(dir, "y_train.txt")); |
| 48 | + var indices_train = ReadData(Path.Join(dir, "indices_train.txt")); |
48 | 49 | // x_train = x_train[indices_train]; |
49 | 50 | // labels_train = labels_train[indices_train]; |
50 | 51 |
|
51 | | - NDArray x_test = File.ReadAllLines(Path.Join(dir, "x_test.txt")); |
52 | | - NDArray labels_test = File.ReadAllLines(Path.Join(dir, "y_test.txt")); |
53 | | - NDArray indices_test = File.ReadAllLines(Path.Join(dir, "indices_test.txt")); |
| 52 | + var x_test = ReadData(Path.Join(dir, "x_test.txt")); |
| 53 | + var labels_test = ReadData(Path.Join(dir, "y_test.txt")); |
| 54 | + var indices_test = ReadData(Path.Join(dir, "indices_test.txt")); |
54 | 55 | // x_test = x_test[indices_test]; |
55 | 56 | // labels_test = labels_test[indices_test]; |
56 | 57 |
|
57 | 58 | // not completed |
58 | | - var xs = x_train.hstack(x_test); |
| 59 | + /*var xs = x_train.hstack(x_test); |
59 | 60 | var labels = labels_train.hstack(labels_test); |
60 | 61 |
|
61 | 62 | var idx = x_train.size; |
62 | 63 | var y_train = labels_train; |
63 | 64 | var y_test = labels_test; |
64 | 65 |
|
65 | | - return ((x_train, y_train), (x_test, y_test)); |
| 66 | + return ((x_train, y_train), (x_test, y_test));*/ |
| 67 | + |
| 68 | + throw new NotImplementedException(); |
| 69 | + } |
| 70 | + |
| 71 | + private int[][] ReadData(string file) |
| 72 | + { |
| 73 | + var lines = new List<int[]>(); |
| 74 | + |
| 75 | + foreach(var line in File.ReadAllLines(file)) |
| 76 | + { |
| 77 | + var matches = Regex.Matches(line, @"\d+,*"); |
| 78 | + var data = new int[matches.Count]; |
| 79 | + for (int i = 0; i < data.Length; i++) |
| 80 | + data[i] = Convert.ToInt32(matches[i].Value.Trim(',')); |
| 81 | + lines.Add(data.ToArray()); |
| 82 | + } |
| 83 | + |
| 84 | + return lines.ToArray(); |
66 | 85 | } |
67 | 86 |
|
68 | 87 | private Dictionary<string, int> GetWordIndex() |
|
0 commit comments