@@ -31,34 +31,40 @@ public class c_api_util
3131 static object locker = new object ( ) ;
3232 public static void DownloadLibrary ( )
3333 {
34- string dll = $ "{ c_api . TensorFlowLibName } .dll";
35-
36- string runtime = "win-x64" ;
34+ string dll = c_api . TensorFlowLibName ;
35+ string directory = AppDomain . CurrentDomain . BaseDirectory ;
36+ string file = "" ;
37+ string url = "" ;
3738
3839 switch ( Environment . OSVersion . Platform )
3940 {
4041 case PlatformID . Win32NT :
41- runtime = "win-x64" ;
42+ dll = $ "{ dll } .dll";
43+ file = Path . Combine ( directory , "tensorflow.zip" ) ;
44+ break ;
45+ case PlatformID . Unix :
46+ dll = $ "lib{ dll } .so";
47+ file = Path . Combine ( directory , "libtensorflow-cpu-linux-x86_64-1.14.0.tar.gz" ) ;
48+ url = "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.14.0.tar.gz" ;
4249 break ;
4350 default :
4451 throw new RuntimeError ( $ "Unknown OS environment: { Environment . OSVersion . Platform } ") ;
4552 }
4653
47- if ( isDllDownloaded || File . Exists ( Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , dll ) ) )
54+ if ( isDllDownloaded || File . Exists ( $ " { directory } / { dll } " ) )
4855 {
4956 isDllDownloaded = true ;
5057 return ;
5158 }
5259
53- string url = $ "https://github.com/SciSharp/TensorFlow.NET/raw/master/tensorflowlib/runtimes/{ runtime } /native/tensorflow.zip";
5460
5561 lock ( locker )
5662 {
57- if ( ! File . Exists ( "tensorflow.zip" ) )
63+ if ( ! File . Exists ( file ) )
5864 {
5965 var wc = new WebClient ( ) ;
60- Console . WriteLine ( $ "Downloading Tensorflow library...") ;
61- var download = Task . Run ( ( ) => wc . DownloadFile ( url , Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "tensorflow.zip" ) ) ) ;
66+ Console . WriteLine ( $ "Downloading Tensorflow library from { url } ...") ;
67+ var download = Task . Run ( ( ) => wc . DownloadFile ( url , file ) ) ;
6268 while ( ! download . IsCompleted )
6369 {
6470 Thread . Sleep ( 1000 ) ;
@@ -71,7 +77,19 @@ public static void DownloadLibrary()
7177 Console . WriteLine ( $ "Extracting...") ;
7278 var task = Task . Run ( ( ) =>
7379 {
74- ZipFile . ExtractToDirectory ( "tensorflow.zip" , AppDomain . CurrentDomain . BaseDirectory ) ;
80+ switch ( Environment . OSVersion . Platform )
81+ {
82+ case PlatformID . Win32NT :
83+ ZipFile . ExtractToDirectory ( file , directory ) ;
84+ break ;
85+ case PlatformID . Unix :
86+ Util . CmdHelper . Bash ( $ "tar xvzf { file } ./lib/") ;
87+ Util . CmdHelper . Bash ( $ "mv { directory } /lib/* { directory } ") ;
88+ Util . CmdHelper . Bash ( $ "rm -r { directory } /lib") ;
89+ break ;
90+ default :
91+ throw new RuntimeError ( $ "Unknown OS environment: { Environment . OSVersion . Platform } ") ;
92+ }
7593 } ) ;
7694
7795 while ( ! task . IsCompleted )
0 commit comments