DeepSharp 0.1.0
See the version list below for details.
dotnet add package DeepSharp --version 0.1.0
NuGet\Install-Package DeepSharp -Version 0.1.0
<PackageReference Include="DeepSharp" Version="0.1.0" />
<PackageVersion Include="DeepSharp" Version="0.1.0" />
<PackageReference Include="DeepSharp" />
paket add DeepSharp --version 0.1.0
#r "nuget: DeepSharp, 0.1.0"
#:package DeepSharp@0.1.0
#addin nuget:?package=DeepSharp&version=0.1.0
#tool nuget:?package=DeepSharp&version=0.1.0
DeepSharp — deep learning in C#
The best of both worlds: TensorFlow's way of describing a network, PyTorch's way of running it.
DeepSharp is the C# layer over the engines that already exist. You describe, train and use a network in C#, and the arithmetic runs on whichever engine suits the job — .NET's own vector maths out of the box, libtorch through TorchSharp when the work gets bigger. Swapping between them does not change a line of your model.
What DeepSharp adds is everything around the engine. Getting your data in, the layers, the training loop, the checkpoints, the metrics and the pictures. An engine gives you fast arithmetic; it does not give you a way to describe a network in C#, feed it real data, watch it learn and save the result. That is the part this library is for.
You build the network the way you prefer — stack the layers and let it train, or write the forward pass yourself. Both give the same model, trained by the same loop, saved to the same file.
using DeepSharp.Tensors;
var maths = new CpuBackend();
var a = Tensor.From(new Shape(2, 2), [1f, 2f, 3f, 4f]);
var b = Tensor.From(new Shape(2, 2), [10f, 20f, 30f, 40f]);
var sum = maths.Add(a, b); // 11, 22, 33, 44
Pipeline-driven design
The sequence is always the same — collect the data, add the features, normalise, deal with the gaps, split into training, validation and test, build the model, check it against data it has never seen. DeepSharp asks you to declare that course in advance as one artefact rather than perform it, and then replays it.
The rule that makes it worth doing: anything that learns from the data is fitted on the training split alone and replayed unchanged. A mean, the value that fills a gap, the categories an encoder knows — fit those on everything and the validation set has quietly taught the model about itself, which produces a model that scores beautifully and disappoints on the day it meets real data, with nothing anywhere going red.
The pipeline is saved beside the model, because a model without it is not usable: the numbers reaching it would not be the numbers it was trained on. It is also what the live service runs, so a feature cannot be computed one way in training and another way in production.
The wiki explains it in full.
Version 0.1.0 — what is here today
The first release is the foundation rather than the finished library. What it contains works and is tested; everything above describes where it is going.
| What it does | |
|---|---|
Shape |
Says how big a tensor is — 2x3 is two rows of three. Tells you off straight away if the sizes do not match. |
Tensor |
The numbers themselves, laid out in that shape. Once made it never changes, so it is safe to reuse. |
ITensorBackend |
Which engine does the arithmetic. Your model is written against this, not against an engine. |
CpuBackend |
The engine that needs no installing: your processor's vector instructions, through .NET's own maths. |
Next: learning from mistakes (gradients), then the layers, the optimizers and the training loop. After that a TorchSharp backend, so the same model can run its heavy work on libtorch. The changelog records what each release actually added, and nothing is claimed before it is true.
How this sits next to TorchSharp and TensorFlow.NET
Those are bindings: they hand you PyTorch's or TensorFlow's own interface, written in C#, with the original engine underneath. They are excellent at being that, and DeepSharp is happy to use one.
What they do not give you is a library that reads like C#, a way to pour your data in, a training loop you did not write yourself, or a picture of what happened. DeepSharp sits on top and provides those — and because your model talks to a backend rather than to an engine, the choice of engine stays a choice.
The small print on that choice: the default backend needs nothing installed and travels inside your application, while libtorch is 76 MB for every platform you ship to. You pick per project, not per library.
Getting started
git clone https://github.com/xkqg/DeepSharp.git
cd DeepSharp
dotnet build DeepSharp.slnx -c Release
Runs on .NET 10. The wiki has the walkthrough, the design decisions and what is planned. CONTRIBUTING.md has the rules for changing anything here: a failing test first, no warnings, and a coverage check that fails rather than reports.
Licence
MIT. See LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- System.Numerics.Tensors (>= 10.0.12)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on DeepSharp:
| Package | Downloads |
|---|---|
|
DeepSharp.Learners.Networks
Where a DeepSharp network meets a DeepSharp pipeline: a network learns from the rows the pipeline hands over from its training split, every feature on one scale, is judged by its validation rows and never sees its test rows; the pipeline's report measures it in the answer's own units; what it predicts for a row served later comes back as a value, a probability, a price or a count, as the pipeline's way back gives it. The network and the pipeline it was trained behind are one file, which refuses to be read beside any other fit of that pipeline — and a checkpoint is the same file with what the run needs to go on. |
|
|
DeepSharp.Charts
The charts of a DeepSharp run, drawn from what the training loop and the measures already keep, never from arrays anybody assembles: the loss curve of the training and the validation rows, the learning rate every epoch took, a confusion matrix as a heatmap of counts, what a model predicted against what was there, what was left over, every measure as bars beside the training rows' average, and a correlation as a heatmap. Each chart is handed out as the text of an SVG, drawn by MatPlotLibNet, and kept in a package of its own so a trainer on a machine with no screen never carries a renderer. |
|
|
DeepSharp.Backends.TorchSharp
A DeepSharp network's arithmetic on libtorch, through TorchSharp: TorchBackend.OnCpu() on the processor or TorchBackend.OnGpu(0) on a graphics card, handed to a run as FitOptions.Backend and to a trained network as it serves. The model does not change a line: every layer, loss, optimizer and gradient is the one DeepSharp runs on its light engine, held to the same contract, operation by operation. The engine keeps what it makes in libtorch's memory and lets it go when nothing holds it. It brings TorchSharp alone; the application brings the libtorch it runs on — libtorch-cpu for its platform, TorchSharp-cpu, or TorchSharp-cuda-windows or TorchSharp-cuda-linux for an NVIDIA card — and the engine names those packages when none is there. |
|
|
DeepSharp.Import.Keras
Reads a model Keras 3 saved into a DeepSharp network: the .keras archive it saves a model to, or the HDF5 file it saved one to before. The layers its description names are built as DeepSharp's words in Keras's meaning build them — a batch normalisation keeping Keras's epsilon and the complement of its momentum, a window padded as TensorFlow's 'same' — each activation a layer of its own and the last one the loss applies itself lifted into that loss; its numbers go into the network's slots as Keras lays them out, strictly, every fault named at once where the file holds it. What no network here is built of — a stride of its own for each axis, a dilated window, channels in groups, pooling — is refused at its layer. |
|
|
DeepSharp.Import.PyTorch
Reads a network PyTorch trained into the same network written with DeepSharp: new SafetensorsFile(network, loss).Read(stream) for a safetensors file, new TorchSaveFile(network, loss).Read(stream) for the .pt or .pth file torch.save(model.state_dict(), file) writes. Every number goes into the slot its name names — a linear layer's weights turned round, a convolution's kernel laid out channels last, the rows a flatten makes of images read row by row where PyTorch reads them channel by channel — and the network and its loss come back, to serve, to measure or to train further. A safetensors file is read by a port of safetensors' own reader, so a file it refuses is refused here in its words. The pickle torch.save writes is a program, so it is read by an interpreter that carries out only what PyTorch's own weights-only reader carries out and builds nothing a file names but what a state dictionary is made of: any other name is refused where the file names it, before anything is looked up, built or run. Every fault among the tensors is named at once by the tensor's name, and a network takes all of a file's numbers or none of them. |
GitHub repositories
This package is not used by any popular GitHub repositories.