diff --git a/TensorFlow.NET.sln b/TensorFlow.NET.sln index 5562853c..e599d8b9 100644 --- a/TensorFlow.NET.sln +++ b/TensorFlow.NET.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "test\TensorFlow EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Keras", "src\TensorFlowNET.Keras\Tensorflow.Keras.csproj", "{6268B461-486A-460B-9B3C-86493CBBAAF7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tensorflow.Keras.UnitTest", "test\Tensorflow.Keras.UnitTest\Tensorflow.Keras.UnitTest.csproj", "{EB92DD90-6346-41FB-B967-2B33A860AD98}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,14 @@ Global {6268B461-486A-460B-9B3C-86493CBBAAF7}.Release|Any CPU.Build.0 = Release|Any CPU {6268B461-486A-460B-9B3C-86493CBBAAF7}.Release|x64.ActiveCfg = Release|Any CPU {6268B461-486A-460B-9B3C-86493CBBAAF7}.Release|x64.Build.0 = Release|Any CPU + {EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|x64.ActiveCfg = Debug|Any CPU + {EB92DD90-6346-41FB-B967-2B33A860AD98}.Debug|x64.Build.0 = Debug|Any CPU + {EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|Any CPU.Build.0 = Release|Any CPU + {EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|x64.ActiveCfg = Release|Any CPU + {EB92DD90-6346-41FB-B967-2B33A860AD98}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/TensorFlowNET.Keras/Engine/CallContext.cs b/src/TensorFlowNET.Keras/Engine/CallContext.cs index 5547c6de..8cc38df7 100644 --- a/src/TensorFlowNET.Keras/Engine/CallContext.cs +++ b/src/TensorFlowNET.Keras/Engine/CallContext.cs @@ -20,7 +20,7 @@ namespace Tensorflow.Keras.Engine } - public void enter(Layer layer, Tensor[] inputs, Graph build_graph, bool training, Saving saving = null) => throw new NotImplementedException(); + public void enter(Layer layer, Tensor[] inputs, Graph build_graph, bool training) => throw new NotImplementedException(); public bool training_arg_passed_to_call(string[] argspec, Dictionary args, Dictionary kwargs) => throw new NotImplementedException(); diff --git a/src/TensorFlowNET.Keras/Engine/Saving.cs b/src/TensorFlowNET.Keras/Engine/Saving.cs deleted file mode 100644 index 8ba804c3..00000000 --- a/src/TensorFlowNET.Keras/Engine/Saving.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Tensorflow.Keras.Engine -{ - public class Saving - { - } -} diff --git a/src/TensorFlowNET.Keras/KwArgs.cs b/src/TensorFlowNET.Keras/KwArgs.cs new file mode 100644 index 00000000..11a90dd8 --- /dev/null +++ b/src/TensorFlowNET.Keras/KwArgs.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras +{ + public class KwArgs + { + private Dictionary args = new Dictionary(); + + public object this[string name] + { + get + { + return args.ContainsKey(name) ? args[name] : null; + } + set + { + args[name] = value; + } + } + + public T Get(string name) + { + if (!args.ContainsKey(name)) + return default(T); + + return (T)args[name]; + } + + public static explicit operator KwArgs(ValueTuple[] p) + { + KwArgs kwArgs = new KwArgs(); + kwArgs.args = new Dictionary(); + foreach (var item in p) + { + kwArgs.args[item.Item1] = item.Item2; + } + + return kwArgs; + } + } +} diff --git a/src/TensorFlowNET.Keras/Optimizer/Adadelta.cs b/src/TensorFlowNET.Keras/Optimizer/Adadelta.cs new file mode 100644 index 00000000..e5d72976 --- /dev/null +++ b/src/TensorFlowNET.Keras/Optimizer/Adadelta.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras +{ + public class Adadelta : Optimizer + { + public Adadelta(float lr= 0.01f, float rho = 0.95f, float? epsilon = null, float decay = 0) : base(null) + { + throw new NotImplementedException(); + } + + public override Tensor[] get_updates(Tensor loss, variables @params) + { + throw new NotImplementedException(); + } + + public override Hashtable get_config() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/TensorFlowNET.Keras/Optimizer/Adagrad.cs b/src/TensorFlowNET.Keras/Optimizer/Adagrad.cs new file mode 100644 index 00000000..4353d79b --- /dev/null +++ b/src/TensorFlowNET.Keras/Optimizer/Adagrad.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras +{ + public class Adagrad : Optimizer + { + public Adagrad(float lr= 0.01f, float? epsilon = null, float decay = 0) : base(null) + { + throw new NotImplementedException(); + } + + public override Tensor[] get_updates(Tensor loss, variables @params) + { + throw new NotImplementedException(); + } + + public override Hashtable get_config() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/TensorFlowNET.Keras/Optimizer/Adam.cs b/src/TensorFlowNET.Keras/Optimizer/Adam.cs new file mode 100644 index 00000000..15053284 --- /dev/null +++ b/src/TensorFlowNET.Keras/Optimizer/Adam.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras +{ + public class Adam : Optimizer + { + public Adam(float lr= 0.001f, float beta_1 = 0.9f, float beta_2 = 0.99f, float? epsilon = null, float decay = 0) : base(null) + { + throw new NotImplementedException(); + } + + public override Tensor[] get_updates(Tensor loss, variables @params) + { + throw new NotImplementedException(); + } + + public override Hashtable get_config() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/TensorFlowNET.Keras/Optimizer/Adamax.cs b/src/TensorFlowNET.Keras/Optimizer/Adamax.cs new file mode 100644 index 00000000..9581c6dc --- /dev/null +++ b/src/TensorFlowNET.Keras/Optimizer/Adamax.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras +{ + public class Adamax : Optimizer + { + public Adamax(float lr = 0.002f, float beta_1 = 0.9f, float beta_2 = 0.999f, float? epsilon = null, float decay = 0) : base(null) + { + throw new NotImplementedException(); + } + + public override Tensor[] get_updates(Tensor loss, variables @params) + { + throw new NotImplementedException(); + } + + public override Hashtable get_config() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/TensorFlowNET.Keras/Optimizer/Nadam.cs b/src/TensorFlowNET.Keras/Optimizer/Nadam.cs new file mode 100644 index 00000000..b933570f --- /dev/null +++ b/src/TensorFlowNET.Keras/Optimizer/Nadam.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras +{ + public class Nadam : Optimizer + { + public Nadam(float lr = 0.002f, float beta_1 = 0.9f, float beta_2 = 0.999f, float? epsilon = null, float schedule_decay = 0.004f) : base(null) + { + throw new NotImplementedException(); + } + + public override Tensor[] get_updates(Tensor loss, variables @params) + { + throw new NotImplementedException(); + } + + public override Hashtable get_config() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/TensorFlowNET.Keras/Optimizer/Optimizer.cs b/src/TensorFlowNET.Keras/Optimizer/Optimizer.cs new file mode 100644 index 00000000..14223c5e --- /dev/null +++ b/src/TensorFlowNET.Keras/Optimizer/Optimizer.cs @@ -0,0 +1,36 @@ +using NumSharp; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras +{ + public class Optimizer + { + public Optimizer(KwArgs kwargs) + { + throw new NotImplementedException(); + } + + public virtual Tensor[] get_updates(Tensor loss, variables @params) + { + return null; + } + + public virtual Tensor[] get_gradients(Tensor loss, variables @params) => throw new NotImplementedException(); + + public virtual void set_weights(NDArray[] weights) => throw new NotImplementedException(); + + public virtual NDArray[] get_weights() => throw new NotImplementedException(); + + public virtual Hashtable get_config() => throw new NotImplementedException(); + + public static string serialize(Optimizer optimizer) => throw new NotImplementedException(); + + public static string deserialize(string config, object custom_objects = null) => throw new NotImplementedException(); + + public static Optimizer get(object identifier) => throw new NotImplementedException(); + + } +} diff --git a/src/TensorFlowNET.Keras/Optimizer/RMSprop.cs b/src/TensorFlowNET.Keras/Optimizer/RMSprop.cs new file mode 100644 index 00000000..79894831 --- /dev/null +++ b/src/TensorFlowNET.Keras/Optimizer/RMSprop.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras +{ + public class RMSprop : Optimizer + { + public RMSprop(float lr= 0.01f, float rho = 0f, float? epsilon = null, float decay = 0) : base(null) + { + throw new NotImplementedException(); + } + + public override Tensor[] get_updates(Tensor loss, variables @params) + { + throw new NotImplementedException(); + } + + public override Hashtable get_config() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/TensorFlowNET.Keras/Optimizer/SGD.cs b/src/TensorFlowNET.Keras/Optimizer/SGD.cs new file mode 100644 index 00000000..17063c54 --- /dev/null +++ b/src/TensorFlowNET.Keras/Optimizer/SGD.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Tensorflow.Keras +{ + public class SGD : Optimizer + { + public SGD(float lr= 0.01f, float momentum= 0, float decay= 0, bool nesterov= false) : base(null) + { + throw new NotImplementedException(); + } + + public override Tensor[] get_updates(Tensor loss, variables @params) + { + throw new NotImplementedException(); + } + + public override Hashtable get_config() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/TensorFlowNET.Keras/OptimizersV2/BaseOptimizerV2.cs b/src/TensorFlowNET.Keras/OptimizersV2/OptimizerV2.cs similarity index 83% rename from src/TensorFlowNET.Keras/OptimizersV2/BaseOptimizerV2.cs rename to src/TensorFlowNET.Keras/OptimizersV2/OptimizerV2.cs index e84acc00..ecb9780a 100644 --- a/src/TensorFlowNET.Keras/OptimizersV2/BaseOptimizerV2.cs +++ b/src/TensorFlowNET.Keras/OptimizersV2/OptimizerV2.cs @@ -4,7 +4,7 @@ using System.Text; namespace Tensorflow.Keras.OptimizersV2 { - class BaseOptimizerV2 + class OptimizerV2 { } } diff --git a/src/TensorFlowNET.Keras/Regularizers/L1L2.cs b/src/TensorFlowNET.Keras/Regularizers/L1L2.cs index 4984790c..927b3319 100644 --- a/src/TensorFlowNET.Keras/Regularizers/L1L2.cs +++ b/src/TensorFlowNET.Keras/Regularizers/L1L2.cs @@ -1,10 +1,25 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Text; namespace Tensorflow.Keras.Regularizers { - class L1L2 + public class L1L2 : Regularizer { + public L1L2(float l1 = 0f, float l2 = 0f) + { + throw new NotImplementedException(); + } + + public override float call(Tensor x) + { + throw new NotImplementedException(); + } + + public override Hashtable get_config() + { + throw new NotImplementedException(); + } } } diff --git a/src/TensorFlowNET.Keras/Regularizers/Regularizer.cs b/src/TensorFlowNET.Keras/Regularizers/Regularizer.cs index ef670912..047b035f 100644 --- a/src/TensorFlowNET.Keras/Regularizers/Regularizer.cs +++ b/src/TensorFlowNET.Keras/Regularizers/Regularizer.cs @@ -1,10 +1,40 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Text; namespace Tensorflow.Keras.Regularizers { - public class Regularizer + public abstract class Regularizer { + public virtual float call(Tensor x) + { + return 0f; + } + + public static Regularizer from_config(Hashtable hashtable) => throw new NotImplementedException(); + + public virtual Hashtable get_config() => throw new NotImplementedException(); + + public static Regularizer l1(float l = 0.01f) + { + return new L1L2(l1: l); + } + + public static Regularizer l2(float l = 0.01f) + { + return new L1L2(l2: l); + } + + public static Regularizer l1_l2(float l1 = 0.01f, float l2 = 0.01f) + { + return new L1L2(l1, l2); + } + + public static string serialize(Regularizer regularizer) => throw new NotImplementedException(); + + public static string deserialize(string config, dynamic custom_objects = null) => throw new NotImplementedException(); + + public static Regularizer get(object identifier) => throw new NotImplementedException(); } } diff --git a/test/Tensorflow.Keras.UnitTest/OptimizerTest.cs b/test/Tensorflow.Keras.UnitTest/OptimizerTest.cs new file mode 100644 index 00000000..1aad1868 --- /dev/null +++ b/test/Tensorflow.Keras.UnitTest/OptimizerTest.cs @@ -0,0 +1,14 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; + +namespace Tensorflow.Keras.UnitTest +{ + [TestClass] + public class OptimizerTest + { + [TestMethod] + public void BaseConstruct() + { + } + } +} diff --git a/test/Tensorflow.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj b/test/Tensorflow.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj new file mode 100644 index 00000000..41dbf2e4 --- /dev/null +++ b/test/Tensorflow.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + +