Skip to content

Commit 1546b4a

Browse files
committed
Add SciSharp.TensorFlow-Cpu.Redist nuget project.
This project can be used to generate a nuget holding tensorflow cpu libraries for windows and linux runtimes. The Copy-NativeTensorFlowLibs.ps1 script can be used to download all the libraries from Google. The examples have been updated to use this nuget to check that things are working. (Make sure to update your package source to have the packages directory in your nuget source before trying this at home).
1 parent 6f39b48 commit 1546b4a

7 files changed

Lines changed: 207 additions & 14 deletions

File tree

TensorFlow.NET.sln

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ EndProject
2222
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowDatasets", "src\TensorFlowDatasets\TensorFlowDatasets.csproj", "{DF151A51-E9FD-41BD-B0F4-08A743755D44}"
2323
EndProject
2424
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Examples.GPU", "test\TensorFlowNET.Examples\TensorFlowNET.Examples.GPU.csproj", "{6F6B3382-8F87-4CD9-BF87-C81D5405685A}"
25+
EndProject
2526
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{EA9A238E-B93F-4809-AB3D-339B2990FBFF}"
2627
ProjectSection(SolutionItems) = preProject
2728
scripts\Copy-NativeTensorFlowLibs.ps1 = scripts\Copy-NativeTensorFlowLibs.ps1
@@ -33,6 +34,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SciSharp.TensorFlow-Gpu.Red
3334
EndProject
3435
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist", "src\runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist\runtime.linux-x64.SciSharp.TensorFlow-Gpu.Redist.csproj", "{E26AA660-F734-444C-A982-3F19C2AF8829}"
3536
EndProject
37+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "runtime.win-x64.SciSharp.TensorFlow-Cpu.Redist", "src\runtime.win-x64.SciSharp.TensorFlow-Cpu.Redist\runtime.win-x64.SciSharp.TensorFlow-Cpu.Redist.csproj", "{54ED61EB-DE05-4052-A92D-15B26478E700}"
38+
EndProject
39+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "runtime.linux-x64.SciSharp.TensorFlow-Cpu.Redist", "src\runtime.linux-x64.SciSharp.TensorFlow-Cpu.Redist\runtime.linux-x64.SciSharp.TensorFlow-Cpu.Redist.csproj", "{977C27F4-2196-4CA4-9A79-80A0F72DBB11}"
40+
EndProject
41+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SciSharp.TensorFlow-Cpu.Redist", "src\SciSharp.TensorFlow-Cpu.Redist\SciSharp.TensorFlow-Cpu.Redist.csproj", "{6AD4A403-2E82-4795-AC61-50D8B271CFC8}"
42+
EndProject
3643
Global
3744
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3845
Debug|Any CPU = Debug|Any CPU
@@ -91,6 +98,18 @@ Global
9198
{E26AA660-F734-444C-A982-3F19C2AF8829}.Debug|Any CPU.Build.0 = Debug|Any CPU
9299
{E26AA660-F734-444C-A982-3F19C2AF8829}.Release|Any CPU.ActiveCfg = Release|Any CPU
93100
{E26AA660-F734-444C-A982-3F19C2AF8829}.Release|Any CPU.Build.0 = Release|Any CPU
101+
{54ED61EB-DE05-4052-A92D-15B26478E700}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
102+
{54ED61EB-DE05-4052-A92D-15B26478E700}.Debug|Any CPU.Build.0 = Debug|Any CPU
103+
{54ED61EB-DE05-4052-A92D-15B26478E700}.Release|Any CPU.ActiveCfg = Release|Any CPU
104+
{54ED61EB-DE05-4052-A92D-15B26478E700}.Release|Any CPU.Build.0 = Release|Any CPU
105+
{977C27F4-2196-4CA4-9A79-80A0F72DBB11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
106+
{977C27F4-2196-4CA4-9A79-80A0F72DBB11}.Debug|Any CPU.Build.0 = Debug|Any CPU
107+
{977C27F4-2196-4CA4-9A79-80A0F72DBB11}.Release|Any CPU.ActiveCfg = Release|Any CPU
108+
{977C27F4-2196-4CA4-9A79-80A0F72DBB11}.Release|Any CPU.Build.0 = Release|Any CPU
109+
{6AD4A403-2E82-4795-AC61-50D8B271CFC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
110+
{6AD4A403-2E82-4795-AC61-50D8B271CFC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
111+
{6AD4A403-2E82-4795-AC61-50D8B271CFC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
112+
{6AD4A403-2E82-4795-AC61-50D8B271CFC8}.Release|Any CPU.Build.0 = Release|Any CPU
94113
EndGlobalSection
95114
GlobalSection(SolutionProperties) = preSolution
96115
HideSolutionNode = FALSE

scripts/Copy-NativeTensorFlowLibs.ps1

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@
77
The TensorFlow libraries are copied for Windows and Linux and it becomes
88
possible to bundle a meta-package containing them.
99
10-
.PARAMETER CpuLibraries
11-
Switch indicating if the script should download the CPU or GPU version of the
10+
.PARAMETER SkipCpuLibraries
11+
Setting this to true skips the downloading of the CPU version of the
1212
TensorFlow libraries.
13-
By default the GPU version of the libraries is downloaded.
13+
By default the CPU version of the libraries are downloaded and put in the
14+
relevant projects.
15+
16+
.PARAMETER SkipGpuLibraries
17+
Setting this to tru skips the downloading of the GPU version of the
18+
TensorFlow libraries.
19+
By default the GPU version of the libraries are downloaded and put in the
20+
releavant projects.
1421
1522
#>
1623
param(
17-
[switch] $CpuLibraries = $false
24+
[switch] $SkipCpuLibraries = $false,
25+
[switch] $SkipGpuLibraries = $false
1826
)
1927

2028
function Expand-TarGzFiles {
@@ -128,22 +136,32 @@ function Copy-Archive {
128136
}
129137

130138
$LinuxGpuArchive = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.14.0.tar.gz"
139+
$LinuxCpuArchive = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.14.0.tar.gz"
131140
$LinuxFiles = @(".\libtensorflow.tar", ".\lib\libtensorflow.so", ".\lib\libtensorflow.so.1", ".\lib\libtensorflow.so.1.14.0", `
132141
".\lib\libtensorflow_framework.so", ".\lib\libtensorflow_framework.so.1", ".\lib\libtensorflow_framework.so.1.14.0")
133142
$WindowsGpuArchive = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.14.0.zip"
143+
$WindowsCpuArchive = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-1.14.0.zip"
134144
$WindowsFiles = @("lib\tensorflow.dll")
135145
$PackagesDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "packages")
136146

137147

138-
if (-not $CpuLibraries) {
139-
$WindowsArchive = $WindowsGpuArchive
140-
$LinuxArchive = $LinuxGpuArchive
148+
if (-not $SkipGpuLibraries) {
149+
$Archive = Copy-Archive -ArchiveUrl $WindowsGpuArchive -TargetDirectory $PackagesDirectory
150+
$TargetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.win-x64.SciSharp.TensorFlow-Gpu.Redist")
151+
Expand-ZipFiles $Archive $WindowsFiles $TargetDirectory
152+
153+
$Archive = Copy-Archive -ArchiveUrl $LinuxGpuArchive -TargetDirectory $PackagesDirectory
154+
$TargetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist")
155+
Expand-TarGzFiles $Archive $LinuxFiles $TargetDirectory
141156
}
142157

143-
$Archive = Copy-Archive -ArchiveUrl $WindowsArchive -TargetDirectory $PackagesDirectory
144-
$TargetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.win-x64.SciSharp.TensorFlow-Gpu.Redist")
145-
Expand-ZipFiles $Archive $WindowsFiles $TargetDirectory
158+
if (-not $SkipCpuLibraries) {
159+
$Archive = Copy-Archive -ArchiveUrl $WindowsCpuArchive -TargetDirectory $PackagesDirectory
160+
$TargetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.win-x64.SciSharp.TensorFlow-Cpu.Redist")
161+
Expand-ZipFiles $Archive $WindowsFiles $TargetDirectory
162+
163+
$Archive = Copy-Archive -ArchiveUrl $LinuxCpuArchive -TargetDirectory $PackagesDirectory
164+
$TargetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.linux-x64.SciSharp.Tensorflow-Cpu.Redist")
165+
Expand-TarGzFiles $Archive $LinuxFiles $TargetDirectory
166+
}
146167

147-
$Archive = Copy-Archive -ArchiveUrl $LinuxArchive -TargetDirectory $PackagesDirectory
148-
$TargetDirectory = [IO.Path]::Combine($PSScriptRoot, "..", "src", "runtime.linux-x64.SciSharp.Tensorflow-Gpu.Redist")
149-
Expand-TarGzFiles $Archive $LinuxFiles $TargetDirectory
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
6+
<AssemblyName>SciSharp.Tensorflow-Cpu.Redist</AssemblyName>
7+
8+
<PackageId>SciSharp.Tensorflow-Cpu.Redist</PackageId>
9+
<Version>1.0.0</Version>
10+
<Authors>SciSharp team</Authors>
11+
<Company>SciSharp STACK</Company>
12+
<RepositoryUrl>https://github.com/SciSharp/TensorFlow.NET</RepositoryUrl>
13+
<RepositoryType>git</RepositoryType>
14+
<Description>
15+
Meta-package for GPU Tensoflow library runtime distribution.
16+
Libraries can be directly downloaded from https://storage.googleapis.com/tensorflow/libtensorflow/
17+
</Description>
18+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
19+
20+
<PackageProjectUrl>https://github.com/SciSharp/TensorFlow.NET</PackageProjectUrl>
21+
<PackageTags>native;tensorflow;machine-learning;ML</PackageTags>
22+
<PackageOutputPath>../../packages</PackageOutputPath>
23+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
24+
25+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
26+
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
27+
<IncludeBuildOutput>false</IncludeBuildOutput>
28+
</PropertyGroup>
29+
30+
<!-- Need to add some dependencies so Meta-Project will pull runtime Project(s) -->
31+
<Target Name="ValidateRuntimePack" BeforeTargets="GenerateNuspec">
32+
<ItemGroup>
33+
<RuntimeLinux Include="../../packages/runtime.linux-x64.SciSharp.Tensorflow-Cpu.Redist.*.nupkg" />
34+
<RuntimeWin Include="../../packages/runtime.win-x64.SciSharp.Tensorflow-Cpu.Redist.*.nupkg" />
35+
</ItemGroup>
36+
<Message Importance="high" Text="Package runtime.linux-x64.SciSharp.Tensorflow-Cpu.Redist: found" Condition="Exists('@(RuntimeLinux)')" />
37+
<Message Importance="high" Text="Package runtime.linux-x64.SciSharp.Tensorflow-Cpu.Redist: not found" Condition="!Exists('@(RuntimeLinux)')" />
38+
<Message Importance="high" Text="Package runtime.win-x64.SciSharp.Tensorflow-Cpu.Redist: found" Condition="Exists('@(RuntimeWin)')" />
39+
<Message Importance="high" Text="Package runtime.win-x64.SciSharp.Tensorflow-Cpu.Redist: not found" Condition="!Exists('@(RuntimeWin)')" />
40+
<Error Text="You must locally 'dotnet pack' at least one runtime.{rid}.SciSharp.Tensorflow-Cpu.Redist project." Condition="!Exists('@(RuntimeLinux)') AND !Exists('@(RuntimeWin)')" />
41+
</Target>
42+
43+
<PropertyGroup>
44+
<RestoreSources>../../packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
45+
</PropertyGroup>
46+
<ItemGroup Condition="Exists('../../packages/runtime.linux-x64.SciSharp.Tensorflow-Cpu.Redist.1.0.0.nupkg')">
47+
<PackageReference Include="runtime.linux-x64.SciSharp.Tensorflow-Cpu.Redist" Version="1.0.0" />
48+
</ItemGroup>
49+
<ItemGroup Condition="Exists('../../packages/runtime.win-x64.SciSharp.Tensorflow-Cpu.Redist.1.0.0.nupkg')">
50+
<PackageReference Include="runtime.win-x64.SciSharp.Tensorflow-Cpu.Redist" Version="1.0.0" />
51+
</ItemGroup>
52+
53+
<ItemGroup>
54+
<RuntimeLinux Include="../../packages/runtime.linux-x64.SciSharp.Tensorflow-Cpu.Redist.*.nupkg" />
55+
<RuntimeWin Include="../../packages/runtime.win-x64.SciSharp.Tensorflow-Cpu.Redist.*.nupkg" />
56+
<Content Include="runtime.json" Condition="Exists('@(RuntimeLinux)') AND Exists('@(RuntimeWin)')">
57+
<PackagePath>runtime.json</PackagePath>
58+
<Pack>true</Pack>
59+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
60+
</Content>
61+
</ItemGroup>
62+
63+
</Project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"runtimes": {
3+
"linux-x64": {
4+
"SciSharp.TensorFlow-Gpu.Redist": {
5+
"runtime.linux-x64.SciSharp.Tensorflow-Cpu.Redist": "1.0.0"
6+
}
7+
},
8+
"win-x64": {
9+
"SciSharp.TensorFlow-Gpu.Redist": {
10+
"runtime.win-x64.SciSharp.Tensorflow-Cpu.Redist": "1.0.0"
11+
}
12+
}
13+
}
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
6+
<AssemblyName>SciSharp.Tensorflow-Cpu.Redist</AssemblyName>
7+
8+
<PackageId>runtime.linux-x64.SciSharp.Tensorflow-Cpu.Redist</PackageId>
9+
<Version>1.0.0</Version>
10+
<Authors>SciSharp team</Authors>
11+
<Company>SciSharp STACK</Company>
12+
<RepositoryUrl>https://github.com/SciSharp/TensorFlow.NET</RepositoryUrl>
13+
<RepositoryType>git</RepositoryType>
14+
<Description>
15+
Distribution of the Linux CPU Tensoflow library.
16+
The libraries can be directly downloaded from https://storage.googleapis.com/tensorflow/libtensorflow/
17+
</Description>
18+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
19+
20+
<PackageProjectUrl>https://github.com/SciSharp/TensorFlow.NET</PackageProjectUrl>
21+
<PackageTags>native;tensorflow;machine-learning;ML</PackageTags>
22+
<PackageOutputPath>../../packages</PackageOutputPath>
23+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
24+
25+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
26+
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
27+
<IncludeBuildOutput>false</IncludeBuildOutput>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<!-- All dlls will be dropped in a folder available through DllImport.-->
32+
<Content Include="*.so.*">
33+
<PackagePath>runtimes/$(RuntimeIdentifier)/native/%(Filename)%(Extension)</PackagePath>
34+
<Pack>true</Pack>
35+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
36+
</Content>
37+
</ItemGroup>
38+
39+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
6+
<AssemblyName>SciSharp.Tensorflow-Cpu.Redist</AssemblyName>
7+
8+
<PackageId>runtime.win-x64.SciSharp.Tensorflow-Cpu.Redist</PackageId>
9+
<Version>1.0.0</Version>
10+
<Authors>SciSharp team</Authors>
11+
<Company>SciSharp STACK</Company>
12+
<RepositoryUrl>https://github.com/SciSharp/TensorFlow.NET</RepositoryUrl>
13+
<RepositoryType>git</RepositoryType>
14+
<Description>
15+
Distribution of the windows GPU Tensoflow library.
16+
The libraries can be directly downloaded from https://storage.googleapis.com/tensorflow/libtensorflow/
17+
</Description>
18+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
19+
20+
<PackageProjectUrl>https://github.com/SciSharp/TensorFlow.NET</PackageProjectUrl>
21+
<PackageTags>native;tensorflow;machine-learning;ML</PackageTags>
22+
<PackageOutputPath>../../packages</PackageOutputPath>
23+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
24+
25+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
26+
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
27+
<IncludeBuildOutput>false</IncludeBuildOutput>
28+
</PropertyGroup>
29+
30+
<ItemGroup>
31+
<!-- All dlls will be dropped in a folder available through DllImport.-->
32+
<Content Include="*.dll">
33+
<PackagePath>runtimes/$(RuntimeIdentifier)/native/%(Filename)%(Extension)</PackagePath>
34+
<Pack>true</Pack>
35+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
36+
</Content>
37+
</ItemGroup>
38+
39+
</Project>

test/TensorFlowNET.Examples/TensorFlowNET.Examples.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<ItemGroup>
1414
<PackageReference Include="Colorful.Console" Version="1.2.9" />
1515
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
16-
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="1.14.0" />
16+
<PackageReference Include="SciSharp.TensorFlow-Cpu.Redist" Version="1.0.0" />
17+
<!--<PackageReference Include="SciSharp.TensorFlow.Redist" Version="1.14.0" />-->
1718
<PackageReference Include="SharpZipLib" Version="1.1.0" />
1819
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
1920
</ItemGroup>

0 commit comments

Comments
 (0)