1
- #TensorFlow Rust
1
+ # < img alt = " TensorFlow " src = " https://www.tensorflow.org/images/tf_logo_transp.png " width = " 170 " /> Rust Binding
2
2
[ ![ Version] ( https://img.shields.io/crates/v/tensorflow.svg )] ( https://crates.io/crates/tensorflow )
3
3
[ ![ Status] ( https://travis-ci.org/tensorflow/rust.svg?branch=master )] ( https://travis-ci.org/tensorflow/rust )
4
4
5
5
TensorFlow Rust provides idiomatic [ Rust] ( https://www.rust-lang.org ) language
6
6
bindings for [ TensorFlow] ( http://tensorflow.org ) .
7
7
8
- This project is still under active development and not guaranteed to have a
9
- stable API. This is especially true because the TensorFlow C API used by this
10
- project has not yet stabilized .
8
+ ** Notice: ** This project is still under active development and not guaranteed to have a
9
+ stable API. This is especially true because the underlying TensorFlow C API has not yet
10
+ been stabilized as well .
11
11
12
- ## Using
12
+ * [ Documentation] ( https://tensorflow.github.io/rust/tensorflow/ )
13
+ * [ TensorFlow website] ( http://tensorflow.org )
14
+ * [ TensorFlow GitHub page] ( https://github.com/tensorflow/tensorflow )
15
+
16
+ ## Getting Started
17
+ Since this crate depends on the TensorFlow C API, it needs to be compiled first. This crate will
18
+ automatically compile TensorFlow for you, but it is also possible to manually install TensorFlow
19
+ and the crate will pick it up accordingly.
20
+
21
+ ### Prerequisites
22
+ The following dependencies are needed to compile and build this crate (assuming TensorFlow itself
23
+ should also be compiled transparently):
24
+
25
+ - git
26
+ - [ bazel] ( https://bazel.build/ )
27
+ - Python Dependencies ` numpy ` , ` dev ` , ` pip ` and ` wheel `
28
+ - Optionally, CUDA packages to support GPU-based processing
13
29
14
- If you only wish to use TensorFlow within your own project, simply include
15
- ` tensorflow = "*" ` in your ` Cargo.toml ` file. If the TensorFlow library is
16
- not already installed on your computer in a place it can be found, you will
17
- need the requirements listed in "Automatically Building Tensorflow" below,
18
- and Cargo will build the library for you.
30
+ The TensorFlow website provides detailed instructions on how to obtain and install said dependencies,
31
+ so if you are unsure please [ check out the docs] ( https://www.tensorflow.org/install/install_sources )
32
+ for further details.
19
33
20
- ## Building
34
+ ### Usage
35
+ Add this to your ` Cargo.toml ` :
21
36
22
- If you only intend to use TensorFlow from within Rust, then you don't need to
23
- build TensorFlow manually and can follow the automatic steps. If you do need to
24
- use TensorFlow outside of Rust, the manual steps will provide you with a
25
- TensorFlow header file and shared library that can be used by other languages.
37
+ ``` toml
38
+ [ dependencies ]
39
+ tensorflow = " 0.3 "
40
+ ```
26
41
27
- ### Automatically building TensorFlow
42
+ and this to your crate root:
43
+
44
+ ``` rust
45
+ extern crate tensorflow;
46
+ ```
28
47
29
- Install [ SWIG] ( http://www.swig.org ) and [ NumPy] ( http://www.numpy.org ) . The
30
- version from your distro's package manager should be fine for these two. Also
31
- install [ Bazel] ( http://bazel.io/docs/install.html ) , which you may need to do
32
- from source.
33
48
Then run ` cargo build -j 1 ` . Since TensorFlow is built during this process, and
34
49
the TensorFlow build is very memory intensive, we recommend using the ` -j 1 `
35
50
flag which tells cargo to use only one task, which in turn tells TensorFlow to
36
51
build with only on task. Of course, if you have a lot of RAM, you can use a
37
52
higher value.
53
+
38
54
To include the especially unstable API (which is currently the ` expr ` module),
39
55
use ` --features tensorflow_unstable ` .
40
56
41
- ### Manually building TensorFlow
57
+ For now, please see the [ Examples] ( https://github.com/tensorflow/rust/tree/master/examples ) for more
58
+ details on how to use this binding.
42
59
43
- Install [ TensorFlow from source] ( https://www.tensorflow.org/versions/master/get_started/os_setup.html#source ) .
60
+ ## Manual TensorFlow Compilation
61
+ If you don't want to build TensorFlow after every ` cargo clean ` or you want to work against
62
+ unreleased/unsupported TensorFlow versions, manual compilation is the way to go.
63
+
64
+ See [ TensorFlow from source] ( https://www.tensorflow.org/install/install_sources ) first.
44
65
The Python/pip steps are not necessary, but building ` tensorflow:libtensorflow.so ` is.
45
66
46
67
In short:
47
68
48
69
1 . Install [ SWIG] ( http://www.swig.org ) and [ NumPy] ( http://www.numpy.org ) . The
49
70
version from your distro's package manager should be fine for these two.
50
- 1 . [ Install Bazel] ( http://bazel.io/docs/install.html ) , which you may need to do
71
+ 2 . [ Install Bazel] ( http://bazel.io/docs/install.html ) , which you may need to do
51
72
from source.
52
- 1 . ` git clone --recurse-submodules https://github.com/tensorflow/tensorflow `
53
- 1 . ` cd tensorflow `
54
- 1 . ` ./configure `
55
- 1 . ` bazel build -c opt --jobs=1 tensorflow:libtensorflow.so `
73
+ 3 . ` git clone https://github.com/tensorflow/tensorflow `
74
+ 4 . ` cd tensorflow `
75
+ 5 . ` ./configure `
76
+ 6 . ` bazel build --compilation_mode= opt --copt=-march=native --jobs=1 tensorflow:libtensorflow.so `
56
77
57
- Using --jobs=1 is recommended unless you have a lot of RAM, because
78
+ Using ` --jobs=1 ` is recommended unless you have a lot of RAM, because
58
79
TensorFlow's build is very memory intensive.
59
80
60
- Copy $TENSORFLOW_SRC/bazel-bin/tensorflow/libtensorflow.so to /usr/local/lib.
61
- If this is not possible, add $TENSORFLOW_SRC/bazel-bin/tensorflow to
62
- LD_LIBRARY_PATH.
81
+ Copy ` $TENSORFLOW_SRC/bazel-bin/tensorflow/libtensorflow.so ` to ` /usr/local/lib ` .
82
+ If this is not possible, add ` $TENSORFLOW_SRC/bazel-bin/tensorflow ` to
83
+ ` LD_LIBRARY_PATH ` .
63
84
64
- You may need to run ` ldconfig ` to reset ` ld ` 's cache after copying libtensorflow.so.
85
+ You may need to run ` ldconfig ` to reset ` ld ` 's cache after copying ` libtensorflow.so ` .
65
86
66
- Now run ` cargo build ` as usual.
67
- To include the especially unstable API (which is currently the ` expr ` module),
68
- use ` --features tensorflow_unstable ` .
69
-
70
- ## RFCs
71
- RFCs are [ issues tagged with RFC] ( https://github.com/tensorflow/rust/labels/rfc ) .
72
- Check them out and comment. Discussions are welcome. After all, thats what a Request For Comment is for!
87
+ ** OSX Note** : If you are running on OSX, there is a
88
+ [ Homebrew PR] ( https://github.com/Homebrew/homebrew-core/pull/10273 ) in process which, once merged,
89
+ will make it easy to install ` libtensorflow ` wihout hassle. In the meantime, you can take a look at
90
+ [ snipsco/tensorflow-build] ( https://github.com/snipsco/tensorflow-build ) which provides a homebrew
91
+ tap that does essentially the same.
73
92
74
- ## FAQs
93
+ ## FAQ's
75
94
76
- #### Why does the compiler say that parts of the API don't exist?
95
+ ### Why does the compiler say that parts of the API don't exist?
77
96
The especially unstable parts of the API (which is currently the ` expr ` modul) are
78
97
feature-gated behind the feature ` tensorflow_unstable ` to prevent accidental
79
98
use. See http://doc.crates.io/manifest.html#the-features-section .
80
99
(We would prefer using an ` #[unstable] ` attribute, but that
81
100
[ doesn't exist] ( https://github.com/rust-lang/rfcs/issues/1491 ) yet.)
82
101
83
- ## Other
84
-
85
- This project is not directly affiliated with the TensorFlow project, although we
86
- do intend to communicate and cooperate with them.
87
-
102
+ ## Contributing
88
103
Developers and users are welcome to join
89
104
[ #tensorflow-rust] ( http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23tensorflow-rust )
90
105
on irc.mozilla.org.
@@ -93,8 +108,9 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for information on how to contribute code
93
108
94
109
This is not an official Google product.
95
110
96
- ##For more information
111
+ RFCs are [ issues tagged with RFC] ( https://github.com/tensorflow/rust/labels/rfc ) .
112
+ Check them out and comment. Discussions are welcome. After all, thats what a Request For
113
+ Comment is for!
97
114
98
- * [ API docs] ( https://tensorflow.github.io/rust )
99
- * [ TensorFlow website] ( http://tensorflow.org )
100
- * [ TensorFlow GitHub page] ( https://github.com/tensorflow/tensorflow )
115
+ ## License
116
+ This project is licensed under the terms of the [ Apache 2.0 license] ( https://github.com/tensorflow/rust/blob/master/LICENSE ) .
0 commit comments