|
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "2024-10-25 11:03:35.818798: I external/local_xla/xla/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.\n",
- "2024-10-25 11:03:35.931633: I external/local_xla/xla/tsl/cuda/cudart_stub.cc:32] Could not find cuda drivers on your machine, GPU will not be used.\n",
- "2024-10-25 11:03:35.978295: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:485] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered\n",
- "2024-10-25 11:03:36.074794: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:8454] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered\n",
- "2024-10-25 11:03:36.095882: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1452] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered\n",
- "2024-10-25 11:03:36.215087: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
- "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
- "2024-10-25 11:03:37.495041: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
- ]
- }
- ],
- "source": [
- "import os\n",
- "import numpy as np\n",
- "import tensorflow as tf\n",
- "import matplotlib\n",
- "import matplotlib.pyplot as plt\n",
- "import cv2\n",
- "import pandas as pd\n",
- "import numpy as np\n",
- "import mlflow\n",
- "from tensorflow.keras import layers, models\n",
- "from tensorflow.keras.preprocessing import image_dataset_from_directory\n",
- "from tensorflow.keras.models import Model\n",
- "from sklearn.metrics import classification_report\n",
- "from PIL import Image\n",
- "from sklearn.metrics import confusion_matrix\n",
- "from sklearn.metrics import ConfusionMatrixDisplay\n",
- "from sklearn import __version__ as sklearn_version"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "<Experiment: artifact_location='mlflow-artifacts:/103379370584144202', creation_time=1721579566179, experiment_id='103379370584144202', last_update_time=1721579566179, lifecycle_stage='active', name='champi', tags={'mlflow.sharedViewState.d4d3ab312f340bdf78e73ff3b2e223651ae813cd5c2bb0ee7938c7dba4de2511': '{\"searchFilter\":\"\",\"orderByKey\":\"attributes.start_time\",\"orderByAsc\":false,\"startTime\":\"ALL\",\"lifecycleFilter\":\"Active\",\"datasetsFilter\":[],\"modelVersionFilter\":\"All '\n",
- " 'Runs\",\"selectedColumns\":[\"attributes.`Models`\",\"metrics.`accuracy`\",\"metrics.`val_accuracy`\",\"attributes.`User`\",\"params.`epochs`\",\"attributes.`Description`\"],\"runsExpanded\":{},\"runsPinned\":[],\"runsHidden\":[],\"runsHiddenMode\":\"FIRST_10_RUNS\",\"compareRunCharts\":[{\"uuid\":\"17218375793866mexilt9\",\"type\":\"BAR\",\"runsCountToCompare\":10,\"metricSectionId\":\"17218375793869x5p8wdz\",\"deleted\":false,\"isGenerated\":true,\"metricKey\":\"train_accuracy\"},{\"uuid\":\"172183757938670qjdu0z\",\"type\":\"BAR\",\"runsCountToCompare\":10,\"metricSectionId\":\"17218375793869x5p8wdz\",\"deleted\":false,\"isGenerated\":true,\"metricKey\":\"train_loss\"},{\"uuid\":\"1721837579386s9miya0n\",\"type\":\"BAR\",\"runsCountToCompare\":10,\"metricSectionId\":\"17218375793869x5p8wdz\",\"deleted\":false,\"isGenerated\":true,\"metricKey\":\"val_accuracy\"},{\"uuid\":\"1721837579386tzl1e19r\",\"type\":\"BAR\",\"runsCountToCompare\":10,\"metricSectionId\":\"17218375793869x5p8wdz\",\"deleted\":false,\"isGenerated\":true,\"metricKey\":\"val_loss\"}],\"compareRunSections\":[{\"uuid\":\"17218375793869x5p8wdz\",\"name\":\"Model '\n",
- " 'metrics\",\"display\":true,\"isReordered\":false,\"deleted\":false,\"isGenerated\":true},{\"uuid\":\"1721837579386jrv4pstu\",\"name\":\"System '\n",
- " 'metrics\",\"display\":true,\"isReordered\":false,\"deleted\":false,\"isGenerated\":true}],\"viewMaximized\":false,\"runListHidden\":false,\"isAccordionReordered\":false,\"useGroupedValuesInCharts\":true,\"groupBy\":null,\"groupsExpanded\":{},\"autoRefreshEnabled\":false}'}>"
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "# Configuration du serveur MLflow\n",
- "mlflow_server_uri = \"https://champi.heuzef.com\"\n",
- "mlflow.set_tracking_uri(mlflow_server_uri)\n",
- "mlflow.set_experiment(\"champi\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Test et Evaluation du Modèle"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "/home/heuzef/GIT/jan24_cds_mushrooms/.venv/lib/python3.11/site-packages/keras/src/layers/convolutional/base_conv.py:107: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n",
- " super().__init__(activity_regularizer=activity_regularizer, **kwargs)\n",
- "/home/heuzef/GIT/jan24_cds_mushrooms/.venv/lib/python3.11/site-packages/keras/src/optimizers/base_optimizer.py:33: UserWarning: Argument `decay` is no longer supported and will be ignored.\n",
- " warnings.warn(\n",
- "WARNING:absl:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.\n",
- "WARNING:absl:Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.\n"
- ]
- },
- {
- "data": {
- "text/html": [
- "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">Model: \"sequential\"</span>\n",
- "</pre>\n"
- ],
- "text/plain": [
- "\u001b[1mModel: \"sequential\"\u001b[0m\n"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
- "┃<span style=\"font-weight: bold\"> Layer (type) </span>┃<span style=\"font-weight: bold\"> Output Shape </span>┃<span style=\"font-weight: bold\"> Param # </span>┃\n",
- "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
- "│ conv2d (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">222</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">222</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">32</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">896</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">222</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">222</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">32</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">128</span> │\n",
- "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">MaxPooling2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">111</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">111</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">32</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ conv2d_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">109</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">109</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">18,496</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization_1 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">109</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">109</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span> │\n",
- "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">MaxPooling2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">54</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">54</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ conv2d_2 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">52</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">52</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">128</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">73,856</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization_2 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">52</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">52</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">128</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span> │\n",
- "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d_2 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">MaxPooling2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">26</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">26</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">128</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ conv2d_3 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">24</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">24</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">295,168</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization_3 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">24</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">24</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">1,024</span> │\n",
- "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d_3 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">MaxPooling2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">12</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">12</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">256</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ conv2d_4 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">10</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">10</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">1,180,160</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization_4 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">10</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">10</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">2,048</span> │\n",
- "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d_4 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">MaxPooling2D</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">5</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">5</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ flatten (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Flatten</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">12800</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ dense (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">6,554,112</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ dropout (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dropout</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">512</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ dense_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>) │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">23</span>) │ <span style=\"color: #00af00; text-decoration-color: #00af00\">11,799</span> │\n",
- "└─────────────────────────────────┴────────────────────────┴───────────────┘\n",
- "</pre>\n"
- ],
- "text/plain": [
- "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
- "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\n",
- "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
- "│ conv2d (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m222\u001b[0m, \u001b[38;5;34m222\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m896\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m222\u001b[0m, \u001b[38;5;34m222\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m128\u001b[0m │\n",
- "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m111\u001b[0m, \u001b[38;5;34m111\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ conv2d_1 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m109\u001b[0m, \u001b[38;5;34m109\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m18,496\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m109\u001b[0m, \u001b[38;5;34m109\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m256\u001b[0m │\n",
- "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d_1 (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m54\u001b[0m, \u001b[38;5;34m54\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ conv2d_2 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m52\u001b[0m, \u001b[38;5;34m52\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m73,856\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m52\u001b[0m, \u001b[38;5;34m52\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\u001b[0m │\n",
- "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d_2 (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m26\u001b[0m, \u001b[38;5;34m26\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ conv2d_3 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m24\u001b[0m, \u001b[38;5;34m24\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m295,168\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization_3 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m24\u001b[0m, \u001b[38;5;34m24\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │\n",
- "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d_3 (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m12\u001b[0m, \u001b[38;5;34m12\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ conv2d_4 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m10\u001b[0m, \u001b[38;5;34m10\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m1,180,160\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ batch_normalization_4 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m10\u001b[0m, \u001b[38;5;34m10\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m2,048\u001b[0m │\n",
- "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ max_pooling2d_4 (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m5\u001b[0m, \u001b[38;5;34m5\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ flatten (\u001b[38;5;33mFlatten\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m12800\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ dense (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m6,554,112\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ dropout (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m512\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n",
- "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
- "│ dense_1 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m23\u001b[0m) │ \u001b[38;5;34m11,799\u001b[0m │\n",
- "└─────────────────────────────────┴────────────────────────┴───────────────┘\n"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Total params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">8,138,457</span> (31.05 MB)\n",
- "</pre>\n"
- ],
- "text/plain": [
- "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m8,138,457\u001b[0m (31.05 MB)\n"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">8,136,471</span> (31.04 MB)\n",
- "</pre>\n"
- ],
- "text/plain": [
- "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m8,136,471\u001b[0m (31.04 MB)\n"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Non-trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">1,984</span> (7.75 KB)\n",
- "</pre>\n"
- ],
- "text/plain": [
- "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m1,984\u001b[0m (7.75 KB)\n"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/html": [
- "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\"> Optimizer params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">2</span> (12.00 B)\n",
- "</pre>\n"
- ],
- "text/plain": [
- "\u001b[1m Optimizer params: \u001b[0m\u001b[38;5;34m2\u001b[0m (12.00 B)\n"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
- "source": [
- "# Charger le modèle\n",
- "model = tf.keras.models.load_model('../../models/artifacts/yvan_jarvispore.h5')\n",
- "\n",
- "model.summary()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 27,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "conv2d\n",
- "batch_normalization\n",
- "max_pooling2d\n",
- "conv2d_1\n",
- "batch_normalization_1\n",
- "max_pooling2d_1\n",
- "conv2d_2\n",
- "batch_normalization_2\n",
- "max_pooling2d_2\n",
- "conv2d_3\n",
- "batch_normalization_3\n",
- "max_pooling2d_3\n",
- "conv2d_4\n",
- "batch_normalization_4\n",
- "max_pooling2d_4\n",
- "flatten\n",
- "dense\n",
- "dropout\n",
- "dense_1\n"
- ]
- }
- ],
- "source": [
- "# Vérifier les noms des couches du modèle\n",
- "for layer in model.layers:\n",
- " print(layer.name)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 28,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[[[[46. 55. 10.]\n",
- " [48. 61. 5.]\n",
- " [45. 70. 4.]\n",
- " ...\n",
- " [22. 34. 10.]\n",
- " [24. 34. 9.]\n",
- " [24. 34. 7.]]\n",
- "\n",
- " [[46. 63. 8.]\n",
- " [43. 68. 2.]\n",
- " [44. 71. 0.]\n",
- " ...\n",
- " [23. 38. 7.]\n",
- " [17. 32. 3.]\n",
- " [25. 39. 13.]]\n",
- "\n",
- " [[46. 68. 3.]\n",
- " [42. 72. 0.]\n",
- " [42. 72. 0.]\n",
- " ...\n",
- " [17. 31. 6.]\n",
- " [18. 30. 6.]\n",
- " [18. 30. 6.]]\n",
- "\n",
- " ...\n",
- "\n",
- " [[57. 93. 6.]\n",
- " [53. 93. 5.]\n",
- " [55. 92. 14.]\n",
- " ...\n",
- " [40. 20. 13.]\n",
- " [54. 25. 11.]\n",
- " [74. 27. 9.]]\n",
- "\n",
- " [[53. 91. 6.]\n",
- " [57. 94. 16.]\n",
- " [53. 84. 8.]\n",
- " ...\n",
- " [58. 18. 6.]\n",
- " [71. 28. 11.]\n",
- " [70. 24. 9.]]\n",
- "\n",
- " [[56. 88. 12.]\n",
- " [55. 87. 11.]\n",
- " [55. 90. 10.]\n",
- " ...\n",
- " [70. 39. 19.]\n",
- " [76. 42. 17.]\n",
- " [72. 37. 15.]]]]\n"
- ]
- }
- ],
- "source": [
- "img_path = 'Stropharia_ambigua.jpg'\n",
- "img = tf.keras.utils.load_img(img_path, target_size=(224, 224))\n",
- "img_array = tf.keras.utils.img_to_array(img)\n",
- "img_array = np.expand_dims(img_array, axis=0)\n",
- "# img_array /= 255.0 <= Ne pas appliquer cette normalisation !\n",
- "\n",
- "print(img_array)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 29,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\u001b[1m1/1\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 28ms/step\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "array([[1.39423105e-15, 1.33577138e-09, 1.18861605e-11, 2.34543396e-13,\n",
- " 1.46086858e-11, 6.81908577e-13, 1.31949776e-15, 6.21433040e-14,\n",
- " 3.58152832e-03, 1.37310572e-05, 9.30511057e-10, 5.02229439e-11,\n",
- " 3.02496773e-07, 1.34497757e-09, 1.17063070e-14, 1.64082564e-16,\n",
- " 8.56261514e-13, 9.82579225e-14, 1.79859188e-16, 9.96404409e-01,\n",
- " 5.06198165e-12, 1.81432788e-12, 1.04054815e-16]], dtype=float32)"
- ]
- },
- "execution_count": 29,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "predictions = model.predict(img_array)\n",
- "\n",
- "predictions"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 30,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "<div>\n",
- "<style scoped>\n",
- " .dataframe tbody tr th:only-of-type {\n",
- " vertical-align: middle;\n",
- " }\n",
- "\n",
- " .dataframe tbody tr th {\n",
- " vertical-align: top;\n",
- " }\n",
- "\n",
- " .dataframe thead th {\n",
- " text-align: right;\n",
- " }\n",
- "</style>\n",
- "<table border=\"1\" class=\"dataframe\">\n",
- " <thead>\n",
- " <tr style=\"text-align: right;\">\n",
- " <th></th>\n",
- " <th>0</th>\n",
- " </tr>\n",
- " </thead>\n",
- " <tbody>\n",
- " <tr>\n",
- " <th>0</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>1</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>2</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>3</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>4</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>5</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>6</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>7</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>8</th>\n",
- " <td>0.040611</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>9</th>\n",
- " <td>0.040467</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>10</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>11</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>12</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>13</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>14</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>15</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>16</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>17</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>18</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>19</th>\n",
- " <td>0.109603</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>20</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>21</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " <tr>\n",
- " <th>22</th>\n",
- " <td>0.040466</td>\n",
- " </tr>\n",
- " </tbody>\n",
- "</table>\n",
- "</div>"
- ],
- "text/plain": [
- " 0\n",
- "0 0.040466\n",
- "1 0.040466\n",
- "2 0.040466\n",
- "3 0.040466\n",
- "4 0.040466\n",
- "5 0.040466\n",
- "6 0.040466\n",
- "7 0.040466\n",
- "8 0.040611\n",
- "9 0.040467\n",
- "10 0.040466\n",
- "11 0.040466\n",
- "12 0.040466\n",
- "13 0.040466\n",
- "14 0.040466\n",
- "15 0.040466\n",
- "16 0.040466\n",
- "17 0.040466\n",
- "18 0.040466\n",
- "19 0.109603\n",
- "20 0.040466\n",
- "21 0.040466\n",
- "22 0.040466"
- ]
- },
- "execution_count": 30,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "score = tf.nn.softmax(predictions[0])\n",
- "\n",
- "pd.DataFrame(tf.nn.softmax(predictions[0]))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 31,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "\u001b[1m1/1\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 43ms/step\n",
- "Classe prédite : 19\n"
- ]
- }
- ],
- "source": [
- "# Faire la prédiction\n",
- "predictions = model.predict(img_array)\n",
- "\n",
- "# Afficher la classe prédite (ou la distribution des probabilités)\n",
- "predicted_class = np.argmax(predictions[0]) # Si le modèle a une sortie par classe\n",
- "print(f'Classe prédite : {predicted_class}')"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "jarvis_env",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.11.9"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
|