Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports .NET Framework #155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ConvNetSharp.Core/ConvNetSharp.Core.Nuget.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
<Version>0.4.14</Version>
Expand Down
3 changes: 2 additions & 1 deletion src/ConvNetSharp.Core/ConvNetSharp.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
15 changes: 9 additions & 6 deletions src/ConvNetSharp.Core/Net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public T GetCostLoss(Volume<T> input, Volume<T> y)
{
this.Forward(input);

if (this.Layers[^1] is ILastLayer<T> lastLayer)
var n = this.Layers.Count;
if (this.Layers[n - 1] is ILastLayer<T> lastLayer)
{
lastLayer.Backward(y, out var loss);
return loss;
Expand Down Expand Up @@ -58,7 +59,8 @@ public int[] GetPrediction()
{
// this is a convenience function for returning the argmax
// prediction, assuming the last layer of the net is a softmax
if (!(this.Layers[^1] is SoftmaxLayer<T> softmaxLayer))
var ln = this.Layers.Count;
if (!(this.Layers[ln - 1] is SoftmaxLayer<T> softmaxLayer))
{
throw new Exception("GetPrediction function assumes softmax as last layer of the net!");
}
Expand Down Expand Up @@ -109,10 +111,11 @@ public void AddLayer(LayerBase<T> layer)

if (this.Layers.Count > 0)
{
inputWidth = this.Layers[^1].OutputWidth;
inputHeight = this.Layers[^1].OutputHeight;
inputDepth = this.Layers[^1].OutputDepth;
lastLayer = this.Layers[^1];
var n = this.Layers.Count;
inputWidth = this.Layers[n - 1].OutputWidth;
inputHeight = this.Layers[n - 1].OutputHeight;
inputDepth = this.Layers[n - 1].OutputDepth;
lastLayer = this.Layers[n - 1];
}
else if (!(layer is InputLayer<T>))
{
Expand Down
5 changes: 3 additions & 2 deletions src/ConvNetSharp.Flow/ConvNetSharp.Flow.Nuget.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
<Version>0.4.14</Version>
Expand Down
5 changes: 3 additions & 2 deletions src/ConvNetSharp.Flow/ConvNetSharp.Flow.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
Expand Down
3 changes: 2 additions & 1 deletion src/ConvNetSharp.Utils/ConvNetSharp.Utils.Nuget.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/ConvNetSharp.Volume.GPU/ConvNetSharp.Volume.GPU.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
Expand Down
29 changes: 21 additions & 8 deletions src/ConvNetSharp.Volume.GPU/Double/Volume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,13 @@ public override void Convolution(Volume<double> filters, int xpad, int ypad, int
result.Shape.Dimensions[1],
result.Shape.Dimensions[0]);

var algo = this._context.CudnnContext.GetConvolutionForwardAlgorithm(
dataDesc, filterDesc,
convolutionDesc, outputDesc,
cudnnConvolutionFwdPreference.PreferFastest, IntPtr.Zero);
var algo = this._context.CudnnContext.FindConvolutionForwardAlgorithm(
dataDesc,
filterDesc,
convolutionDesc,
outputDesc,
1
).First().algo;

var workspaceSize = this._context.CudnnContext.GetConvolutionForwardWorkspaceSize(
dataDesc, filterDesc,
Expand Down Expand Up @@ -373,14 +376,24 @@ public override void Convolution(Volume<double> filters, int xpad, int ypad, int
filters.Shape.Dimensions[1],
filters.Shape.Dimensions[0]);

var filterAlgo = this._context.CudnnContext.GetConvolutionBackwardFilterAlgorithm(dataDesc, dOutputDesc,
convolutionDesc, dfilterDesc, cudnnConvolutionBwdFilterPreference.PreferFastest, IntPtr.Zero);
var filterAlgo = this._context.CudnnContext.FindConvolutionBackwardFilterAlgorithm(
dataDesc,
dOutputDesc,
convolutionDesc,
dfilterDesc,
1
).First().algo;
var filterWorkspaceSize = this._context.CudnnContext.GetConvolutionBackwardFilterWorkspaceSize(dataDesc,
dOutputDesc, convolutionDesc, dfilterDesc, filterAlgo);
filterWorkspaceSize = filterWorkspaceSize == 0 ? new SizeT(1) : filterWorkspaceSize;

var dataAlgo = this._context.CudnnContext.GetConvolutionBackwardDataAlgorithm(filterDesc, dOutputDesc,
convolutionDesc, dDataDesc, cudnnConvolutionBwdDataPreference.PreferFastest, IntPtr.Zero);
var dataAlgo = this._context.CudnnContext.FindConvolutionBackwardDataAlgorithm(
filterDesc,
dOutputDesc,
convolutionDesc,
dDataDesc,
1
).First().algo;
var dataWorkspaceSize = this._context.CudnnContext.GetConvolutionBackwardDataWorkspaceSize(dfilterDesc,
dOutputDesc, convolutionDesc, dDataDesc, dataAlgo);
dataWorkspaceSize = dataWorkspaceSize == 0 ? new SizeT(1) : dataWorkspaceSize;
Expand Down
29 changes: 21 additions & 8 deletions src/ConvNetSharp.Volume.GPU/Single/Volume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,13 @@ public override void Convolution(Volume<float> filters, int xpad, int ypad, int
result.Shape.Dimensions[1],
result.Shape.Dimensions[0]);

var algo = this._context.CudnnContext.GetConvolutionForwardAlgorithm(
dataDesc, filterDesc,
convolutionDesc, outputDesc,
cudnnConvolutionFwdPreference.PreferFastest, IntPtr.Zero);
var algo = this._context.CudnnContext.FindConvolutionForwardAlgorithm(
dataDesc,
filterDesc,
convolutionDesc,
outputDesc,
1
).First().algo;

var workspaceSize = this._context.CudnnContext.GetConvolutionForwardWorkspaceSize(
dataDesc, filterDesc,
Expand Down Expand Up @@ -379,14 +382,24 @@ public override void Convolution(Volume<float> filters, int xpad, int ypad, int
filters.Shape.Dimensions[1],
filters.Shape.Dimensions[0]);

var filterAlgo = this._context.CudnnContext.GetConvolutionBackwardFilterAlgorithm(dataDesc, dOutputDesc,
convolutionDesc, dfilterDesc, cudnnConvolutionBwdFilterPreference.PreferFastest, IntPtr.Zero);
var filterAlgo = this._context.CudnnContext.FindConvolutionBackwardFilterAlgorithm(
dataDesc,
dOutputDesc,
convolutionDesc,
dfilterDesc,
1
).First().algo;
var filterWorkspaceSize = this._context.CudnnContext.GetConvolutionBackwardFilterWorkspaceSize(dataDesc,
dOutputDesc, convolutionDesc, dfilterDesc, filterAlgo);
filterWorkspaceSize = filterWorkspaceSize == 0 ? new SizeT(1) : filterWorkspaceSize;

var dataAlgo = this._context.CudnnContext.GetConvolutionBackwardDataAlgorithm(filterDesc, dOutputDesc,
convolutionDesc, dDataDesc, cudnnConvolutionBwdDataPreference.PreferFastest, IntPtr.Zero);
var dataAlgo = this._context.CudnnContext.FindConvolutionBackwardDataAlgorithm(
filterDesc,
dOutputDesc,
convolutionDesc,
dDataDesc,
1
).First().algo;
var dataWorkspaceSize = this._context.CudnnContext.GetConvolutionBackwardDataWorkspaceSize(dfilterDesc,
dOutputDesc, convolutionDesc, dDataDesc, dataAlgo);
dataWorkspaceSize = dataWorkspaceSize == 0 ? new SizeT(1) : dataWorkspaceSize;
Expand Down
3 changes: 2 additions & 1 deletion src/ConvNetSharp.Volume/ConvNetSharp.Volume.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
Loading