Awesome Open Source
Awesome Open Source

stensorflow - Scala Native TensorFlow


This library implements the C TensorFlow API adapted for the Scala Native platform.

Scala Native is a unique platform that marries the high level language of Scala but compiles to native code with a lightweight managed runtime which includes a state of the art garbage collector. The combination allows for great programming and the ability to use high performance C language libraries like TensorFlow.

Scala Native uses the Scala compiler to produce NIR (Native Intermediate Representation) that is optimized and then converted to LLVM IR. Finally LLVM code is optimized and compiled by Clang to produce a native executable.

Getting started

Maven Central

If you are already familiar with Scala Native you can jump right in by adding the following dependency in your sbt build file.

libraryDependencies += "org.ekrich" %%% "stensorflow" % "x.y.z"

To use in sbt, replace x.y.z with the version from Maven Central badge above. All available versions can be seen at the Maven Repository.

Otherwise follow the Getting Started instructions for Scala Native if you are not already setup.

Additional libraries

The TensorFlow C library is required and the current version is 2.7.0.

  • Linux/Ubuntu can TensorFlow following the following directions:

Essentially do the following for this platform and version: x84_64-2.7.0:

$ curl -fsSL \
    | tar -xz -C /usr/local
  • macOS can install TensorFlow using Homebrew which will install into the /usr/local/Cellar/libtensorflow/<version> directory.

Note: macOS Catalina 10.15.x or greater is required to install TensorFlow via Homebrew although the CI seems to work with 10.14.

$ brew install libtensorflow
  • Other OSes need to have libtensorflow available on the system.

Usage and Help

scaladoc Join chat

Reference the link above for Scaladoc. The documentation is a little sparse but hopefully will improve with time.

After sbt is installed and any other Scala Native prerequisites are met you can use the following Gitter G8 template instructions to get a fully functional Scala Native application with an example in the body of the main program.

$ sbt new ekrich/stensorflow.g8
$ cd <directory entered after the prompt>
$ sbt run

In addition, look at the stensorflow unit tests for other examples of usage.

TensorFlow References and External Documentation

TensorFlow Website
TensorFlow for JVM using JNI


Release 0.2.0 - (2021-12-13)
Release 0.1.0 - (2021-07-02)

Related Awesome Lists
Top Programming Languages
Top Projects

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Machine Learning (37,040
Scala (28,656
Tensorflow (22,338
Neural Network (15,489
Llvm (3,924
Scala Compiler (90
Scala Native (83