| @@ -11,6 +11,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Core", "src\T | |||||
| EndProject | EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Utility", "src\TensorFlowNET.Utility\TensorFlowNET.Utility.csproj", "{00D9085C-0FC7-453C-A0CC-BAD98F44FEA0}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Utility", "src\TensorFlowNET.Utility\TensorFlowNET.Utility.csproj", "{00D9085C-0FC7-453C-A0CC-BAD98F44FEA0}" | ||||
| EndProject | 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 | Global | ||||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| Debug|Any CPU = Debug|Any CPU | 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}.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.ActiveCfg = Release|Any CPU | ||||
| {00D9085C-0FC7-453C-A0CC-BAD98F44FEA0}.Release|Any CPU.Build.0 = 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 | EndGlobalSection | ||||
| GlobalSection(SolutionProperties) = preSolution | GlobalSection(SolutionProperties) = preSolution | ||||
| HideSolutionNode = FALSE | HideSolutionNode = FALSE | ||||
| @@ -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<IEnumerable<string>> Get() | |||||
| { | |||||
| return new string[] { "value1", "value2" }; | |||||
| } | |||||
| // GET api/values/5 | |||||
| [HttpGet("{id}")] | |||||
| public ActionResult<string> 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) | |||||
| { | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -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<Startup>(); | |||||
| } | |||||
| } | |||||
| @@ -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(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,13 @@ | |||||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | |||||
| <PropertyGroup> | |||||
| <TargetFramework>netcoreapp2.2</TargetFramework> | |||||
| <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | |||||
| </PropertyGroup> | |||||
| <ItemGroup> | |||||
| <PackageReference Include="Microsoft.AspNetCore.App" /> | |||||
| <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> | |||||
| </ItemGroup> | |||||
| </Project> | |||||
| @@ -0,0 +1,9 @@ | |||||
| { | |||||
| "Logging": { | |||||
| "LogLevel": { | |||||
| "Default": "Debug", | |||||
| "System": "Information", | |||||
| "Microsoft": "Information" | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,8 @@ | |||||
| { | |||||
| "Logging": { | |||||
| "LogLevel": { | |||||
| "Default": "Warning" | |||||
| } | |||||
| }, | |||||
| "AllowedHosts": "*" | |||||
| } | |||||
| @@ -51,4 +51,8 @@ Docs: https://tensorflownet.readthedocs.io</Description> | |||||
| <Content CopyToOutputDirectory="PreserveNewest" Include="./runtimes/win-x64/native/tensorflow.dll" Link="tensorflow.dll" Pack="true" PackagePath="runtimes/win-x64/native/tensorflow.dll" /> | <Content CopyToOutputDirectory="PreserveNewest" Include="./runtimes/win-x64/native/tensorflow.dll" Link="tensorflow.dll" Pack="true" PackagePath="runtimes/win-x64/native/tensorflow.dll" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | |||||
| <Folder Include="APIs\Keras\" /> | |||||
| </ItemGroup> | |||||
| </Project> | </Project> | ||||
| @@ -11,8 +11,15 @@ | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <ProjectReference Include="..\..\..\Keras.NET\src\KerasNET.Core\KerasNET.Core.csproj" /> | |||||
| <ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" /> | <ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" /> | ||||
| <ProjectReference Include="..\..\src\TensorFlowNET.Utility\TensorFlowNET.Utility.csproj" /> | <ProjectReference Include="..\..\src\TensorFlowNET.Utility\TensorFlowNET.Utility.csproj" /> | ||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | |||||
| <Reference Include="Newtonsoft.Json"> | |||||
| <HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\newtonsoft.json\9.0.1\lib\netstandard1.0\Newtonsoft.Json.dll</HintPath> | |||||
| </Reference> | |||||
| </ItemGroup> | |||||
| </Project> | </Project> | ||||
| @@ -4,6 +4,9 @@ using System.IO; | |||||
| using System.Text; | using System.Text; | ||||
| using Tensorflow; | using Tensorflow; | ||||
| using NumSharp.Core; | using NumSharp.Core; | ||||
| using Newtonsoft.Json; | |||||
| using System.Linq; | |||||
| using Keras; | |||||
| namespace TensorFlowNET.Examples | namespace TensorFlowNET.Examples | ||||
| { | { | ||||
| @@ -14,10 +17,20 @@ namespace TensorFlowNET.Examples | |||||
| public void Run() | 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["<PAD>"], | |||||
| padding: "post", | |||||
| maxlen: 256); | |||||
| } | } | ||||
| private void PrepareData() | |||||
| private ((NDArray, NDArray), (NDArray, NDArray)) PrepareData() | |||||
| { | { | ||||
| Directory.CreateDirectory(dir); | Directory.CreateDirectory(dir); | ||||
| @@ -32,14 +45,39 @@ namespace TensorFlowNET.Examples | |||||
| NDArray x_train = File.ReadAllLines(Path.Join(dir, "x_train.txt")); | NDArray x_train = File.ReadAllLines(Path.Join(dir, "x_train.txt")); | ||||
| NDArray labels_train = File.ReadAllLines(Path.Join(dir, "y_train.txt")); | NDArray labels_train = File.ReadAllLines(Path.Join(dir, "y_train.txt")); | ||||
| NDArray indices_train = File.ReadAllLines(Path.Join(dir, "indices_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 x_test = File.ReadAllLines(Path.Join(dir, "x_test.txt")); | ||||
| NDArray labels_test = File.ReadAllLines(Path.Join(dir, "y_test.txt")); | NDArray labels_test = File.ReadAllLines(Path.Join(dir, "y_test.txt")); | ||||
| NDArray indices_test = File.ReadAllLines(Path.Join(dir, "indices_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<string, int> GetWordIndex() | |||||
| { | |||||
| var result = new Dictionary<string, int>(); | |||||
| var json = File.ReadAllText(Path.Join(dir, "imdb_word_index.json")); | |||||
| var dict = JsonConvert.DeserializeObject<Dictionary<string, int>>(json); | |||||
| dict.Keys.Select(k => result[k] = dict[k] + 3).ToList(); | |||||
| result["<PAD>"] = 0; | |||||
| result["<START>"] = 1; | |||||
| result["<UNK>"] = 2; // unknown | |||||
| result["<UNUSED>"] = 3; | |||||
| return result; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||