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); noLoop(); } void draw() { background(0); Graph g = new Graph(); String value = "Hello from " + TensorFlow.version(); Tensor t = null; try { t = Tensor.create(value.getBytes("UTF-8")); } catch (Exception e) { println(e.getMessage()); } g.opBuilder("Const", "MyConst") .setAttr("dtype", t.dataType()) .setAttr("value", t) .build(); Session s = new Session(g); Tensor output = null; try { output = s.runner() .fetch("MyConst") .run() .get(0); println(new String(output.bytesValue(), "UTF-8")); } catch (Exception e) { println(e.getMessage()); } } |