{"id":1922,"date":"2017-04-14T11:57:18","date_gmt":"2017-04-14T03:57:18","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1922"},"modified":"2017-04-14T11:58:58","modified_gmt":"2017-04-14T03:58:58","slug":"tensorflow-in-processing","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2017\/04\/14\/tensorflow-in-processing\/","title":{"rendered":"TensorFlow in Processing"},"content":{"rendered":"<p>The Java binding for the Google Deep Learning library, <a href=\"https:\/\/www.tensorflow.org\/api_docs\/java\/reference\/org\/tensorflow\/package-summary\">TensorFlow<\/a> is now available. The binary library files for version 1.1.0-rc1 \u00a0are also available for download <a href=\"https:\/\/github.com\/tensorflow\/tensorflow\/tree\/master\/tensorflow\/java\">here<\/a>. Below is the code for the Hello World program included in the distribution that I modified for Processing.<br \/>\n&nbsp;<\/p>\n<pre lang=\"java\">\r\nimport org.tensorflow.Graph;\r\nimport org.tensorflow.Session;\r\nimport org.tensorflow.Tensor;\r\nimport org.tensorflow.TensorFlow;\r\n\r\nGraph g1;\r\nOutput o1;\r\nOutput o2;\r\nOutput o3;\r\nPFont font;\r\nString res;\r\n\r\nvoid setup() {\r\n  size(640, 480);\r\n  noLoop();\r\n}\r\n\r\nvoid draw() {\r\n  background(0);\r\n  Graph g = new Graph();\r\n  String value = \"Hello from \" + TensorFlow.version();\r\n  Tensor t = null;\r\n  try {\r\n    t = Tensor.create(value.getBytes(\"UTF-8\"));\r\n  } \r\n  catch (Exception e) {\r\n    println(e.getMessage());\r\n  }\r\n  g.opBuilder(\"Const\", \"MyConst\")\r\n    .setAttr(\"dtype\", t.dataType())\r\n    .setAttr(\"value\", t)\r\n    .build();\r\n  Session s = new Session(g);\r\n  Tensor output = null;\r\n  try {\r\n    output = s.runner()\r\n      .fetch(\"MyConst\")\r\n      .run()\r\n      .get(0);\r\n    println(new String(output.bytesValue(), \"UTF-8\"));\r\n  } \r\n  catch (Exception e) {\r\n    println(e.getMessage());\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Java binding for the Google Deep Learning library, TensorFlow is now available. The binary library files for version 1.1.0-rc1 \u00a0are also available for download here. Below is the code for the Hello World program included in the distribution that I modified for Processing. &nbsp; import org.tensorflow.Graph; import org.tensorflow.Session; import org.tensorflow.Tensor; import org.tensorflow.TensorFlow; Graph g1; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89,79],"tags":[62,154],"class_list":["post-1922","post","type-post","status-publish","format-standard","hentry","category-research","category-software-2","tag-processing-org","tag-tensorflow"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=1922"}],"version-history":[{"count":3,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1922\/revisions"}],"predecessor-version":[{"id":1925,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1922\/revisions\/1925"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1922"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}