{"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-07-09T16:55:41","modified_gmt":"2026-07-09T15:55:41","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 (linux)<\/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 summarize 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 (linux)<\/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<h3 class=\"wp-block-heading\">Installing Keras3 \/ Tensorflow \/ PyTorch-on windows (Jules Robin &amp; Isidore Dubuisson)<\/h3>\n\n\n\n<p>Thanks to <a href=\"https:\/\/www.linkedin.com\/in\/jules-robin-938188330\/\">Jules Robin<\/a> and <a href=\"https:\/\/www.linkedin.com\/in\/isidore-dubuisson-7186a9175\/\">Isidore Dubuisson<\/a>, it is now easy to install the required environment under Microsoft Windows. This solution is built around PowerShell and virtualenv Python (venv). Follow the instructions in the git repository of Jules, <a href=\"https:\/\/github.com\/Tquapol\/Local-Python-Environment-for-Jupyter-Notebook\">https:\/\/github.com\/Tquapol\/Local-Python-Environment-for-Jupyter-Notebook<\/a><\/p>\n\n\n\n<p>1- Download the requirements file (you can adapt it)<\/p>\n\n\n\n<p>3- Download the <em>launch_jupyter_notebook.bat<\/em> <\/p>\n\n\n\n<p>2- Download the Jupyter_exe.bat file <a href=\"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/pdf\/tmp\/install_env.bat\" data-type=\"link\" data-id=\"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/pdf\/tmp\/install_env.bat\">here<\/a> in the same folder as the requirements<\/p>\n\n\n\n<p>3- Execute the Jupyter_exe.bat, then the <em>launch_jupyter_notebook.bat<\/em> file.<\/p>\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":9,"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=\/wp\/v2\/posts\/1716\/revisions"}],"predecessor-version":[{"id":1741,"href":"https:\/\/www.creatis.insa-lyon.fr\/~grenier\/index.php?rest_route=\/wp\/v2\/posts\/1716\/revisions\/1741"}],"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}]}}