From 5870de43565bcb8a76860f138f4a6622e81cc598 Mon Sep 17 00:00:00 2001 From: Jean-Luc Parouty <Jean-Luc.Parouty@simap.grenoble-inp.fr> Date: Tue, 16 Jan 2024 22:05:55 +0100 Subject: [PATCH] Replace Wine.Keras2 by Wine.Keras3 (v2.5.1) --- BHPD.Keras3/02-DNN-Regression-Premium.ipynb | 13 +++---- README.ipynb | 30 +++++++++------- README.md | 18 ++++++---- .../01-DNN-Wine-Regression.ipynb | 34 +++++++++++-------- fidle/about.yml | 23 +++++++------ fidle/ci/default.yml | 11 +++++- 6 files changed, 73 insertions(+), 56 deletions(-) rename {Wine.Keras2 => Wine.Keras3}/01-DNN-Wine-Regression.ipynb (93%) diff --git a/BHPD.Keras3/02-DNN-Regression-Premium.ipynb b/BHPD.Keras3/02-DNN-Regression-Premium.ipynb index 2934861..d3a23c4 100644 --- a/BHPD.Keras3/02-DNN-Regression-Premium.ipynb +++ b/BHPD.Keras3/02-DNN-Regression-Premium.ipynb @@ -7,7 +7,7 @@ "<img width=\"800px\" src=\"../fidle/img/header.svg\"></img>\n", "\n", "# <!-- TITLE --> [K3BHPD2] - Regression with a Dense Network (DNN) - Advanced code\n", - " <!-- DESC --> A more advanced implementation of the precedent example\n", + " <!-- DESC --> A more advanced implementation of the precedent example, using Keras3\n", " <!-- AUTHOR : Jean-Luc Parouty (CNRS/SIMaP) -->\n", "\n", "## Objectives :\n", @@ -268,9 +268,7 @@ "source": [ "model=get_model_v1( (13,) )\n", "\n", - "model.summary()\n", - "# img=keras.utils.plot_model( model, to_file='./run/model.png', show_shapes=True, show_layer_names=True, dpi=96)\n", - "# display(img)" + "model.summary()" ] }, { @@ -289,10 +287,7 @@ "os.makedirs('./run/models', mode=0o750, exist_ok=True)\n", "save_dir = \"./run/models/best_model.keras\"\n", "\n", - "# savemodel_callback = tf.keras.callbacks.ModelCheckpoint(filepath=save_dir, verbose=0, save_best_only=True)\n", - "\n", - "savemodel_callback = keras.callbacks.ModelCheckpoint( filepath=save_dir, monitor='val_mae', mode='max', save_best_only=True)\n", - "\n" + "savemodel_callback = keras.callbacks.ModelCheckpoint( filepath=save_dir, monitor='val_mae', mode='max', save_best_only=True)" ] }, { @@ -310,7 +305,7 @@ "source": [ "history = model.fit(x_train,\n", " y_train,\n", - " epochs = 100,\n", + " epochs = 50,\n", " batch_size = 10,\n", " verbose = fit_verbosity,\n", " validation_data = (x_test, y_test),\n", diff --git a/README.ipynb b/README.ipynb index b051119..3b01ded 100644 --- a/README.ipynb +++ b/README.ipynb @@ -3,13 +3,13 @@ { "cell_type": "code", "execution_count": 1, - "id": "79c87fd3", + "id": "9fccea2b", "metadata": { "execution": { - "iopub.execute_input": "2024-01-16T19:19:00.566206Z", - "iopub.status.busy": "2024-01-16T19:19:00.565614Z", - "iopub.status.idle": "2024-01-16T19:19:00.577256Z", - "shell.execute_reply": "2024-01-16T19:19:00.576334Z" + "iopub.execute_input": "2024-01-16T21:04:27.072205Z", + "iopub.status.busy": "2024-01-16T21:04:27.071380Z", + "iopub.status.idle": "2024-01-16T21:04:27.081582Z", + "shell.execute_reply": "2024-01-16T21:04:27.080749Z" }, "jupyter": { "source_hidden": true @@ -52,7 +52,7 @@ "For more information, you can contact us at : \n", "[<img width=\"200px\" style=\"vertical-align:middle\" src=\"fidle/img/00-Mail_contact.svg\"></img>](#top)\n", "\n", - "Current Version : <!-- VERSION_BEGIN -->2.5.0<!-- VERSION_END -->\n", + "Current Version : <!-- VERSION_BEGIN -->2.5.1<!-- VERSION_END -->\n", "\n", "\n", "## Course materials\n", @@ -73,7 +73,7 @@ "The world of Deep Learning is changing very fast !\n", "\n", "<!-- TOC_BEGIN -->\n", - "<!-- Automatically generated on : 16/01/24 20:18:59 -->\n", + "<!-- Automatically generated on : 16/01/24 22:04:25 -->\n", "\n", "### Linear and logistic regression\n", "- **[LINR1](LinearReg/01-Linear-Regression.ipynb)** - [Linear regression with direct resolution](LinearReg/01-Linear-Regression.ipynb) \n", @@ -89,21 +89,25 @@ "- **[PER57](Perceptron/01-Simple-Perceptron.ipynb)** - [Perceptron Model 1957](Perceptron/01-Simple-Perceptron.ipynb) \n", "Example of use of a Perceptron, with sklearn and IRIS dataset of 1936 !\n", "\n", - "### BHPD regression (DNN), using Keras3\n", + "### BHPD regression (DNN), using Keras3/PyTorch\n", "- **[K3BHPD1](BHPD.Keras3/01-DNN-Regression.ipynb)** - [Regression with a Dense Network (DNN)](BHPD.Keras3/01-DNN-Regression.ipynb) \n", "Simple example of a regression with the dataset Boston Housing Prices Dataset (BHPD)\n", "- **[K3BHPD2](BHPD.Keras3/02-DNN-Regression-Premium.ipynb)** - [Regression with a Dense Network (DNN) - Advanced code](BHPD.Keras3/02-DNN-Regression-Premium.ipynb) \n", - "A more advanced implementation of the precedent example\n", + "A more advanced implementation of the precedent example, using Keras3\n", "\n", "### BHPD regression (DNN), using PyTorch\n", "- **[PBHPD1](BHPD.PyTorch/01-DNN-Regression_PyTorch.ipynb)** - [Regression with a Dense Network (DNN)](BHPD.PyTorch/01-DNN-Regression_PyTorch.ipynb) \n", "A Simple regression with a Dense Neural Network (DNN) using Pytorch - BHPD dataset\n", "\n", - "### Wine Quality prediction (DNN), using PyTorch Lightning\n", + "### Wine Quality prediction (DNN), using Keras3/PyTorch\n", + "- **[K3WINE1](Wine.Keras3/01-DNN-Wine-Regression.ipynb)** - [Wine quality prediction with a Dense Network (DNN)](Wine.Keras3/01-DNN-Wine-Regression.ipynb) \n", + "Another example of regression, with a wine quality prediction, using Keras 3 and PyTorch\n", + "\n", + "### Wine Quality prediction (DNN), using PyTorch/Lightning\n", "- **[LWINE1](Wine.Lightning/01-DNN-Wine-Regression-lightning.ipynb)** - [Wine quality prediction with a Dense Network (DNN)](Wine.Lightning/01-DNN-Wine-Regression-lightning.ipynb) \n", "Another example of regression, with a wine quality prediction, using PyTorch Lightning\n", "\n", - "### MNIST classification (DNN,CNN), using Keras3\n", + "### MNIST classification (DNN,CNN), using Keras3/PyTorch\n", "- **[K3MNIST1](MNIST.Keras3/01-DNN-MNIST.ipynb)** - [Simple classification with DNN](MNIST.Keras3/01-DNN-MNIST.ipynb) \n", "An example of classification using a dense neural network for the famous MNIST dataset\n", "- **[K3MNIST2](MNIST.Keras3/02-CNN-MNIST.ipynb)** - [Simple classification with CNN](MNIST.Keras3/02-CNN-MNIST.ipynb) \n", @@ -119,7 +123,7 @@ "- **[LMNIST2](MNIST.Lightning/02-CNN-MNIST_Lightning.ipynb)** - [Simple classification with CNN](MNIST.Lightning/02-CNN-MNIST_Lightning.ipynb) \n", "An example of classification using a convolutional neural network for the famous MNIST dataset, using PyTorch Lightning\n", "\n", - "### Images classification with Convolutional Neural Networks (CNN), using Keras3\n", + "### Images classification GTSRB with Convolutional Neural Networks (CNN), using Keras3/PyTorch\n", "- **[K3GTSRB1](GTSRB.Keras3/01-Preparation-of-data.ipynb)** - [Dataset analysis and preparation](GTSRB.Keras3/01-Preparation-of-data.ipynb) \n", "Episode 1 : Analysis of the GTSRB dataset and creation of an enhanced dataset\n", "- **[K3GTSRB2](GTSRB.Keras3/02-First-convolutions.ipynb)** - [First convolutions](GTSRB.Keras3/02-First-convolutions.ipynb) \n", @@ -252,7 +256,7 @@ "from IPython.display import display,Markdown\n", "display(Markdown(open('README.md', 'r').read()))\n", "#\n", - "# This README is visible under Jupiter Lab ;-)# Automatically generated on : 16/01/24 20:18:59" + "# This README is visible under Jupiter Lab ;-)# Automatically generated on : 16/01/24 22:04:26" ] } ], diff --git a/README.md b/README.md index f4d5867..5393036 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ For more information, see **https://fidle.cnrs.fr** : For more information, you can contact us at : [<img width="200px" style="vertical-align:middle" src="fidle/img/00-Mail_contact.svg"></img>](#top) -Current Version : <!-- VERSION_BEGIN -->2.5.0<!-- VERSION_END --> +Current Version : <!-- VERSION_BEGIN -->2.5.1<!-- VERSION_END --> ## Course materials @@ -52,7 +52,7 @@ For these reason, they are kept as examples, while we develop the Keras3/PyTorch The world of Deep Learning is changing very fast ! <!-- TOC_BEGIN --> -<!-- Automatically generated on : 16/01/24 20:18:59 --> +<!-- Automatically generated on : 16/01/24 22:04:25 --> ### Linear and logistic regression - **[LINR1](LinearReg/01-Linear-Regression.ipynb)** - [Linear regression with direct resolution](LinearReg/01-Linear-Regression.ipynb) @@ -68,21 +68,25 @@ Simple example of logistic regression with a sklearn solution - **[PER57](Perceptron/01-Simple-Perceptron.ipynb)** - [Perceptron Model 1957](Perceptron/01-Simple-Perceptron.ipynb) Example of use of a Perceptron, with sklearn and IRIS dataset of 1936 ! -### BHPD regression (DNN), using Keras3 +### BHPD regression (DNN), using Keras3/PyTorch - **[K3BHPD1](BHPD.Keras3/01-DNN-Regression.ipynb)** - [Regression with a Dense Network (DNN)](BHPD.Keras3/01-DNN-Regression.ipynb) Simple example of a regression with the dataset Boston Housing Prices Dataset (BHPD) - **[K3BHPD2](BHPD.Keras3/02-DNN-Regression-Premium.ipynb)** - [Regression with a Dense Network (DNN) - Advanced code](BHPD.Keras3/02-DNN-Regression-Premium.ipynb) -A more advanced implementation of the precedent example +A more advanced implementation of the precedent example, using Keras3 ### BHPD regression (DNN), using PyTorch - **[PBHPD1](BHPD.PyTorch/01-DNN-Regression_PyTorch.ipynb)** - [Regression with a Dense Network (DNN)](BHPD.PyTorch/01-DNN-Regression_PyTorch.ipynb) A Simple regression with a Dense Neural Network (DNN) using Pytorch - BHPD dataset -### Wine Quality prediction (DNN), using PyTorch Lightning +### Wine Quality prediction (DNN), using Keras3/PyTorch +- **[K3WINE1](Wine.Keras3/01-DNN-Wine-Regression.ipynb)** - [Wine quality prediction with a Dense Network (DNN)](Wine.Keras3/01-DNN-Wine-Regression.ipynb) +Another example of regression, with a wine quality prediction, using Keras 3 and PyTorch + +### Wine Quality prediction (DNN), using PyTorch/Lightning - **[LWINE1](Wine.Lightning/01-DNN-Wine-Regression-lightning.ipynb)** - [Wine quality prediction with a Dense Network (DNN)](Wine.Lightning/01-DNN-Wine-Regression-lightning.ipynb) Another example of regression, with a wine quality prediction, using PyTorch Lightning -### MNIST classification (DNN,CNN), using Keras3 +### MNIST classification (DNN,CNN), using Keras3/PyTorch - **[K3MNIST1](MNIST.Keras3/01-DNN-MNIST.ipynb)** - [Simple classification with DNN](MNIST.Keras3/01-DNN-MNIST.ipynb) An example of classification using a dense neural network for the famous MNIST dataset - **[K3MNIST2](MNIST.Keras3/02-CNN-MNIST.ipynb)** - [Simple classification with CNN](MNIST.Keras3/02-CNN-MNIST.ipynb) @@ -98,7 +102,7 @@ An example of classification using a dense neural network for the famous MNIST d - **[LMNIST2](MNIST.Lightning/02-CNN-MNIST_Lightning.ipynb)** - [Simple classification with CNN](MNIST.Lightning/02-CNN-MNIST_Lightning.ipynb) An example of classification using a convolutional neural network for the famous MNIST dataset, using PyTorch Lightning -### Images classification with Convolutional Neural Networks (CNN), using Keras3 +### Images classification GTSRB with Convolutional Neural Networks (CNN), using Keras3/PyTorch - **[K3GTSRB1](GTSRB.Keras3/01-Preparation-of-data.ipynb)** - [Dataset analysis and preparation](GTSRB.Keras3/01-Preparation-of-data.ipynb) Episode 1 : Analysis of the GTSRB dataset and creation of an enhanced dataset - **[K3GTSRB2](GTSRB.Keras3/02-First-convolutions.ipynb)** - [First convolutions](GTSRB.Keras3/02-First-convolutions.ipynb) diff --git a/Wine.Keras2/01-DNN-Wine-Regression.ipynb b/Wine.Keras3/01-DNN-Wine-Regression.ipynb similarity index 93% rename from Wine.Keras2/01-DNN-Wine-Regression.ipynb rename to Wine.Keras3/01-DNN-Wine-Regression.ipynb index a443c84..f3abe84 100644 --- a/Wine.Keras2/01-DNN-Wine-Regression.ipynb +++ b/Wine.Keras3/01-DNN-Wine-Regression.ipynb @@ -6,8 +6,8 @@ "source": [ "<img width=\"800px\" src=\"../fidle/img/header.svg\"></img>\n", "\n", - "# <!-- TITLE --> [K2WINE1] - Wine quality prediction with a Dense Network (DNN)\n", - " <!-- DESC --> Another example of regression, with a wine quality prediction, using Keras 2 and Tensorflow (obsolete)\n", + "# <!-- TITLE --> [K3WINE1] - Wine quality prediction with a Dense Network (DNN)\n", + " <!-- DESC --> Another example of regression, with a wine quality prediction, using Keras 3 and PyTorch\n", " <!-- AUTHOR : Jean-Luc Parouty (CNRS/SIMaP) -->\n", "\n", "## Objectives :\n", @@ -61,24 +61,18 @@ "metadata": {}, "outputs": [], "source": [ - "# import os\n", - "# os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'\n", + "import os\n", + "os.environ['KERAS_BACKEND'] = 'torch'\n", "\n", - "import tensorflow as tf\n", - "from tensorflow import keras\n", + "import keras\n", "\n", "import numpy as np\n", - "import matplotlib.pyplot as plt\n", "import pandas as pd\n", - "import os,sys\n", - "\n", - "from IPython.display import Markdown\n", - "from importlib import reload\n", "\n", "import fidle\n", "\n", "# Init Fidle environment\n", - "run_id, run_dir, datasets_dir = fidle.init('K2WINE1')" + "run_id, run_dir, datasets_dir = fidle.init('K3WINE1')" ] }, { @@ -267,9 +261,9 @@ "outputs": [], "source": [ "os.makedirs('./run/models', mode=0o750, exist_ok=True)\n", - "save_dir = \"./run/models/best_model.h5\"\n", + "save_dir = \"./run/models/best_model.keras\"\n", "\n", - "savemodel_callback = tf.keras.callbacks.ModelCheckpoint(filepath=save_dir, verbose=0, save_best_only=True)" + "savemodel_callback = keras.callbacks.ModelCheckpoint( filepath=save_dir, monitor='val_mae', mode='max', save_best_only=True)" ] }, { @@ -365,7 +359,7 @@ "metadata": {}, "outputs": [], "source": [ - "loaded_model = tf.keras.models.load_model('./run/models/best_model.h5')\n", + "loaded_model = keras.models.load_model('./run/models/best_model.keras')\n", "loaded_model.summary()\n", "print(\"Loaded.\")" ] @@ -435,6 +429,16 @@ " print(f'{i:03d} {pred:.2f} {real} {delta:+.2f} ')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Few questions :\n", + "- Can this model be used for red wines from Bordeaux and/or Beaujolais?\n", + "- What are the limitations of this model?\n", + "- What are the limitations of this dataset?" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/fidle/about.yml b/fidle/about.yml index c3a1687..ae56d2c 100644 --- a/fidle/about.yml +++ b/fidle/about.yml @@ -13,26 +13,27 @@ # # This file describes the notebooks used by the Fidle training. -version: 2.5.0 -content: notebooks -name: Notebooks Fidle -description: All notebooks used by the Fidle training +version: 2.5.1 +content: notebooks +name: Notebooks Fidle +description: All notebooks used by the Fidle training -readme_md: README.md -readme_ipynb: README.ipynb -default_ci: fidle/ci/default.yml +readme_md: README.md +readme_ipynb: README.ipynb +default_ci: fidle/ci/default.yml toc: LinearReg: Linear and logistic regression Perceptron: Perceptron Model 1957 - BHPD.Keras3: BHPD regression (DNN), using Keras3 + BHPD.Keras3: BHPD regression (DNN), using Keras3/PyTorch BHPD.PyTorch: BHPD regression (DNN), using PyTorch - Wine.Lightning: Wine Quality prediction (DNN), using PyTorch Lightning - MNIST.Keras3: MNIST classification (DNN,CNN), using Keras3 + Wine.Keras3: Wine Quality prediction (DNN), using Keras3/PyTorch + Wine.Lightning: Wine Quality prediction (DNN), using PyTorch/Lightning + MNIST.Keras3: MNIST classification (DNN,CNN), using Keras3/PyTorch MNIST.PyTorch: MNIST classification (DNN,CNN), using PyTorch MNIST.Lightning: MNIST classification (DNN,CNN), using Lightning - GTSRB.Keras3: Images classification with Convolutional Neural Networks (CNN), using Keras3 + GTSRB.Keras3: Images classification GTSRB with Convolutional Neural Networks (CNN), using Keras3/PyTorch Embedding.Keras2: Sentiment analysis with word embedding, using Keras2 (obsolete) RNN.Keras2: Time series with Recurrent Neural Network (RNN), using Keras2 (obsolete) Transformers.PyTorch: Sentiment analysis with transformer, using PyTorch diff --git a/fidle/ci/default.yml b/fidle/ci/default.yml index a22b264..46dc911 100644 --- a/fidle/ci/default.yml +++ b/fidle/ci/default.yml @@ -1,6 +1,6 @@ campain: version: '1.0' - description: Automatically generated ci profile (16/01/24 20:18:59) + description: Automatically generated ci profile (16/01/24 22:04:25) directory: ./campains/default existing_notebook: 'remove # remove|skip' report_template: 'fidle # fidle|default' @@ -42,6 +42,15 @@ K3BHPD2: PBHPD1: notebook: BHPD.PyTorch/01-DNN-Regression_PyTorch.ipynb +# +# ------------ Wine.Keras3 +# +K3WINE1: + notebook: Wine.Keras3/01-DNN-Wine-Regression.ipynb + overrides: + fit_verbosity: default + dataset_name: default + # # ------------ Wine.Lightning # -- GitLab