Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakkumar1984 committed Jun 5, 2019
2 parents 0d9e5bc + e8ca84d commit 1f8a22e
Show file tree
Hide file tree
Showing 168 changed files with 998 additions and 1,136 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,5 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc
/examples/MNIST/model
44 changes: 15 additions & 29 deletions MxNetLib.CSharp.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.489
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.202
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7F9899A6-10C3-44BE-8696-EAEA7C2D596B}"
EndProject
Expand All @@ -15,16 +15,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BostonHousingRegression", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTest", "examples\ConsoleTest\ConsoleTest.csproj", "{FC8EAC50-7DAA-4B7B-8C25-200C551A3805}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "library", "library", "{CEEC827D-B484-493F-A87F-6198C2932111}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MxNetLib", "src\library\MxNetLib\MxNetLib.csproj", "{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MxNetLib.NN", "src\MxNETLib.NN\MxNetLib.NN.csproj", "{ADB0F6E6-5875-4681-AF38-1703A1257A4D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MxNetLib.OpGenerator", "src\MxNetLib.OpGenerator\MxNetLib.OpGenerator.csproj", "{7B131000-BB76-460C-948B-F5A557B6EB6B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{E14006BF-4543-41FD-A2DE-821DB4211935}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MxNetLib", "src\MxNetLib\MxNetLib.csproj", "{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -65,30 +61,22 @@ Global
{FC8EAC50-7DAA-4B7B-8C25-200C551A3805}.Release|Any CPU.Build.0 = Release|Any CPU
{FC8EAC50-7DAA-4B7B-8C25-200C551A3805}.Release|x64.ActiveCfg = Release|Any CPU
{FC8EAC50-7DAA-4B7B-8C25-200C551A3805}.Release|x64.Build.0 = Release|Any CPU
{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897}.Debug|x64.ActiveCfg = Debug|Any CPU
{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897}.Debug|x64.Build.0 = Debug|Any CPU
{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897}.Release|Any CPU.Build.0 = Release|Any CPU
{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897}.Release|x64.ActiveCfg = Release|Any CPU
{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897}.Release|x64.Build.0 = Release|Any CPU
{ADB0F6E6-5875-4681-AF38-1703A1257A4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ADB0F6E6-5875-4681-AF38-1703A1257A4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ADB0F6E6-5875-4681-AF38-1703A1257A4D}.Debug|x64.ActiveCfg = Debug|x64
{ADB0F6E6-5875-4681-AF38-1703A1257A4D}.Debug|x64.Build.0 = Debug|x64
{ADB0F6E6-5875-4681-AF38-1703A1257A4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ADB0F6E6-5875-4681-AF38-1703A1257A4D}.Release|Any CPU.Build.0 = Release|Any CPU
{ADB0F6E6-5875-4681-AF38-1703A1257A4D}.Release|x64.ActiveCfg = Release|x64
{ADB0F6E6-5875-4681-AF38-1703A1257A4D}.Release|x64.Build.0 = Release|x64
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Debug|x64.ActiveCfg = Debug|Any CPU
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Debug|x64.Build.0 = Debug|Any CPU
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Debug|x64.ActiveCfg = Debug|x64
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Debug|x64.Build.0 = Debug|x64
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Release|Any CPU.Build.0 = Release|Any CPU
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Release|x64.ActiveCfg = Release|Any CPU
{7B131000-BB76-460C-948B-F5A557B6EB6B}.Release|x64.Build.0 = Release|Any CPU
{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8}.Debug|x64.ActiveCfg = Debug|x64
{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8}.Debug|x64.Build.0 = Debug|x64
{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8}.Release|Any CPU.Build.0 = Release|Any CPU
{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8}.Release|x64.ActiveCfg = Release|Any CPU
{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -98,10 +86,8 @@ Global
{17E02EF9-EE16-4959-8364-14CD53321D68} = {A28464AE-58E0-4BCD-AA19-B65E571DC285}
{8AEA3E2F-9EB7-4FB4-A6CA-864D51625F38} = {A28464AE-58E0-4BCD-AA19-B65E571DC285}
{FC8EAC50-7DAA-4B7B-8C25-200C551A3805} = {A28464AE-58E0-4BCD-AA19-B65E571DC285}
{CEEC827D-B484-493F-A87F-6198C2932111} = {7F9899A6-10C3-44BE-8696-EAEA7C2D596B}
{63AFC60F-E3CB-45D6-BA50-CDB47B1D2897} = {CEEC827D-B484-493F-A87F-6198C2932111}
{ADB0F6E6-5875-4681-AF38-1703A1257A4D} = {7F9899A6-10C3-44BE-8696-EAEA7C2D596B}
{7B131000-BB76-460C-948B-F5A557B6EB6B} = {7F9899A6-10C3-44BE-8696-EAEA7C2D596B}
{26EAB045-8EE9-4FEC-A67E-212B5FA47FB8} = {7F9899A6-10C3-44BE-8696-EAEA7C2D596B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6C75B613-36E0-4042-B237-EB2E76AE1E8C}
Expand Down
69 changes: 68 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,68 @@
# MxNet-NN
# MxNet

Apache MXNet (incubating) is a deep learning framework designed for both efficiency and flexibility. It allows you to mix symbolic and imperative programming to maximize efficiency and productivity. At its core, MXNet contains a dynamic dependency scheduler that automatically parallelizes both symbolic and imperative operations on the fly. A graph optimization layer on top of that makes symbolic execution fast and memory efficient. MXNet is portable and lightweight, scaling effectively to multiple GPUs and multiple machines.

MXNet is more than a deep learning project. It is a collection of blue prints and guidelines for building deep learning systems, and interesting insights of DL systems for hackers.

mxnetlib is a CSharp binding coving all the Imperative and Symbolic API's with an easy to use interface. Also developed a high level interface to build and train model.

Setup MxNet for Windows: https://github.com/deepakkumar1984/mxnetlib/wiki/Setup---Windows

## Nuget

Install the package: Install-Package MxNetLib

https://www.nuget.org/packages/MxNetLib

## Symbolic Example
```csharp
model.SetInput(784);

var x = Symbol.Variable("X");
var fc1 = sym.Relu(sym.FullyConnected(x, Symbol.Variable("fc1_w"), 128));
var fc2 = sym.Relu(sym.FullyConnected(fc1, Symbol.Variable("fc2_w"), 128));
var fc3 = sym.FullyConnected(fc2, Symbol.Variable("fc3_w"), 10);
var output = sym.SoftmaxOutput(fc3, Symbol.Variable("label"), symbol_name: "model");

model.SetDefaultInitializer(new RandomUniform(-1, 1));
model.Compile(output, OptimizerRegistry.SGD(), MetricType.Accuracy);
```

## High Level API Example
```csharp
model.SetInput(784);

model.Add(new Dense(128, ActivationType.ReLU, kernalInitializer: new RandomUniform(-1, 1)));
model.Add(new Dense(128, ActivationType.ReLU, kernalInitializer: new RandomUniform(-1, 1)));
model.Add(new Dense(10));

model.Compile(OptimizerRegistry.SGD(), LossType.SoftmaxCategorialCrossEntropy, MetricType.Accuracy);
```

## Train and Inference

```csharp

//Training for 10 epoch
model.Fit(train, 10, batchSize, val);

//Load test data
ImageDataFrame frame = new ImageDataFrame(1, 28, 28);
frame.LoadImages("test_6.png", "test_4.png", "test_4.png", "test_6.png");
NDArray test = frame.ToVariable().Ravel() / 255;

// Predict
var prediction = model.Predict(test).Argmax();
Console.WriteLine(prediction.ToString());
```

## Saving and Loading model and checkpoint

```csharp
string modelFolder = "../../../model";
model.SaveModel(modelFolder);
model.SaveCheckpoint(modelFolder);

var loadedModel = Module.LoadModel(modelFolder);
loadedModel.LoadCheckpoint(modelFolder);
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MxNETLib.NN\MxNetLib.NN.csproj" />
<ProjectReference Include="..\..\src\MxNetLib\MxNetLib.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion examples/BostonHousingRegression/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void Main(string[] args)
model.Add(new Dense(32, ActivationType.ReLU));
model.Add(new Dense(1));

model.Compile(Optimizers.Adam(), LossType.MeanSquaredError, MetricType.MeanAbsoluteError);
model.Compile(OptimizerRegistry.Adam(), LossType.MeanSquaredError, MetricType.MeanAbsoluteError);
model.Fit(train, 1000, 32);

Console.ReadLine();
Expand Down
2 changes: 1 addition & 1 deletion examples/ConsoleTest/ConsoleTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\library\MxNetLib\MxNetLib.csproj" />
<ProjectReference Include="..\MNIST\MNIST.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion examples/ConsoleTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Program
{
static void Main(string[] args)
{
MXNet.SetDevice(DeviceType.GPU);
MXNet.SetDevice(DeviceType.CPU);
NDArray x = new NDArray(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new Shape(3, 3)).Reshape(new Shape(9));
NDArray y = new NDArray(new float[] { -1, -2, 3, 4, -5, -6, -7, -8 }, new Shape(9));
//var acc = new Accuracy();
Expand Down
15 changes: 13 additions & 2 deletions examples/MNIST/MNIST.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\library\MxNetLib\MxNetLib.csproj" />
<ProjectReference Include="..\..\src\MxNETLib.NN\MxNetLib.NN.csproj" />
<ProjectReference Include="..\..\src\MxNetLib\MxNetLib.csproj" />
</ItemGroup>

<ItemGroup>
Expand All @@ -33,6 +32,18 @@
<None Update="mnist_data\train-labels-idx1-ubyte">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test_2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test_4.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test_5.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test_6.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading

0 comments on commit 1f8a22e

Please sign in to comment.