The tensorflow-ocaml project provides some OCaml bindings for TensorFlow.
These bindings are in a very early stage of their development and are not ready for real-world usage. They are likely to change a lot in the near future. Expect some segfaults if you use them for now.
opam install ocamlbuild ctypes ctypes-foreign core
You may also have to install the python-dev package.
git clone https://github.com/LaurentMazare/tensorflow-ocaml.git
Install TensorFlow.
Copy the TensorFlow shared library to lib/libtensorflow.so
in the cloned repo. You may have to tweak the following command depending on where TensorFlow was installed.
cp ~/.local/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so lib/libtensorflow.so
make run
Enjoy!
examples/load.ml
contains a simple example where the TensorFlow graph is loaded from a file (this graph has been generated byexamples/load.py
).examples/simple.ml
andexamples/var.ml
show how to generate a TensorFlow graph from OCaml and execute it.
The TensorFlow graph operators are defined in src/graph/ops.ml
. This file has been automatically generated from src/gen_ops/ops.pbtxt
which comes from the TensorFlow distribution.
Only the basic operators are likely to work for now.
- ocaml-ctypes is used for the C bindings.
- Core is only necessary when generating the graph from OCaml, the wrapper itself does not need it.
- The code in the piqi directory comes from the Piqi project. There is no need to install piqi though.