@@ -13,10 +13,81 @@ kinks and TODO-items that I left while I was doing the work.
1313My work-in-progress API documentation [ current API
1414documentation] ( https://migueldeicaza.github.io/TensorFlowSharp/ ) .
1515
16- # Getting Started
16+ # Using TensorFlowSharp
1717
18- You can either use the TensorFlow C-library release binaries, or build your own
19- from source.
18+ ## Installation
19+
20+ The easiest way to get started is to use the NuGet package for
21+ TensorFlowSharp which contains both the .NET API as well as the
22+ native libraries for 64-bit Linux, Mac and Windows using the CPU backend.
23+
24+ You can install using NuGet like this:
25+
26+ ```
27+ nuget install TensorFlowSharp
28+ ```
29+
30+ Or select it from the NuGet packages UI on Visual Studio.
31+
32+ Alternatively, you can [ download it] ( https://www.nuget.org/api/v2/package/TensorFlowSharp/0.96.0 ) directly.
33+
34+ ## Using TensorFlowSharp
35+
36+ Your best source of information right now are the SampleTest that
37+ exercises various APIs of TensorFlowSharp, or the stand-alone samples
38+ located in "Examples".
39+
40+ This API binding is closer design-wise to the Java and Go bindings
41+ which use explicit TensorFlow graphs and sessions. Your application
42+ will typically create a graph (TFGraph) and setup the operations
43+ there, then create a session from it (TFSession), then use the session
44+ runner to setup inputs and outputs and execute the pipeline.
45+
46+ Something like this:
47+
48+ ```
49+ var graph = new TFGraph ();
50+ graph.Import (File.ReadAllBytes ("MySavedModel");
51+ var session = new TFSession (graph);
52+ var runner = session.GetRunner ();
53+ runner.AddInput (graph ["input"] [0], tensor);
54+ runner.Fetch (graph ["output"] [0]);
55+
56+ var output = runner.Run ();
57+
58+ // Fethc the results from output:
59+ TFTensor result = output [0];
60+ ```
61+
62+ In scenarios where you do not need to setup the graph independently,
63+ the session will create one for you. The following example shows how
64+ to abuse TensorFlow to compute the addition of two numbers:
65+
66+ ```
67+ var s = new TFSession ();
68+ var g = s.Graph;
69+
70+ var a = g.Const (2);
71+ var b = g.Const (3);
72+ Console.WriteLine ("a=2 b=3");
73+
74+ // Add two constants
75+ var results = s.GetRunner ().Run (g.Add (a, b));
76+ var val = results [0].GetValue ();
77+ Console.WriteLine ("a+b={0}", val);
78+
79+ // Multiply two constants
80+ results = s.GetRunner ().Run (g.Mul (a, b));
81+ Console.WriteLine ("a*b={0}", results [0].GetValue ());
82+ ```
83+
84+ # Working on TensorFlowSharp
85+
86+ TensorFlowSharp are bindings to the native TensorFlow library.
87+
88+ You can either use the TensorFlow C-library release binaries, or build
89+ your own from source. Here are some pre-built TensorFlow binaries you
90+ can use for each platform:
2091
2192- Linux
2293 - CPU-only: https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-1.1.0.tar.gz
@@ -34,16 +105,10 @@ Once you do that, you need to open the solution file on the top
34105level directory and build. This will produce both the TensorFlowSharp
35106library as well as compile the tests and samples.
36107
37- # Work in Progress
38-
39- These instructions reflect what you need to get up and running with the
40- current code as I am working on it. In the long-term, we will just have
41- NuGet packages that eliminate all the manual steps required here.
42-
43- ## Building your own version
108+ ## Building your own native TensorFlow library
44109
45110To build the TensorFlow C library from source,
46- [ try this ] ( https://github.com/tensorflow/tensorflow/blob/master/tensorflow/go/README.md#building-the-tensorflow-c-library-from-source ) .
111+ [ follow these instructions ] ( https://github.com/tensorflow/tensorflow/blob/master/tensorflow/go/README.md#building-the-tensorflow-c-library-from-source ) .
47112
48113This includes checking out the Tensorflow sources, installing Bazel,
49114and building the core.
@@ -83,9 +148,8 @@ sudo cp bazel-bin/tensorflow/libtensorflow.so /usr/local/lib/libtensorflow.dylib
83148
84149## Running the test
85150
86- I am currently using Xamarin Studio on a Mac to do the development, but this
87- should work on Windows with VS and Linux with MonoDevelop, there is nothing
88- Xamarin specific here.
151+ I am currently using Visual Studio for Mac to do the development, but this
152+ should work on Windows with VS and Linux with MonoDevelop.
89153
90154Before the solution will run you will need the shared library generated to
91155be on a location accessibly by the Mono runtime (for example /usr/local/lib).
@@ -98,9 +162,7 @@ Tensorflow is a 64-bit library, so you will need to use a 64-bit Mono to run,
98162at home (where I am doing this work), I have a copy of 64-bit Mono on /mono,
99163so you will want to set that in your project configuration, to do this:
100164
101- Open the project options (double click on the "SampleTest" project), then
102- select Run/Default, go to the "Advanced" tab, and select "Execute in .NET runtime"
103- and make sure that you select one that is 64-bit enabled.
165+ Ensure that your Build/Compiler settings set "Platform Target" to "x64".
104166
105167Open the solution file in the top directory, and when you hit run, this will
106168run the API test.
@@ -122,16 +184,12 @@ https://github.com/tensorflow/models
122184
123185### Packaging
124186
125- x86: It is not clear to me how to distribute the native libtensorflow to users, as
126- it is designed to be compiled for your host system. I would like to figure out
127- how we can distribute packages that have been compiled with the optimal set of
128- optimizations for users to consume.
129-
130187Mobile: we need to package the library for consumption on Android and iOS.
131188
132- ### NuGet Package
189+ ### Documentation Styling
133190
134- Would love to have a NuGet package for all platforms.
191+ The API documentation has not been styled, I am using the barebones template
192+ for documentation, and it can use some work.
135193
136194### Issues
137195
0 commit comments