Browse Source

imdb dataset.

tags/keras_v0.3.0
Oceania2018 4 years ago
parent
commit
93fd34b225
9 changed files with 174 additions and 7 deletions
  1. +27
    -1
      TensorFlow.NET.sln
  2. +1
    -1
      src/TensorFlowNET.Console/Tensorflow.Console.csproj
  3. +97
    -0
      src/TensorFlowNET.Keras/Datasets/Imdb.cs
  4. +1
    -0
      src/TensorFlowNET.Keras/Datasets/KerasDataset.cs
  5. +15
    -0
      src/TensorFlowNET.Keras/Preprocessings/Preprocessing.image_dataset_from_directory.cs
  6. +21
    -0
      src/TensorFlowNET.Recommenders/Tensorflow.Recommenders.csproj
  7. +9
    -1
      src/TensorFlowNET.Text/Tensorflow.Text.csproj
  8. +2
    -3
      src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj
  9. +1
    -1
      test/TensorFlowNET.UnitTest/Tensorflow.UnitTest.csproj

+ 27
- 1
TensorFlow.NET.sln View File

@@ -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


+ 1
- 1
src/TensorFlowNET.Console/Tensorflow.Console.csproj View File

@@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TensorFlowNET.Keras\Tensorflow.Keras.csproj" />
<ProjectReference Include="..\TensorFlowNET.Recommenders\Tensorflow.Recommenders.csproj" />
<ProjectReference Include="..\TensorFlowNET.Text\Tensorflow.Text.csproj" />
</ItemGroup>



+ 97
- 0
src/TensorFlowNET.Keras/Datasets/Imdb.cs View File

@@ -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
{
/// <summary>
/// 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).
/// </summary>
public class Imdb
{
string origin_folder = "https://storage.googleapis.com/tensorflow/tf-keras-datasets/";
string file_name = "imdb.npz";
string dest_folder = "imdb";

/// <summary>
/// Loads the [IMDB dataset](https://ai.stanford.edu/~amaas/data/sentiment/).
/// </summary>
/// <param name="path"></param>
/// <param name="num_words"></param>
/// <param name="skip_top"></param>
/// <param name="maxlen"></param>
/// <param name="seed"></param>
/// <param name="start_char"></param>
/// <param name="oov_char"></param>
/// <param name="index_from"></param>
/// <returns></returns>
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<byte[]>(bytes);
return (y["x_train.npy"], y["x_test.npy"]);
}

(NDArray, NDArray) LoadY(byte[] bytes)
{
var y = np.Load_Npz<long[]>(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);
}
}
}

+ 1
- 0
src/TensorFlowNET.Keras/Datasets/KerasDataset.cs View File

@@ -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();
}
}

+ 15
- 0
src/TensorFlowNET.Keras/Preprocessings/Preprocessing.image_dataset_from_directory.cs View File

@@ -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;
}
}
}

+ 21
- 0
src/TensorFlowNET.Recommenders/Tensorflow.Recommenders.csproj View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>0.0.1</Version>
<Description>TensorFlow Recommenders is a library for building recommender system models using TensorFlow.</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TensorFlowNET.Keras\Tensorflow.Keras.csproj" />
</ItemGroup>

</Project>

+ 9
- 1
src/TensorFlowNET.Text/Tensorflow.Text.csproj View File

@@ -6,6 +6,7 @@
<AssemblyName>Tensorflow.Text</AssemblyName>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.1</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -13,7 +14,14 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TensorFlowNET.Core\Tensorflow.Binding.csproj" />
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TensorFlowNET.Keras\Tensorflow.Keras.csproj" />
</ItemGroup>

</Project>

+ 2
- 3
src/TensorFlowNet.Benchmarks/Tensorflow.Benchmark.csproj View File

@@ -29,12 +29,11 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.3.0" />
<PackageReference Include="TensorFlow.NET" Version="0.20.0" />
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TensorFlowNET.Core\Tensorflow.Binding.csproj" />
<ProjectReference Include="..\TensorFlowNET.Keras\Tensorflow.Keras.csproj" />
</ItemGroup>

</Project>

+ 1
- 1
test/TensorFlowNET.UnitTest/Tensorflow.UnitTest.csproj View File

@@ -55,7 +55,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\TensorFlowNET.Keras\Tensorflow.Keras.csproj" />
<ProjectReference Include="..\..\src\TensorFlowNET.Recommenders\Tensorflow.Recommenders.csproj" />
<ProjectReference Include="..\..\src\TensorFlowNET.Text\Tensorflow.Text.csproj" />
</ItemGroup>



Loading…
Cancel
Save