Keras.NET 0.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Keras.NET --version 0.5.0
                    
NuGet\Install-Package Keras.NET -Version 0.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Keras.NET" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Keras.NET" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Keras.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Keras.NET --version 0.5.0
                    
#r "nuget: Keras.NET, 0.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Keras.NET@0.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Keras.NET&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=Keras.NET&version=0.5.0
                    
Install as a Cake Tool

Keras.NET

Keras.NET is a high-level neural networks API, written in C# with Python Binding and capable of running on top of TensorFlow, CNTK, or Theano. It was developed with a focus on enabling fast experimentation. Being able to go from idea to result with the least possible delay is key to doing good research.

Use Keras if you need a deep learning library that:

Allows for easy and fast prototyping (through user friendliness, modularity, and extensibility). Supports both convolutional networks and recurrent networks, as well as combinations of the two. Runs seamlessly on CPU and GPU.

Keras.NET is using:

Prerequisite

  • Python 3.7
  • Install keras and numpy

Example with XOR sample

//Load train data
NDarray x = np.array(new float[,] { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 } });
NDarray y = np.array(new float[] { 0, 1, 1, 0 });

//Build sequential model
var model = new Sequential();
model.Add(new Dense(32, activation: "relu", input_shape: new Shape(2)));
model.Add(new Dense(64, activation: "relu"));
model.Add(new Dense(1, activation: "sigmoid"));

//Compile and train
model.Compile(optimizer:"sgd", loss:"binary_crossentropy", metrics: new string[] { "accuracy" });
model.Fit(x, y, batch_size: 2, epochs: 1000, verbose: 1);

//Save model and weights
string json = model.ToJson();
File.WriteAllText("model.json", json);
model.SaveWeight("model.h5");

//Load model and weight
var loaded_model = Sequential.ModelFromJson(File.ReadAllText("model.json"));
loaded_model.LoadWeight("model.h5");

Output:

alternate text is missing from this package README image

Another example with Prima Indians Diabetic Dataset

Python example taken from: https://machinelearningmastery.com/save-load-keras-deep-learning-models/

//Load train data
NDarray dataset = np.loadtxt(fname: "pima-indians-diabetes.data.csv", delimiter: ",");
var X = dataset[":,0: 8"];
var Y = dataset[":, 8"];

//Build sequential model
var model = new Sequential();
model.Add(new Dense(12, input_dim: 8, kernel_initializer: "uniform", activation: "relu"));
model.Add(new Dense(8, kernel_initializer: "uniform", activation: "relu"));
model.Add(new Dense(1, activation: "sigmoid"));

//Compile and train
model.Compile(optimizer:"adam", loss:"binary_crossentropy", metrics: new string[] { "accuracy" });
model.Fit(X, Y, batch_size: 10, epochs: 150, verbose: 1);

//Evaluate model
var scores = model.Evaluate(X, Y, verbose: 1);
Console.WriteLine("Accuracy: {0}", scores[1] * 100);

//Save model and weights
string json = model.ToJson();
File.WriteAllText("model.json", json);
model.SaveWeight("model.h5");
Console.WriteLine("Saved model to disk");
//Load model and weight
var loaded_model = Sequential.ModelFromJson(File.ReadAllText("model.json"));
loaded_model.LoadWeight("model.h5");
Console.WriteLine("Loaded model from disk");

loaded_model.Compile(optimizer: "rmsprop", loss: "binary_crossentropy", metrics: new string[] { "accuracy" });
scores = model.Evaluate(X, Y, verbose: 1);
Console.WriteLine("Accuracy: {0}", scores[1] * 100);

Output

alternate text is missing from this package README image

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Keras.NET:

Package Downloads
Laraue.Core.Keras

Utils to launch Keras models in .NET

BasicSamples

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.8.5 28,142 12/7/2020
3.8.4.4 2,847 9/22/2020
3.7.5 1,506 12/7/2020
3.7.4.4 1,215 9/22/2020
3.7.4.2 8,857 5/1/2020
3.7.4.1 1,584 3/23/2020
3.7.3 2,576 1/10/2020
3.6.4.2 1,183 5/1/2020
3.6.4.1 762 3/23/2020
3.6.3 1,003 1/10/2020
3.6.2.4 1,031 12/28/2019
3.6.2.3 745 12/28/2019
3.6.2.2 791 12/28/2019
3.6.2.1 664 12/28/2019
3.6.1.12 1,582 11/8/2019
3.6.1.11 1,111 10/6/2019
3.6.1.10 767 10/6/2019
3.6.1.9 790 9/27/2019
3.6.1.8 3,625 8/22/2019
3.6.1.6 840 8/14/2019
3.6.1.5 897 7/30/2019
3.6.1.4 808 7/22/2019
3.6.1.1 794 7/22/2019
3.5.4.2 681 5/1/2020
3.5.4.1 683 3/23/2020
3.5.3 803 1/10/2020
3.5.2.4 700 12/28/2019
3.5.2.3 727 12/28/2019
3.5.2.2 756 12/28/2019
3.5.2.1 632 12/28/2019
3.5.1.12 660 11/8/2019
3.5.1.11 652 10/6/2019
3.5.1.10 658 10/6/2019
3.5.1.9 671 9/27/2019
3.5.1.8 683 8/22/2019
3.5.1.6 672 8/14/2019
3.5.1.5 678 7/30/2019
3.5.1.4 812 7/22/2019
2.7.5 642 12/7/2020
2.7.4.4 580 9/22/2020
2.7.4.2 628 5/1/2020
2.7.4.1 674 3/23/2020
2.7.3 729 1/10/2020
2.7.2.4 718 12/28/2019
2.7.2.3 744 12/28/2019
2.7.2.2 769 12/28/2019
2.7.2.1 742 12/28/2019
2.7.1.12 638 11/8/2019
2.7.1.11 675 10/6/2019
2.7.1.10 636 10/6/2019
2.7.1.9 621 9/27/2019
2.7.1.8 661 8/22/2019
2.7.1.6 659 8/14/2019
2.7.1.5 665 7/30/2019
2.7.1.4 676 7/22/2019
2.7.1.2 703 7/22/2019
2.7.1.1 785 7/22/2019
0.6.4 886 7/16/2019
0.6.3 815 6/26/2019
0.6.2 691 6/25/2019
0.6.0 708 6/21/2019
0.5.2 703 6/18/2019
0.5.0 773 6/18/2019