{"id":79946,"date":"2020-09-26T09:00:44","date_gmt":"2020-09-26T03:30:44","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=79946"},"modified":"2020-09-26T09:00:44","modified_gmt":"2020-09-26T03:30:44","slug":"keras-backend-functions","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/","title":{"rendered":"Keras Backend Functions and Utilities"},"content":{"rendered":"<p>Keras is a high-level neural network API. It is simple and easy and offers ample features to simplify the task of the user. It is user-friendly offering high readability and focuses on the idea of a Model.<\/p>\n<p>Keras is built for fast experiments. It is the most popular Python library supporting Deep Learning. Let us learn about Keras Backend Functions and Utilities.<\/p>\n<h3>Keras Backend Basics<\/h3>\n<p>Knowing that Keras is a high-level neural network API. Clearly, it does not support low-level computations. It depends on other platforms and libraries to do these low-level tasks.<\/p>\n<p>There are some specialized and optimized manipulation libraries that help Keras. These libraries are called the \u2018Backend Engines\u2019 of Keras. Keras have such three libraries supporting Keras in the backend.<\/p>\n<p>These are TensorFlow, Theano, and Microsoft CNTK. Keras offers you an opportunity to choose among these backends. Because Keras handles problems in a modular way.<\/p>\n<p>You can also choose multiple backends if you want. Keras runs on the top of these backend engines.<\/p>\n<h3>Commonly Used Keras Backends<\/h3>\n<p>Although Keras support three backend engines. TensorFlow and Theano have commonly used backends:<\/p>\n<h4>1. TensorFlow<\/h4>\n<p>TensorFlow is an open-source library used for Machine Learning and developed by Google. It focuses on symbolic tensor manipulations and is mainly used for mathematical computational tasks.<\/p>\n<h4>2. Theano<\/h4>\n<p>Theano is another backend Python library developed by the LISA lab at the University of Montreal. It is also an open-source Deep Learning library.<\/p>\n<p>It offers you an opportunity to evaluate the multi-dimensional arrays and allows you to manipulate and evaluate mathematical expressions.<\/p>\n<h4>How to Select\/Change a Backend in Keras<\/h4>\n<p>To check about the backend you are using, you can use a backend function.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">keras.backend.backend()\n<\/pre>\n<p>Although Keras opts TensorFlow as its default backend. Still, it offers you an opportunity to change and switch between backends.<\/p>\n<p>If you want to change the backend from TensorFlow to Theano or CNTK, you need to execute a small code of two lines. Using use_backend() and passing the name of the backend as its argument, you can accomplish your task.<\/p>\n<p><strong>Code to switch to Theano:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">library(keras)\nuse_backend(\u201ctheano\u201d)\n<\/pre>\n<p><strong>Code to switch to CNTK:<\/strong><br \/>\nTo use CNTK as your backend engine, follow the installation instructions.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">library(keras)\nuse_backend(\u201ccntk\u201d)\n<\/pre>\n<h4>Configuration File of Keras<\/h4>\n<p>If you have run Keras at least once, and if not, you can create it. You will find the configuration file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">$home\/.keras\/keras.json<\/pre>\n<p>The default configuration files look like:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{\n    \"image_data_format\": \"channels_last\",\n    \"epsilon\": 1e-07,\n    \"floatx\": \"float32\",\n    \"backend\": \"tensorflow\"\n}\n<\/pre>\n<p>To change the backend, edit TensorFlow, theano, or cntk in the backend, according to your choice. Now, save the file and restart your terminal. On starting the Keras again, you will find your backend changed.<\/p>\n<h3>Keras Backend Functions<\/h3>\n<p>There are ample backend functions that enable you to perform effectively. Let\u2019s study a few of them:<br \/>\n<strong>1. Symbolic():<\/strong> it is useful in TensorFlow 2.0. It enables you to enter the Keras graph. It returns a decorated graph.<br \/>\nkeras.backend.symbolic(func)<\/p>\n<p><strong>2. Eager():<\/strong> It is useful in TensorFlow 2.0. it helps you to exit the Keras graph. It returns the decorated function.<br \/>\nkeras.backend.eager(func)<\/p>\n<p><strong>3. Backend():<\/strong> It returns the name of the backend you are currently using. It returns the name as a string.<br \/>\nkeras.backend.backend()<\/p>\n<p><strong>4. Clear_session():<\/strong> It enables you to destroy the current Keras graph and enables you to create a new graph.<br \/>\nkeras.backend.clear_session()<\/p>\n<p><strong>5. Shape()<\/strong>: It returns the shape of variable or tensor in symbolic form.<br \/>\nkeras.backend.shape(x)<\/p>\n<h3>Conclusion<\/h3>\n<p>Keras is the most famous Python library for Deep Learning. It is very simple and enables fast implementation. It runs on the top of TensorFlow and Theano. But it does not perform low-level computations.<\/p>\n<p>So, it takes the help of backend engines. These Keras backend engines are TensorFlow, Theano, and Microsoft CNTK. TensorFlow is the default backend for Keras. Keras is glooming these days.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Keras is a high-level neural network API. It is simple and easy and offers ample features to simplify the task of the user. It is user-friendly offering high readability and focuses on the idea&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79984,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3263],"tags":[3277,3278,3279,3280],"class_list":["post-79946","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-keras-tutorials","tag-keras-backend","tag-keras-backend-tensorflow","tag-keras-backend-theano","tag-keras-backend-utilities"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Keras Backend Functions and Utilities - TechVidvan<\/title>\n<meta name=\"description\" content=\"Keras is model-level library, providing high-level building blocks for deep learning. There are 2 Keras backend engines- TensorFlow, Theano\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Keras Backend Functions and Utilities - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Keras is model-level library, providing high-level building blocks for deep learning. There are 2 Keras backend engines- TensorFlow, Theano\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-26T03:30:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/Keras-backend-Tensorflow-Theano.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Keras Backend Functions and Utilities - TechVidvan","description":"Keras is model-level library, providing high-level building blocks for deep learning. There are 2 Keras backend engines- TensorFlow, Theano","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:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/","og_locale":"en_US","og_type":"article","og_title":"Keras Backend Functions and Utilities - TechVidvan","og_description":"Keras is model-level library, providing high-level building blocks for deep learning. There are 2 Keras backend engines- TensorFlow, Theano","og_url":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-09-26T03:30:44+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/Keras-backend-Tensorflow-Theano.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Keras Backend Functions and Utilities","datePublished":"2020-09-26T03:30:44+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/"},"wordCount":623,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/Keras-backend-Tensorflow-Theano.jpg","keywords":["Keras Backend","Keras backend TensorFlow","Keras backend Theano","Keras Backend Utilities"],"articleSection":["Keras Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/","url":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/","name":"Keras Backend Functions and Utilities - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/Keras-backend-Tensorflow-Theano.jpg","datePublished":"2020-09-26T03:30:44+00:00","description":"Keras is model-level library, providing high-level building blocks for deep learning. There are 2 Keras backend engines- TensorFlow, Theano","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/Keras-backend-Tensorflow-Theano.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/09\/Keras-backend-Tensorflow-Theano.jpg","width":802,"height":420,"caption":"Keras backend-Tensorflow & Theano"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/keras-backend-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Keras Backend Functions and Utilities"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=79946"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79946\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/79984"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=79946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=79946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=79946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}