TensorFlow in Processing

The Java binding for the Google Deep Learning library, TensorFlow is now available. The binary library files for version 1.1.0-rc1  are also available for download here. Below is the code for the Hello World program included in the distribution that I modified for Processing.

import org.tensorflow.Graph;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
import org.tensorflow.TensorFlow;
Graph g1;
Output o1;
Output o2;
Output o3;
PFont font;
String res;
void setup() {
  size(640, 480);
void draw() {
  Graph g = new Graph();
  String value = "Hello from " + TensorFlow.version();
  Tensor t = null;
  try {
    t = Tensor.create(value.getBytes("UTF-8"));
  catch (Exception e) {
  g.opBuilder("Const", "MyConst")
    .setAttr("dtype", t.dataType())
    .setAttr("value", t)
  Session s = new Session(g);
  Tensor output = null;
  try {
    output = s.runner()
    println(new String(output.bytesValue(), "UTF-8"));
  catch (Exception e) {
This entry was posted in Research, Software and tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.