Browse Source

Optimizer and Regularizer classes skeleton added

tags/v0.20
Deepak Kumar 5 years ago
parent
commit
1c3529267e
17 changed files with 347 additions and 14 deletions
  1. +10
    -0
      TensorFlow.NET.sln
  2. +1
    -1
      src/TensorFlowNET.Keras/Engine/CallContext.cs
  3. +0
    -10
      src/TensorFlowNET.Keras/Engine/Saving.cs
  4. +43
    -0
      src/TensorFlowNET.Keras/KwArgs.cs
  5. +25
    -0
      src/TensorFlowNET.Keras/Optimizer/Adadelta.cs
  6. +25
    -0
      src/TensorFlowNET.Keras/Optimizer/Adagrad.cs
  7. +25
    -0
      src/TensorFlowNET.Keras/Optimizer/Adam.cs
  8. +25
    -0
      src/TensorFlowNET.Keras/Optimizer/Adamax.cs
  9. +25
    -0
      src/TensorFlowNET.Keras/Optimizer/Nadam.cs
  10. +36
    -0
      src/TensorFlowNET.Keras/Optimizer/Optimizer.cs
  11. +25
    -0
      src/TensorFlowNET.Keras/Optimizer/RMSprop.cs
  12. +25
    -0
      src/TensorFlowNET.Keras/Optimizer/SGD.cs
  13. +1
    -1
      src/TensorFlowNET.Keras/OptimizersV2/OptimizerV2.cs
  14. +16
    -1
      src/TensorFlowNET.Keras/Regularizers/L1L2.cs
  15. +31
    -1
      src/TensorFlowNET.Keras/Regularizers/Regularizer.cs
  16. +14
    -0
      test/Tensorflow.Keras.UnitTest/OptimizerTest.cs
  17. +20
    -0
      test/Tensorflow.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj

+ 10
- 0
TensorFlow.NET.sln View File

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


+ 1
- 1
src/TensorFlowNET.Keras/Engine/CallContext.cs View File

@@ -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<string, object> args, Dictionary<string, object> kwargs) => throw new NotImplementedException();



+ 0
- 10
src/TensorFlowNET.Keras/Engine/Saving.cs View File

@@ -1,10 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow.Keras.Engine
{
public class Saving
{
}
}

+ 43
- 0
src/TensorFlowNET.Keras/KwArgs.cs View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Tensorflow.Keras
{
public class KwArgs
{
private Dictionary<string, object> args = new Dictionary<string, object>();

public object this[string name]
{
get
{
return args.ContainsKey(name) ? args[name] : null;
}
set
{
args[name] = value;
}
}

public T Get<T>(string name)
{
if (!args.ContainsKey(name))
return default(T);

return (T)args[name];
}

public static explicit operator KwArgs(ValueTuple<string, object>[] p)
{
KwArgs kwArgs = new KwArgs();
kwArgs.args = new Dictionary<string, object>();
foreach (var item in p)
{
kwArgs.args[item.Item1] = item.Item2;
}

return kwArgs;
}
}
}

+ 25
- 0
src/TensorFlowNET.Keras/Optimizer/Adadelta.cs View File

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

+ 25
- 0
src/TensorFlowNET.Keras/Optimizer/Adagrad.cs View File

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

+ 25
- 0
src/TensorFlowNET.Keras/Optimizer/Adam.cs View File

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

+ 25
- 0
src/TensorFlowNET.Keras/Optimizer/Adamax.cs View File

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

+ 25
- 0
src/TensorFlowNET.Keras/Optimizer/Nadam.cs View File

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

+ 36
- 0
src/TensorFlowNET.Keras/Optimizer/Optimizer.cs View File

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

}
}

+ 25
- 0
src/TensorFlowNET.Keras/Optimizer/RMSprop.cs View File

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

+ 25
- 0
src/TensorFlowNET.Keras/Optimizer/SGD.cs View File

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

src/TensorFlowNET.Keras/OptimizersV2/BaseOptimizerV2.cs → src/TensorFlowNET.Keras/OptimizersV2/OptimizerV2.cs View File

@@ -4,7 +4,7 @@ using System.Text;

namespace Tensorflow.Keras.OptimizersV2
{
class BaseOptimizerV2
class OptimizerV2
{
}
}

+ 16
- 1
src/TensorFlowNET.Keras/Regularizers/L1L2.cs View File

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

+ 31
- 1
src/TensorFlowNET.Keras/Regularizers/Regularizer.cs View File

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

+ 14
- 0
test/Tensorflow.Keras.UnitTest/OptimizerTest.cs View File

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

+ 20
- 0
test/Tensorflow.Keras.UnitTest/Tensorflow.Keras.UnitTest.csproj View File

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

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>

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

</Project>

Loading…
Cancel
Save