diff --git a/src/TensorFlowHub/Class1.cs b/src/TensorFlowHub/Class1.cs deleted file mode 100644 index b6bc08de..00000000 --- a/src/TensorFlowHub/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace TensorFlowHub -{ - public class Class1 - { - } -} diff --git a/src/TensorFlowHub/DataSetBase.cs b/src/TensorFlowHub/DataSetBase.cs new file mode 100644 index 00000000..dc47b1c8 --- /dev/null +++ b/src/TensorFlowHub/DataSetBase.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NumSharp; + +namespace Tensorflow.Hub +{ + public abstract class DataSetBase : IDataSet + { + public NDArray Data { get; protected set; } + public NDArray Labels { get; protected set; } + } +} diff --git a/src/TensorFlowHub/Datasets.cs b/src/TensorFlowHub/Datasets.cs new file mode 100644 index 00000000..6c05efb6 --- /dev/null +++ b/src/TensorFlowHub/Datasets.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NumSharp; + +namespace Tensorflow.Hub +{ + public class Datasets where TDataSet : IDataSet + { + public TDataSet Train { get; private set; } + + public TDataSet Validation { get; private set; } + + public TDataSet Test { get; private set; } + + public Datasets(TDataSet train, TDataSet validation, TDataSet test) + { + Train = train; + Validation = validation; + Test = test; + } + + public (NDArray, NDArray) Randomize(NDArray x, NDArray y) + { + var perm = np.random.permutation(y.shape[0]); + np.random.shuffle(perm); + return (x[perm], y[perm]); + } + + /// + /// selects a few number of images determined by the batch_size variable (if you don't know why, read about Stochastic Gradient Method) + /// + /// + /// + /// + /// + /// + public (NDArray, NDArray) GetNextBatch(NDArray x, NDArray y, int start, int end) + { + var slice = new Slice(start, end); + var x_batch = x[slice]; + var y_batch = y[slice]; + return (x_batch, y_batch); + } + } +} diff --git a/src/TensorFlowHub/IDataSet.cs b/src/TensorFlowHub/IDataSet.cs new file mode 100644 index 00000000..f38a4217 --- /dev/null +++ b/src/TensorFlowHub/IDataSet.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NumSharp; + +namespace Tensorflow.Hub +{ + public interface IDataSet + { + NDArray Data { get; } + NDArray Labels { get; } + } +} diff --git a/src/TensorFlowHub/IModelLoader.cs b/src/TensorFlowHub/IModelLoader.cs new file mode 100644 index 00000000..530138af --- /dev/null +++ b/src/TensorFlowHub/IModelLoader.cs @@ -0,0 +1,14 @@ +using System; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using NumSharp; + +namespace Tensorflow.Hub +{ + public interface IModelLoader + where TDataSet : IDataSet + { + Task> LoadAsync(ModelLoadSetting setting); + } +} diff --git a/src/TensorFlowHub/MnistDataSet.cs b/src/TensorFlowHub/MnistDataSet.cs new file mode 100644 index 00000000..65b8ebae --- /dev/null +++ b/src/TensorFlowHub/MnistDataSet.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NumSharp; +using Tensorflow; + +namespace Tensorflow.Hub +{ + public class MnistDataSet : DataSetBase + { + public int NumOfExamples { get; private set; } + public int EpochsCompleted { get; private set; } + public int IndexInEpoch { get; private set; } + + public MnistDataSet(NDArray images, NDArray labels, TF_DataType dtype, bool reshape) + { + EpochsCompleted = 0; + IndexInEpoch = 0; + + NumOfExamples = images.shape[0]; + + images = images.reshape(images.shape[0], images.shape[1] * images.shape[2]); + images.astype(dtype.as_numpy_datatype()); + images = np.multiply(images, 1.0f / 255.0f); + Data = images; + + labels.astype(dtype.as_numpy_datatype()); + Labels = labels; + } + } +} diff --git a/src/TensorFlowHub/MnistModelLoader.cs b/src/TensorFlowHub/MnistModelLoader.cs new file mode 100644 index 00000000..9e612a11 --- /dev/null +++ b/src/TensorFlowHub/MnistModelLoader.cs @@ -0,0 +1,16 @@ +using System; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Text; +using NumSharp; + +namespace Tensorflow.Hub +{ + public class MnistModelLoader : IModelLoader + { + public Task> LoadAsync(ModelLoadSetting setting) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/TensorFlowHub/ModelLoadSetting.cs b/src/TensorFlowHub/ModelLoadSetting.cs new file mode 100644 index 00000000..95bbaa48 --- /dev/null +++ b/src/TensorFlowHub/ModelLoadSetting.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NumSharp; + +namespace Tensorflow.Hub +{ + public class ModelLoadSetting + { + public string TrainDir { get; set; } + public bool OneHot { get; set; } + public TF_DataType DtType { get; set; } = TF_DataType.TF_FLOAT; + public bool ReShape { get; set; } + public int ValidationSize { get; set; } = 5000; + public int? TrainSize { get; set; } + public int? TestSize { get; set; } + public string SourceUrl { get; set; } + } +} diff --git a/src/TensorFlowHub/TensorFlowHub.csproj b/src/TensorFlowHub/TensorFlowHub.csproj index 9f5c4f4a..b79578a4 100644 --- a/src/TensorFlowHub/TensorFlowHub.csproj +++ b/src/TensorFlowHub/TensorFlowHub.csproj @@ -1,7 +1,13 @@ - + TensorFlow.Net.Hub + Tensorflow.Hub netstandard2.0 - + + + + + +