{"id":1716,"date":"2026-06-04T10:57:02","date_gmt":"2026-06-04T09:57:02","guid":{"rendered":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/?p=1716"},"modified":"2026-06-12T10:19:55","modified_gmt":"2026-06-12T09:19:55","slug":"keras-3-for-practical-sessions","status":"publish","type":"post","link":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/?p=1716","title":{"rendered":"Keras 3 for practical sessions"},"content":{"rendered":"\n<p><a href=\"https:\/\/keras.io\/\">Keras 3<\/a> is a simple, powerful, and flexible API that allows one to quickly learn deep learning concepts.<\/p>\n\n\n\n<p>It is a multi-framework API in python compatible with Tensorflow, PyTorch and JAX backends.<\/p>\n\n\n\n<p>Significant efforts have been made to ensure compatibility and strong performance in terms of memory and computation, whether using tf.data.Dataset, DataLoader (PyTorch), or NumPy arrays.<\/p>\n\n\n\n<p>With Keras, you can go from very high-level functions (as fit()) to very deep customization (i.e., layers, training iterations, &#8230;).<\/p>\n\n\n\n<p>To use a specific backend, you have to set the KERAS_BACKEND variable to one of &#8220;tensorflow&#8221;, &#8220;jax&#8221; or &#8220;torch&#8221; <strong>before <\/strong>importing keras. To do so, you can do it with a simple command line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export KERAS_BACKEND=\"tensorflow\"<\/code><\/pre>\n\n\n\n<p>or, by beginning your Python code with :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nos.environ&#91;\"KERAS_BACKEND\"] = \"tensorflow\"\nimport keras\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Keras3 based on Tensorflow-gpu backend<\/h3>\n\n\n\n<p>With Keras, TensorFlow and Jax are faster than PyTorch (see the benchmark here). For Windows users, the installation of recent versions of TensorFlow must be done with WSL (<a href=\"https:\/\/www.tensorflow.org\/install\/pip?hl=fr#windows-wsl2\">see here<\/a>).<\/p>\n\n\n\n<p>To install Keras and TensorFlow, you can follow this <a href=\"https:\/\/keras.io\/getting_started\/#configuring-your-backend\">link<\/a>. I resume and optimize the procedure in the following :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/raw.githubusercontent.com\/keras-team\/keras\/refs\/heads\/master\/requirements-tensorflow-cuda.txt\nwget https:\/\/raw.githubusercontent.com\/keras-team\/keras\/refs\/heads\/master\/requirements-common.txt\n\nconda create -y -n Keras3TF python=3.12\nconda activate Keras3TF\n\npip install -r requirements-tensorflow-cuda.txt\npip install --upgrade keras keras-cv keras-hub keras-tuner tqdm jupyterlab jupyter-app-launcher ipywidgets matplotlib\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Keras3 based on PyTorch-gpu backend<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/raw.githubusercontent.com\/keras-team\/keras\/refs\/heads\/master\/requirements-torch-cuda.txt\nwget https:\/\/raw.githubusercontent.com\/keras-team\/keras\/refs\/heads\/master\/requirements-common.txt\n\nconda create -y -n Keras3Torch python=3.12\nconda activate Keras3Torch \n\npip install -r requirements-torch-cuda.txt\npip install --upgrade keras keras-cv keras-hub keras-tuner tqdm jupyterlab jupyter-app-launcher ipywidgets matplotlib\n<\/code><\/pre>\n\n\n\n<p>Remember to set the KERAS_BACKEND variable<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nos.environ&#91;\"KERAS_BACKEND\"] = \"torch\"\nimport keras\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Keras 3 is a simple, powerful, and flexible API that allows one to quickly learn deep learning concepts. It is a multi-framework API in python compatible with Tensorflow, PyTorch and JAX backends. Significant efforts have been made to ensure compatibility and strong performance in terms of memory and computation, whether using tf.data.Dataset, DataLoader (PyTorch), or [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,17,18,3,4,1],"tags":[],"class_list":["post-1716","post","type-post","status-publish","format-standard","hentry","category-computer-science","category-deep-learning","category-deep-learning-teaching","category-research","category-teaching","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=\/wp\/v2\/posts\/1716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1716"}],"version-history":[{"count":6,"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=\/wp\/v2\/posts\/1716\/revisions"}],"predecessor-version":[{"id":1725,"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=\/wp\/v2\/posts\/1716\/revisions\/1725"}],"wp:attachment":[{"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}