forked from tensorflow/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial release of installation guides for Java, C, and Go.
Updated leftnav_files to provide pointers to new installation guides. Updated landing page (index.md) to distinguish between OS installs and language installs. Change: 151712658
- Loading branch information
1 parent
f169e81
commit e58377e
Showing
5 changed files
with
509 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
# Installing TensorFlow | ||
|
||
We provide installation instructions for the following platforms: | ||
The following guides explain how to install a version of TensorFlow | ||
that enables you to write applications in Python: | ||
|
||
* @{$install_linux$Installing TensorFlow on Ubuntu} | ||
* @{$install_mac$Installing TensorFlow on Mac OS X} | ||
* @{$install_windows$Installing TensorFlow on Windows} | ||
* @{$install_sources$Installing TensorFlow from Sources} | ||
|
||
The following guide explains how to migrate your older TensorFlow | ||
applications to Version 1.0: | ||
Many aspects of the Python TensorFlow API changed from version 0.n to 1.0. | ||
The following guide explains how to migrate older TensorFlow applications | ||
to Version 1.0: | ||
|
||
* @{$migration$Transitioning to TensorFlow 1.0} | ||
|
||
The following guides explain how to install TensorFlow libraries for use in | ||
other programming languages. These APIs are aimed at deploying TensorFlow | ||
models in applications and are not as extensive as the Python APIs. | ||
|
||
* @{$install_java$Installing TensorFlow for Java} | ||
* @{$install_c$Installing TensorFlow for C} | ||
* @{$install_go$Installing TensorFlow for Go} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Installing TensorFlow for C | ||
|
||
TensorFlow provides a C API defined in | ||
[`c_api.h`](https://github.com/tensorflow/tensorflow/tree/master/c/c_api.h), | ||
which is suitable for | ||
[building bindings for other languages](https://www.tensorflow.org/extend/language_bindings). | ||
The API leans towards simplicity and uniformity rather than convenience. | ||
|
||
|
||
## Supported Platforms | ||
|
||
You may install TensorFlow for C on the following operating systems: | ||
|
||
* Linux | ||
* Mac OS X | ||
|
||
|
||
## Installation | ||
|
||
Take the following steps to install the TensorFlow for C library and | ||
enable TensorFlow for C: | ||
|
||
1. Decide whether you will run TensorFlow for C on CPU(s) only or | ||
with the help of GPU(s). To help you decide, read the section | ||
entitled "Determine which TensorFlow to install" in one of the | ||
following guides: | ||
|
||
* @{$install_linux#determine_which_tensorflow_to_install$Installing TensorFlow on Linux} | ||
* @{$install_mac#determine_which_tensorflow_to_install$Installing TensorFlow on Mac OS} | ||
|
||
2. Download and extract the TensorFlow C library into `/usr/local/lib` by | ||
invoking the following shell commands: | ||
|
||
TF_TYPE="cpu" # Change to "gpu" for GPU support | ||
OS="linux" # Change to "darwin" for Mac OS | ||
TARGET_DIRECTORY="/usr/local" | ||
curl -L \ | ||
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-${OS}-x86_64-1.1.0.tar.gz" | | ||
sudo tar -C $TARGET_DIRECTORY -xz | ||
|
||
The `tar` command extracts the TensorFlow C library into the `lib` | ||
subdirectory of `TARGET_DIRECTORY`. For example, specifying `/usr/local` | ||
as `TARGET_DIRECTORY` causes `tar` to extract the TensorFlow C library | ||
into `/usr/local/lib`. | ||
|
||
If you'd prefer to extract the library into a different directory, | ||
adjust `TARGET_DIRECTORY` accordingly. | ||
|
||
3. In Step 2, if you specified a system directory (for example, `/usr/local`) | ||
as the `TARGET_DIRECTORY`, then run `ldconfig` to configure the linker. | ||
For example: | ||
|
||
<pre><b>sudo ldconfig</b></pre> | ||
|
||
If you assigned a `TARGET_DIRECTORY` other than a system | ||
directory (for example, `~/mydir`), then you must append the extraction | ||
directory (for example, `~/mydir/lib`) to two environment variables. | ||
For example: | ||
|
||
<pre> <b>export LIBRARY_PATH=$LIBRARY_PATH:~/mydir/lib</b> # For both Linux and Mac OS X | ||
<b>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/mydir/lib</b> # For Linux only | ||
<b>export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:~/mydir/lib</b> # For Mac OS X only</pre> | ||
|
||
|
||
|
||
## Validate your installation | ||
|
||
After installing TensorFlow for C, enter the following code into a file named | ||
`hello_tf.c`: | ||
|
||
```c | ||
#include <stdio.h> | ||
#include <tensorflow/c/c_api.h> | ||
|
||
int main() { | ||
printf(“Hello from TensorFlow C library version %s\n”, TF_Version()); | ||
return 0; | ||
} | ||
``` | ||
|
||
### Build and Run | ||
|
||
Build `hello_tf.c` by invoking the following command: | ||
|
||
|
||
<pre><b>gcc hello_tf.c</b></pre> | ||
|
||
|
||
Running the resulting executable should output the following message: | ||
|
||
|
||
<pre><b>a.out</b> | ||
Hello from TensorFlow C library version <i>number</i></pre> | ||
|
||
|
||
### Troubleshooting | ||
|
||
If building the program fails, the most likely culprit is that `gcc` cannot | ||
find the TensorFlow C library. One way to fix this problem is to specify | ||
the `-I` and `-L` options to `gcc`. For example, if the `TARGET_LIBRARY` | ||
was `/usr/local`, you would invoke `gcc` as follows: | ||
|
||
<pre><b>gcc -I/usr/local/include -L/usr/local/lib hello_tf.c -ltensorflow</b></pre> | ||
|
||
If executing `a.out` fails, ask yourself the following questions: | ||
|
||
* Did the program build without error? | ||
* Have you assigned the correct directory to the environment variables | ||
noted in Step 3 of [Installation](#installation)? | ||
* Did you export those environment variables? | ||
|
||
If you are still seeing build or execution error messages, search (or post to) | ||
[StackOverflow](www.stackoverflow.com/questions/tagged/tensorflow) for | ||
possible solutions. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# Installing TensorFlow for Go | ||
|
||
TensorFlow provides APIs for use in Go programs. These APIs are particularly | ||
well-suited to loading models created in Python and executing them within | ||
a Go application. This guide explains how to install and set up the | ||
[TensorFlow Go package](https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go). | ||
|
||
**WARNING:** The TensorFlow Go API is *not* covered by the TensorFlow | ||
[API stability guarantees](https://www.tensorflow.org/programmers_guide/version_semantics). | ||
|
||
|
||
## Supported Platforms | ||
|
||
You may install TensorFlow for Go on the following operating systems: | ||
|
||
* Linux | ||
* Mac OS X | ||
|
||
|
||
## Installation | ||
|
||
TensorFlow for Go depends on the TensorFlow C library. Take the following | ||
steps to install this library and enable TensorFlow for Go: | ||
|
||
1. Decide whether you will run TensorFlow for Go on CPU(s) only or with | ||
the help of GPU(s). To help you decide, read the section entitled | ||
"Determine which TensorFlow to install" in one of the following guides: | ||
|
||
* @{$install_linux#determine_which_tensorflow_to_install$Installing TensorFlow on Linux} | ||
* @{$install_mac#determine_which_tensorflow_to_install$Installing TensorFlow on Mac OS} | ||
|
||
2. Download and extract the TensorFlow C library into `/usr/local/lib` by | ||
invoking the following shell commands: | ||
|
||
TF_TYPE="cpu" # Change to "gpu" for GPU support | ||
TARGET_DIRECTORY='/usr/local' | ||
curl -L \ | ||
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-$(go env GOOS)-x86_64-1.1.0.tar.gz" | | ||
sudo tar -C $TARGET_DIRECTORY -xz | ||
|
||
The `tar` command extracts the TensorFlow C library into the `lib` | ||
subdirectory of `TARGET_DIRECTORY`. For example, specifying `/usr/local` | ||
as `TARGET_DIRECTORY` causes `tar` to extract the TensorFlow C library | ||
into `/usr/local/lib`. | ||
|
||
If you'd prefer to extract the library into a different directory, | ||
adjust `TARGET_DIRECTORY` accordingly. | ||
|
||
3. In Step 2, if you specified a system directory (for example, `/usr/local`) | ||
as the `TARGET_DIRECTORY`, then run `ldconfig` to configure the linker. | ||
For example: | ||
|
||
<pre><b>sudo ldconfig</b></pre> | ||
|
||
If you assigned a `TARGET_DIRECTORY` other than a system | ||
directory (for example, `~/mydir`), then you must append the extraction | ||
directory (for example, `~/mydir/lib`) to two environment variables | ||
as follows: | ||
|
||
<pre> <b>export LIBRARY_PATH=$LIBRARY_PATH:~/mydir/lib</b> # For both Linux and Mac OS X | ||
<b>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/mydir/lib</b> # For Linux only | ||
<b>export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:~/mydir/lib</b> # For Mac OS X only</pre> | ||
|
||
4. Now that the TensorFlow C library is installed, invoke `go get` as follows | ||
to download the appropriate packages and their dependencies: | ||
|
||
<pre><b>go get github.com/tensorflow/tensorflow/tensorflow/go</b></pre> | ||
|
||
5. Invoke `go test` as follows to validate the TensorFlow for Go | ||
installation: | ||
|
||
<pre><b>go test github.com/tensorflow/tensorflow/tensorflow/go</b></pre> | ||
|
||
If `go get` or `go test` generate error messages, search (or post to) | ||
[StackOverflow](http://www.stackoverflow.com/questions/tagged/tensorflow) | ||
for possible solutions. | ||
|
||
|
||
## Hello World | ||
|
||
After installing TensorFlow for Go, enter the following code into a | ||
file named `hello_tf.go`: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
tf "github.com/tensorflow/tensorflow/tensorflow/go" | ||
"github.com/tensorflow/tensorflow/tensorflow/go/op" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
// Construct a graph with an operation that produces a string constant. | ||
s := op.NewScope() | ||
c := op.Const(s, "Hello from TensorFlow version " + tf.Version()) | ||
graph, err := s.Finalize() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Execute the graph in a session. | ||
sess, err := tf.NewSession(graph, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
output, err := sess.Run(nil, []tf.Output{c}, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(output[0].Value()) | ||
} | ||
``` | ||
|
||
For a more advanced example of TensorFlow in Go, look at the | ||
[example in the API documentation](https://godoc.org/github.com/tensorflow/tensorflow/tensorflow/go#ex-package), | ||
which uses a pre-trained TensorFlow model to label contents of an image. | ||
|
||
|
||
### Running | ||
|
||
Run `hello_tf.go` by invoking the following command: | ||
|
||
<pre><b>go run hello_tf.go</b> | ||
Hello from TensorFlow version <i>number</i></pre> | ||
|
||
The program might also generate multiple warning messages of the | ||
following form, which you can ignore: | ||
|
||
<pre>W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library | ||
wasn't compiled to use *Type* instructions, but these are available on your | ||
machine and could speed up CPU computations.</pre> | ||
|
||
|
||
## Building from source code | ||
|
||
TensorFlow is open-source. You may build TensorFlow for Go from the | ||
TensorFlow source code by following the instructions in a | ||
[separate document](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/go/README.md). |
Oops, something went wrong.