{"id":178,"date":"2022-09-20T19:06:19","date_gmt":"2022-09-20T19:06:19","guid":{"rendered":"https:\/\/valerio.nu\/?p=178"},"modified":"2022-09-20T19:06:21","modified_gmt":"2022-09-20T19:06:21","slug":"tensorflow-computational-graph-using-java-maven","status":"publish","type":"post","link":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/","title":{"rendered":"TensorFlow Computational Graph using Java (Maven)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Our last <a href=\"https:\/\/valerio.nu\/index.php\/2022\/08\/14\/how-to-set-up-a-tensorflow-java-project-using-maven\/\">tutorial<\/a> focused on introducing <a href=\"https:\/\/www.tensorflow.org\/guide\/tensor\">TensorFlow<\/a>. In that article, we covered the basic installation and use of TensorFlow in Java. In this tutorial, our focus is to highlight the TensorFlow Computational Graph components. With that said, let us explore graphs.\u00a0<\/p>\n\n\n\n<p>Graphs are a basic and crucial component of TensorFlow. They represent data structures that are comprised of applicable operations and defined data. Graphs can also contain keys and values. The keys are like maps that direct to the actual value.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"545\" height=\"444\" src=\"https:\/\/valerio.nu\/wp-content\/uploads\/2022\/09\/image.png\" alt=\"\" class=\"wp-image-190\" srcset=\"https:\/\/valerio.nu\/wp-content\/uploads\/2022\/09\/image.png 545w, https:\/\/valerio.nu\/wp-content\/uploads\/2022\/09\/image-300x244.png 300w\" sizes=\"auto, (max-width: 545px) 100vw, 545px\" \/><\/figure>\n<\/div>\n\n\n<p>The above picture represents a graph with two data and one operand (multiplication) that performs an operation and stores the result in another container (c).<\/p>\n\n\n\n<p>Applying the above graph diagram in our code we have a representation as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Graph cgraph = new Graph();<\/code><\/pre>\n\n\n\n<p>The code above initializes the Graph class. Thus, making it possible to access features associated with it.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Tensors<\/h2>\n\n\n\n<p>At the core of TensorFlow are Tensors. TensorFlow operates on multidimensional arrays. Furthermore, It takes several multidimensional array forms such as:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>A Scalar is a 0-dimensional tensor<\/li><li>A Vector is a 1-dimensional tensor<\/li><li>A Matrix is a 2-dimensional tensor&nbsp;<\/li><\/ol>\n\n\n\n<p>Tensors have ranks. The total number of directions a tensor can have in an N-dimensional space is called the Rank of the tensor. In summary, a Scalar has zero ranks,\u00a0 Vector has one rank and a matrix has two ranks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Operations<\/h2>\n\n\n\n<p>This represents a graph node that performs computation on tensors. An Operation is a node in a function graph that accepts zero or more Tensor objects as user input or insertion and produces the required zero or more Tensor objects as output. As an example, the code below where we see two inputs (2, and 3) and the \u201cMatMul\u201d&nbsp; operator to give the resultant multiplication output. e.g.,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>       Mul&lt;TInt32&gt; dblX = tf.math.mul(2, 3);<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Sessions<\/strong><\/h2>\n\n\n\n<p>Lastly, TensorFlow Session encompasses the environment where Operation objects are run and data objects are assessed. Furthermore, sessions are a crucial part of  Tensor operation and evaluation. Below is a quick example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> Session newSession = new Session(graph)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Conclusively, we have looked at TensorFlow Graph with a view to explaining in detail the components that makeup TensorFlow. The code for this tutorial is available on our <a href=\"https:\/\/github.com\/valerio-nu\/tensorflow_tutorial_2\">GitHub page<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Our last tutorial focused on introducing TensorFlow. In that article, we covered the basic installation and use of TensorFlow in Java. In this tutorial, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-178","post","type-post","status-publish","format-standard","hentry","category-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>TensorFlow Computational Graph using Java (Maven) - Andy&#039;s blog \u2935\ufe0f<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TensorFlow Computational Graph using Java (Maven) - Andy&#039;s blog \u2935\ufe0f\" \/>\n<meta property=\"og:description\" content=\"Introduction Our last tutorial focused on introducing TensorFlow. In that article, we covered the basic installation and use of TensorFlow in Java. In this tutorial, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/\" \/>\n<meta property=\"og:site_name\" content=\"Andy&#039;s blog \u2935\ufe0f\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-20T19:06:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-20T19:06:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/valerio.nu\/wp-content\/uploads\/2022\/09\/image.png\" \/>\n<meta name=\"author\" content=\"andy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"andy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/\"},\"author\":{\"name\":\"andy\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/#\\\/schema\\\/person\\\/da69cc3da309893b0d3bc8fcef75f128\"},\"headline\":\"TensorFlow Computational Graph using Java (Maven)\",\"datePublished\":\"2022-09-20T19:06:19+00:00\",\"dateModified\":\"2022-09-20T19:06:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/\"},\"wordCount\":357,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/valerio.nu\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/image.png\",\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/\",\"url\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/\",\"name\":\"TensorFlow Computational Graph using Java (Maven) - Andy&#039;s blog \u2935\ufe0f\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/valerio.nu\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/image.png\",\"datePublished\":\"2022-09-20T19:06:19+00:00\",\"dateModified\":\"2022-09-20T19:06:21+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/#\\\/schema\\\/person\\\/da69cc3da309893b0d3bc8fcef75f128\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/#primaryimage\",\"url\":\"https:\\\/\\\/valerio.nu\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/image.png\",\"contentUrl\":\"https:\\\/\\\/valerio.nu\\\/wp-content\\\/uploads\\\/2022\\\/09\\\/image.png\",\"width\":545,\"height\":444},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/09\\\/20\\\/tensorflow-computational-graph-using-java-maven\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/valerio.nu\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"TensorFlow Computational Graph using Java (Maven)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/#website\",\"url\":\"https:\\\/\\\/valerio.nu\\\/\",\"name\":\"Andy&#039;s blog \u2935\ufe0f\",\"description\":\"Abandon all hope, ye who enter here\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/valerio.nu\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/#\\\/schema\\\/person\\\/da69cc3da309893b0d3bc8fcef75f128\",\"name\":\"andy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g\",\"caption\":\"andy\"},\"sameAs\":[\"https:\\\/\\\/valerio.nu\"],\"url\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/author\\\/giuseppe\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"TensorFlow Computational Graph using Java (Maven) - Andy&#039;s blog \u2935\ufe0f","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/","og_locale":"en_US","og_type":"article","og_title":"TensorFlow Computational Graph using Java (Maven) - Andy&#039;s blog \u2935\ufe0f","og_description":"Introduction Our last tutorial focused on introducing TensorFlow. In that article, we covered the basic installation and use of TensorFlow in Java. In this tutorial, [&hellip;]","og_url":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/","og_site_name":"Andy&#039;s blog \u2935\ufe0f","article_published_time":"2022-09-20T19:06:19+00:00","article_modified_time":"2022-09-20T19:06:21+00:00","og_image":[{"url":"https:\/\/valerio.nu\/wp-content\/uploads\/2022\/09\/image.png","type":"","width":"","height":""}],"author":"andy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"andy","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/#article","isPartOf":{"@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/"},"author":{"name":"andy","@id":"https:\/\/valerio.nu\/#\/schema\/person\/da69cc3da309893b0d3bc8fcef75f128"},"headline":"TensorFlow Computational Graph using Java (Maven)","datePublished":"2022-09-20T19:06:19+00:00","dateModified":"2022-09-20T19:06:21+00:00","mainEntityOfPage":{"@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/"},"wordCount":357,"commentCount":0,"image":{"@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/#primaryimage"},"thumbnailUrl":"https:\/\/valerio.nu\/wp-content\/uploads\/2022\/09\/image.png","articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/","url":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/","name":"TensorFlow Computational Graph using Java (Maven) - Andy&#039;s blog \u2935\ufe0f","isPartOf":{"@id":"https:\/\/valerio.nu\/#website"},"primaryImageOfPage":{"@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/#primaryimage"},"image":{"@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/#primaryimage"},"thumbnailUrl":"https:\/\/valerio.nu\/wp-content\/uploads\/2022\/09\/image.png","datePublished":"2022-09-20T19:06:19+00:00","dateModified":"2022-09-20T19:06:21+00:00","author":{"@id":"https:\/\/valerio.nu\/#\/schema\/person\/da69cc3da309893b0d3bc8fcef75f128"},"breadcrumb":{"@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/#primaryimage","url":"https:\/\/valerio.nu\/wp-content\/uploads\/2022\/09\/image.png","contentUrl":"https:\/\/valerio.nu\/wp-content\/uploads\/2022\/09\/image.png","width":545,"height":444},{"@type":"BreadcrumbList","@id":"https:\/\/valerio.nu\/index.php\/2022\/09\/20\/tensorflow-computational-graph-using-java-maven\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/valerio.nu\/"},{"@type":"ListItem","position":2,"name":"TensorFlow Computational Graph using Java (Maven)"}]},{"@type":"WebSite","@id":"https:\/\/valerio.nu\/#website","url":"https:\/\/valerio.nu\/","name":"Andy&#039;s blog \u2935\ufe0f","description":"Abandon all hope, ye who enter here","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/valerio.nu\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/valerio.nu\/#\/schema\/person\/da69cc3da309893b0d3bc8fcef75f128","name":"andy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g","caption":"andy"},"sameAs":["https:\/\/valerio.nu"],"url":"https:\/\/valerio.nu\/index.php\/author\/giuseppe\/"}]}},"_links":{"self":[{"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/posts\/178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/comments?post=178"}],"version-history":[{"count":9,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":192,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/posts\/178\/revisions\/192"}],"wp:attachment":[{"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/media?parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/categories?post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/tags?post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}