Skip to content

xclerc/tensorflow-ocaml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Installation

Install the dependencies

opam install ocamlbuild ctypes ctypes-foreign core

You may also have to install the python-dev package.

Clone the repo

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

Try executing the examples from the root of the cloned repo

make run

Enjoy!

Examples

  • examples/load.ml contains a simple example where the TensorFlow graph is loaded from a file (this graph has been generated by examples/load.py).
  • examples/simple.ml and examples/var.ml show how to generate a TensorFlow graph from OCaml and execute it.

Generating the TensorFlow Graph from OCaml

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.

Dependencies

  • 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.

About

OCaml bindings for TensorFlow

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • OCaml 92.4%
  • C 7.3%
  • Other 0.3%