diff --git a/TensorFlow.NET.sln b/TensorFlow.NET.sln index 0e05b4bd..f662c554 100644 --- a/TensorFlow.NET.sln +++ b/TensorFlow.NET.sln @@ -11,6 +11,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Core", "src\T EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Utility", "src\TensorFlowNET.Utility\TensorFlowNET.Utility.csproj", "{00D9085C-0FC7-453C-A0CC-BAD98F44FEA0}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KerasNET.Core", "..\Keras.NET\src\KerasNET.Core\KerasNET.Core.csproj", "{07E37E81-3BCD-4BBB-AE5D-28527F1C7745}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TensorFlowNET.Visualization", "TensorFlowNET.Visualization\TensorFlowNET.Visualization.csproj", "{4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +37,14 @@ Global {00D9085C-0FC7-453C-A0CC-BAD98F44FEA0}.Debug|Any CPU.Build.0 = Debug|Any CPU {00D9085C-0FC7-453C-A0CC-BAD98F44FEA0}.Release|Any CPU.ActiveCfg = Release|Any CPU {00D9085C-0FC7-453C-A0CC-BAD98F44FEA0}.Release|Any CPU.Build.0 = Release|Any CPU + {07E37E81-3BCD-4BBB-AE5D-28527F1C7745}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07E37E81-3BCD-4BBB-AE5D-28527F1C7745}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07E37E81-3BCD-4BBB-AE5D-28527F1C7745}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07E37E81-3BCD-4BBB-AE5D-28527F1C7745}.Release|Any CPU.Build.0 = Release|Any CPU + {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4BB2ABD1-635E-41E4-B534-CB5B6A2D754D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TensorFlowNET.Visualization/Controllers/ValuesController.cs b/TensorFlowNET.Visualization/Controllers/ValuesController.cs new file mode 100644 index 00000000..37089ab5 --- /dev/null +++ b/TensorFlowNET.Visualization/Controllers/ValuesController.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace TensorFlowNET.Visualization.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ValuesController : ControllerBase + { + // GET api/values + [HttpGet] + public ActionResult> Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/TensorFlowNET.Visualization/Program.cs b/TensorFlowNET.Visualization/Program.cs new file mode 100644 index 00000000..de1def2e --- /dev/null +++ b/TensorFlowNET.Visualization/Program.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace TensorFlowNET.Visualization +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/TensorFlowNET.Visualization/Startup.cs b/TensorFlowNET.Visualization/Startup.cs new file mode 100644 index 00000000..c668b596 --- /dev/null +++ b/TensorFlowNET.Visualization/Startup.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace TensorFlowNET.Visualization +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseMvc(); + } + } +} diff --git a/TensorFlowNET.Visualization/TensorFlowNET.Visualization.csproj b/TensorFlowNET.Visualization/TensorFlowNET.Visualization.csproj new file mode 100644 index 00000000..423afacf --- /dev/null +++ b/TensorFlowNET.Visualization/TensorFlowNET.Visualization.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp2.2 + InProcess + + + + + + + + diff --git a/TensorFlowNET.Visualization/appsettings.Development.json b/TensorFlowNET.Visualization/appsettings.Development.json new file mode 100644 index 00000000..e203e940 --- /dev/null +++ b/TensorFlowNET.Visualization/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/TensorFlowNET.Visualization/appsettings.json b/TensorFlowNET.Visualization/appsettings.json new file mode 100644 index 00000000..def9159a --- /dev/null +++ b/TensorFlowNET.Visualization/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/data/imdb.zip b/data/imdb.zip index dc45d13f..f38c4840 100644 Binary files a/data/imdb.zip and b/data/imdb.zip differ diff --git a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj index c4e5891d..ae1c5b8b 100644 --- a/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj +++ b/src/TensorFlowNET.Core/TensorFlowNET.Core.csproj @@ -51,4 +51,8 @@ Docs: https://tensorflownet.readthedocs.io + + + + diff --git a/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj b/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj index 9dc1bd17..826e0ae0 100644 --- a/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj +++ b/test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj @@ -11,8 +11,15 @@ + + + + C:\Program Files\dotnet\sdk\NuGetFallbackFolder\newtonsoft.json\9.0.1\lib\netstandard1.0\Newtonsoft.Json.dll + + + diff --git a/test/TensorFlowNET.Examples/TextClassificationWithMovieReviews.cs b/test/TensorFlowNET.Examples/TextClassificationWithMovieReviews.cs index 95ec24dc..ace5ab31 100644 --- a/test/TensorFlowNET.Examples/TextClassificationWithMovieReviews.cs +++ b/test/TensorFlowNET.Examples/TextClassificationWithMovieReviews.cs @@ -4,6 +4,9 @@ using System.IO; using System.Text; using Tensorflow; using NumSharp.Core; +using Newtonsoft.Json; +using System.Linq; +using Keras; namespace TensorFlowNET.Examples { @@ -14,10 +17,20 @@ namespace TensorFlowNET.Examples public void Run() { - PrepareData(); + var((train_data, train_labels), (test_data, test_labels)) = PrepareData(); + + Console.WriteLine($"Training entries: {train_data.size}, labels: {train_labels.size}"); + + // A dictionary mapping words to an integer index + var word_index = GetWordIndex(); + + train_data = keras.preprocessing.sequence.pad_sequences(train_data, + value: word_index[""], + padding: "post", + maxlen: 256); } - private void PrepareData() + private ((NDArray, NDArray), (NDArray, NDArray)) PrepareData() { Directory.CreateDirectory(dir); @@ -32,14 +45,39 @@ namespace TensorFlowNET.Examples NDArray x_train = File.ReadAllLines(Path.Join(dir, "x_train.txt")); NDArray labels_train = File.ReadAllLines(Path.Join(dir, "y_train.txt")); NDArray indices_train = File.ReadAllLines(Path.Join(dir, "indices_train.txt")); - x_train = x_train[indices_train]; - labels_train = labels_train[indices_train]; + // x_train = x_train[indices_train]; + // labels_train = labels_train[indices_train]; NDArray x_test = File.ReadAllLines(Path.Join(dir, "x_test.txt")); NDArray labels_test = File.ReadAllLines(Path.Join(dir, "y_test.txt")); NDArray indices_test = File.ReadAllLines(Path.Join(dir, "indices_test.txt")); - x_test = x_test[indices_test]; - labels_test = labels_test[indices_test]; + // x_test = x_test[indices_test]; + // labels_test = labels_test[indices_test]; + + // not completed + var xs = x_train.hstack(x_test); + var labels = labels_train.hstack(labels_test); + + var idx = x_train.size; + var y_train = labels_train; + var y_test = labels_test; + + return ((x_train, y_train), (x_test, y_test)); + } + + private Dictionary GetWordIndex() + { + var result = new Dictionary(); + var json = File.ReadAllText(Path.Join(dir, "imdb_word_index.json")); + var dict = JsonConvert.DeserializeObject>(json); + + dict.Keys.Select(k => result[k] = dict[k] + 3).ToList(); + result[""] = 0; + result[""] = 1; + result[""] = 2; // unknown + result[""] = 3; + + return result; } } }