1- $targetDirectory = [IO.Path ]::Combine($PSScriptRoot , " .." , " src" , " runtime.win-x64.SciSharp.TensorFlow-Gpu.Redist" )
2-
3- $fileName = " libtensorflow-gpu-windows-x86_64-1.14.0.zip"
4- $zipfile = [IO.Path ]::Combine($PSScriptRoot , " .." , " packages" , $fileName )
5- if (-not (Test-Path $zipfile - PathType Leaf)) {
6- # Create the directory just in case it's actually needed...
7- $path = [IO.Path ]::Combine($PSScriptRoot , " .." , " packages" )
8- New-Item - Path $path - Force - ItemType Directory
9- Write-Host " Downloading libtensorflow gpu for Windows..."
1+ <#
2+ . SYNOPSIS
3+ Copy the native TensorFlow library to enable the packing a nuget to make
4+ them available to TensorFlow.NET
5+
6+ . DESCRIPTION
7+ The TensorFlow libraries are copied for Windows and Linux and it becomes
8+ possible to bundle a meta-package containing them.
9+
10+ . PARAMETER CpuLibraries
11+ Switch indicating if the script should download the CPU or GPU version of the
12+ TensorFlow libraries.
13+ By default the GPU version of the libraries is downloaded.
14+
15+ #>
16+ param (
17+ [switch ] $CpuLibraries = $false
18+ )
19+
20+ function Expand-TarGzFiles {
21+ <#
22+ . SYNOPSIS
23+ Expands the given list of files from the given archive into the given
24+ target directory.
25+
26+ . PARAMETER Archive
27+ Path to the archive that should be considered.
28+
29+ . PARAMETER Files
30+ Files that should be extracted from the archive.
31+
32+ . PARAMETER TargetDirectory
33+ Directory into which the files should be expanded.
34+
35+ #>
36+ param
37+ (
38+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )] [string ] $Archive ,
39+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )] [string []] $Files ,
40+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )] [string ] $TargetDirectory
41+ )
42+
43+ & 7z e $Archive - o" $TargetDirectory "
44+ $TarArchive = Join-Path $TargetDirectory " libtensorflow.tar"
45+
46+ & 7z e $TarArchive $Files - o" $TargetDirectory "
47+ Remove-Item $TarArchive
48+ }
49+
50+ function Expand-ZipFiles {
51+ <#
52+ . SYNOPSIS
53+ Expands the given list of files from the given archive into the given target directory.
54+
55+ . PARAMETER Archive
56+ Path to the archive that should be considered.
57+
58+ . PARAMETER Files
59+ Files that should be extracted from the archive.
60+
61+ . PARAMETER TargetDirectory
62+ Directory into which the files should be expanded.
63+ #>
64+ param (
65+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )] [string ] $Archive ,
66+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )] [string []] $Files ,
67+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )] [string ] $TargetDirectory
68+ )
69+
70+ & 7z e $Archive $Files - o" $TargetDirectory "
71+ }
72+
73+ function Split-ArchiveFromUrl {
74+ <#
75+ . SYNOPSIS
76+ Extracts the archive name out of the given Url.
77+
78+ . PARAMETER ArchiveUrl
79+ Url of the archive that will be downloaded.
80+
81+ #>
82+ param (
83+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )] [string ] $ArchiveUrl
84+ )
85+
86+ $uriParts = $ArchiveUrl.split (" /" )
87+ $ArchivePath = $uriParts [$uriParts.Count - 1 ]
88+
89+ return $ArchivePath
90+ }
91+
92+ function Copy-Archive {
93+ <#
94+ . SYNOPSIS
95+ This function copies the given binary file to the given target location.
96+
97+ . PARAMETER ArchiveUrl
98+ Url where the archive should be downloaded from.
99+
100+ . PARAMETER TargetDirectory
101+ Target directory where the archive should be downloaded.
102+ #>
103+ param (
104+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
105+ [string ] $ArchiveUrl ,
106+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , ValueFromPipelineByPropertyName = $true )]
107+ [string ] $TargetDirectory
108+ )
109+
110+ $ArchiveName = Split-ArchiveFromUrl $ArchiveUrl
111+
112+ $TargetPath = [IO.Path ]::Combine($PSScriptRoot , " .." , " packages" , $ArchiveName )
113+
114+ if (Test-Path $TargetPath - PathType Leaf) {
115+ Write-Error " $TargetPath already exists, please remove to download againg."
116+ return $TargetPath
117+ }
118+
119+ if (-not (Test-Path $TargetDirectory - PathType Container)) {
120+ Write-Host " Creating missing $TargetDirectory "
121+ New-Item - Path $TargetDirectory - ItemType Directory
122+ }
123+ Write-Host " Downloading $ArchiveUrl , this might take a while..."
10124 $wc = New-Object System.Net.WebClient
11- $wc.DownloadFile (" https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.14.0.zip" , $zipfile )
125+ $wc.DownloadFile ($ArchiveUrl , $TargetPath )
126+
127+ return $TargetPath
128+ }
129+
130+ $LinuxGpuArchive = " https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-1.14.0.tar.gz"
131+ $LinuxFiles = @ (" .\libtensorflow.tar" , " .\lib\libtensorflow.so" , " .\lib\libtensorflow.so.1" , " .\lib\libtensorflow.so.1.14.0" , `
132+ " .\lib\libtensorflow_framework.so" , " .\lib\libtensorflow_framework.so.1" , " .\lib\libtensorflow_framework.so.1.14.0" )
133+ $WindowsGpuArchive = " https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-windows-x86_64-1.14.0.zip"
134+ $WindowsFiles = @ (" lib\tensorflow.dll" )
135+ $PackagesDirectory = [IO.Path ]::Combine($PSScriptRoot , " .." , " packages" )
136+
137+
138+ if (-not $CpuLibraries ) {
139+ $WindowsArchive = $WindowsGpuArchive
140+ $LinuxArchive = $LinuxGpuArchive
12141}
13142
14- $libraryName = " tensoflow.dll "
15- $libraryLocation = " lib\tensorflow.dll "
16- $windowsTensorFlow = Join-Path $targetDirectory $libraryName
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
17146
18- if (-not (Test-Path $windowsTensorFlow ))
19- {
20- & 7z e $zipfile $libraryLocation - o" $targetDirectory "
21- }
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
0 commit comments