diff --git a/TensorFlow.NET.sln b/TensorFlow.NET.sln index 6d618d8d..3173c1a9 100644 --- a/TensorFlow.NET.sln +++ b/TensorFlow.NET.sln @@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Console", "src\T EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Keras", "src\TensorFlowNET.Keras\Tensorflow.Keras.csproj", "{49D71826-C03D-4FA7-9BAC-22C1327E65CF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tensorflow.Text", "src\TensorFlowNET.Text\Tensorflow.Text.csproj", "{1AB8108D-4FFE-4A16-88E7-328EAF686370}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Text", "src\TensorFlowNET.Text\Tensorflow.Text.csproj", "{1AB8108D-4FFE-4A16-88E7-328EAF686370}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Recommenders", "src\TensorFlowNET.Recommenders\Tensorflow.Recommenders.csproj", "{F17AAECB-960A-4E18-A270-BAD776F0E55B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -175,6 +177,30 @@ Global {1AB8108D-4FFE-4A16-88E7-328EAF686370}.Release|x64.Build.0 = Release|Any CPU {1AB8108D-4FFE-4A16-88E7-328EAF686370}.Release|x86.ActiveCfg = Release|Any CPU {1AB8108D-4FFE-4A16-88E7-328EAF686370}.Release|x86.Build.0 = Release|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug|x64.ActiveCfg = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug|x64.Build.0 = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug|x86.ActiveCfg = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug|x86.Build.0 = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug-Minimal|Any CPU.ActiveCfg = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug-Minimal|Any CPU.Build.0 = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug-Minimal|x64.ActiveCfg = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug-Minimal|x64.Build.0 = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug-Minimal|x86.ActiveCfg = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Debug-Minimal|x86.Build.0 = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Publish|Any CPU.ActiveCfg = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Publish|Any CPU.Build.0 = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Publish|x64.ActiveCfg = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Publish|x64.Build.0 = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Publish|x86.ActiveCfg = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Publish|x86.Build.0 = Debug|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Release|Any CPU.Build.0 = Release|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Release|x64.ActiveCfg = Release|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Release|x64.Build.0 = Release|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Release|x86.ActiveCfg = Release|Any CPU + {F17AAECB-960A-4E18-A270-BAD776F0E55B}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/TensorFlowNET.Console/Tensorflow.Console.csproj b/src/TensorFlowNET.Console/Tensorflow.Console.csproj index 8d7a66d1..d2b64e80 100644 --- a/src/TensorFlowNET.Console/Tensorflow.Console.csproj +++ b/src/TensorFlowNET.Console/Tensorflow.Console.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/TensorFlowNET.Keras/Datasets/Imdb.cs b/src/TensorFlowNET.Keras/Datasets/Imdb.cs new file mode 100644 index 00000000..98769a21 --- /dev/null +++ b/src/TensorFlowNET.Keras/Datasets/Imdb.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using Tensorflow.Keras.Utils; +using NumSharp; +using System.Linq; + +namespace Tensorflow.Keras.Datasets +{ + /// + /// This is a dataset of 25,000 movies reviews from IMDB, labeled by sentiment + /// (positive/negative). Reviews have been preprocessed, and each review is + /// encoded as a list of word indexes(integers). + /// + public class Imdb + { + string origin_folder = "https://storage.googleapis.com/tensorflow/tf-keras-datasets/"; + string file_name = "imdb.npz"; + string dest_folder = "imdb"; + + /// + /// Loads the [IMDB dataset](https://ai.stanford.edu/~amaas/data/sentiment/). + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public DatasetPass load_data(string path = "imdb.npz", + int num_words = -1, + int skip_top = 0, + int maxlen = -1, + int seed = 113, + int start_char = 1, + int oov_char= 2, + int index_from = 3) + { + var dst = Download(); + + var lines = File.ReadAllLines(Path.Combine(dst, "imdb_train.txt")); + var x_train_string = new string[lines.Length]; + var y_train = np.zeros(new int[] { lines.Length }, NPTypeCode.Int64); + for (int i = 0; i < lines.Length; i++) + { + y_train[i] = long.Parse(lines[i].Substring(0, 1)); + x_train_string[i] = lines[i].Substring(2); + } + + var x_train = np.array(x_train_string); + + File.ReadAllLines(Path.Combine(dst, "imdb_test.txt")); + var x_test_string = new string[lines.Length]; + var y_test = np.zeros(new int[] { lines.Length }, NPTypeCode.Int64); + for (int i = 0; i < lines.Length; i++) + { + y_test[i] = long.Parse(lines[i].Substring(0, 1)); + x_test_string[i] = lines[i].Substring(2); + } + + var x_test = np.array(x_test_string); + + return new DatasetPass + { + Train = (x_train, y_train), + Test = (x_test, y_test) + }; + } + + (NDArray, NDArray) LoadX(byte[] bytes) + { + var y = np.Load_Npz(bytes); + return (y["x_train.npy"], y["x_test.npy"]); + } + + (NDArray, NDArray) LoadY(byte[] bytes) + { + var y = np.Load_Npz(bytes); + return (y["y_train.npy"], y["y_test.npy"]); + } + + string Download() + { + var dst = Path.Combine(Path.GetTempPath(), dest_folder); + Directory.CreateDirectory(dst); + + Web.Download(origin_folder + file_name, dst, file_name); + + return dst; + // return Path.Combine(dst, file_name); + } + } +} diff --git a/src/TensorFlowNET.Keras/Datasets/KerasDataset.cs b/src/TensorFlowNET.Keras/Datasets/KerasDataset.cs index d5442298..0a328702 100644 --- a/src/TensorFlowNET.Keras/Datasets/KerasDataset.cs +++ b/src/TensorFlowNET.Keras/Datasets/KerasDataset.cs @@ -20,5 +20,6 @@ namespace Tensorflow.Keras.Datasets { public Mnist mnist { get; } = new Mnist(); public Cifar10 cifar10 { get; } = new Cifar10(); + public Imdb imdb { get; } = new Imdb(); } } diff --git a/src/TensorFlowNET.Keras/Preprocessings/Preprocessing.image_dataset_from_directory.cs b/src/TensorFlowNET.Keras/Preprocessings/Preprocessing.image_dataset_from_directory.cs index a57ac73e..c17799ac 100644 --- a/src/TensorFlowNET.Keras/Preprocessings/Preprocessing.image_dataset_from_directory.cs +++ b/src/TensorFlowNET.Keras/Preprocessings/Preprocessing.image_dataset_from_directory.cs @@ -57,5 +57,20 @@ namespace Tensorflow.Keras dataset = dataset.batch(batch_size); return dataset; } + + public IDatasetV2 text_dataset_from_directory(string directory, + string labels = "inferred", + string label_mode = "int", + string[] class_names = null, + int batch_size = 32, + bool shuffle = true, + int? seed = null, + float validation_split = 0.2f, + string subset = null) + { + + + return null; + } } } diff --git a/src/TensorFlowNET.Recommenders/Tensorflow.Recommenders.csproj b/src/TensorFlowNET.Recommenders/Tensorflow.Recommenders.csproj new file mode 100644 index 00000000..ba47de36 --- /dev/null +++ b/src/TensorFlowNET.Recommenders/Tensorflow.Recommenders.csproj @@ -0,0 +1,21 @@ + + + + netstandard2.0 + 0.0.1 + TensorFlow Recommenders is a library for building recommender system models using TensorFlow. + LICENSE + + + + + True + + + + + + + + + diff --git a/src/TensorFlowNET.Text/Tensorflow.Text.csproj b/src/TensorFlowNET.Text/Tensorflow.Text.csproj index 9a56bea2..e687524c 100644 --- a/src/TensorFlowNET.Text/Tensorflow.Text.csproj +++ b/src/TensorFlowNET.Text/Tensorflow.Text.csproj @@ -6,6 +6,7 @@ Tensorflow.Text true 0.0.1 + LICENSE @@ -13,7 +14,14 @@ - + + True + + + + + + diff --git a/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj b/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj index c539919c..9069f2ec 100644 --- a/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj +++ b/src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj @@ -29,12 +29,11 @@ - - + - + diff --git a/test/TensorFlowNET.UnitTest/Tensorflow.UnitTest.csproj b/test/TensorFlowNET.UnitTest/Tensorflow.UnitTest.csproj index f5792971..bb3a16c8 100644 --- a/test/TensorFlowNET.UnitTest/Tensorflow.UnitTest.csproj +++ b/test/TensorFlowNET.UnitTest/Tensorflow.UnitTest.csproj @@ -55,7 +55,7 @@ - +