You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Base_JarviSpore.ipynb 43 KiB

2 days ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stderr",
  10. "output_type": "stream",
  11. "text": [
  12. "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",
  13. "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",
  14. "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",
  15. "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",
  16. "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",
  17. "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",
  18. "To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
  19. "2024-10-25 11:03:37.495041: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n"
  20. ]
  21. }
  22. ],
  23. "source": [
  24. "import os\n",
  25. "import numpy as np\n",
  26. "import tensorflow as tf\n",
  27. "import matplotlib\n",
  28. "import matplotlib.pyplot as plt\n",
  29. "import cv2\n",
  30. "import pandas as pd\n",
  31. "import numpy as np\n",
  32. "import mlflow\n",
  33. "from tensorflow.keras import layers, models\n",
  34. "from tensorflow.keras.preprocessing import image_dataset_from_directory\n",
  35. "from tensorflow.keras.models import Model\n",
  36. "from sklearn.metrics import classification_report\n",
  37. "from PIL import Image\n",
  38. "from sklearn.metrics import confusion_matrix\n",
  39. "from sklearn.metrics import ConfusionMatrixDisplay\n",
  40. "from sklearn import __version__ as sklearn_version"
  41. ]
  42. },
  43. {
  44. "cell_type": "code",
  45. "execution_count": 2,
  46. "metadata": {},
  47. "outputs": [
  48. {
  49. "data": {
  50. "text/plain": [
  51. "<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",
  52. " '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",
  53. " 'metrics\",\"display\":true,\"isReordered\":false,\"deleted\":false,\"isGenerated\":true},{\"uuid\":\"1721837579386jrv4pstu\",\"name\":\"System '\n",
  54. " 'metrics\",\"display\":true,\"isReordered\":false,\"deleted\":false,\"isGenerated\":true}],\"viewMaximized\":false,\"runListHidden\":false,\"isAccordionReordered\":false,\"useGroupedValuesInCharts\":true,\"groupBy\":null,\"groupsExpanded\":{},\"autoRefreshEnabled\":false}'}>"
  55. ]
  56. },
  57. "execution_count": 2,
  58. "metadata": {},
  59. "output_type": "execute_result"
  60. }
  61. ],
  62. "source": [
  63. "# Configuration du serveur MLflow\n",
  64. "mlflow_server_uri = \"https://champi.heuzef.com\"\n",
  65. "mlflow.set_tracking_uri(mlflow_server_uri)\n",
  66. "mlflow.set_experiment(\"champi\")"
  67. ]
  68. },
  69. {
  70. "cell_type": "markdown",
  71. "metadata": {},
  72. "source": [
  73. "# Test et Evaluation du Modèle"
  74. ]
  75. },
  76. {
  77. "cell_type": "code",
  78. "execution_count": 3,
  79. "metadata": {},
  80. "outputs": [
  81. {
  82. "name": "stderr",
  83. "output_type": "stream",
  84. "text": [
  85. "/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",
  86. " super().__init__(activity_regularizer=activity_regularizer, **kwargs)\n",
  87. "/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",
  88. " warnings.warn(\n",
  89. "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",
  90. "WARNING:absl:Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.\n"
  91. ]
  92. },
  93. {
  94. "data": {
  95. "text/html": [
  96. "<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",
  97. "</pre>\n"
  98. ],
  99. "text/plain": [
  100. "\u001b[1mModel: \"sequential\"\u001b[0m\n"
  101. ]
  102. },
  103. "metadata": {},
  104. "output_type": "display_data"
  105. },
  106. {
  107. "data": {
  108. "text/html": [
  109. "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
  110. "┃<span style=\"font-weight: bold\"> Layer (type) </span>┃<span style=\"font-weight: bold\"> Output Shape </span>┃<span style=\"font-weight: bold\"> Param # </span>┃\n",
  111. "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
  112. "│ 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",
  113. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  114. "│ 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",
  115. "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
  116. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  117. "│ 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",
  118. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  119. "│ 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",
  120. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  121. "│ 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",
  122. "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
  123. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  124. "│ 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",
  125. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  126. "│ 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",
  127. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  128. "│ 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",
  129. "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
  130. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  131. "│ 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",
  132. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  133. "│ 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",
  134. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  135. "│ 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",
  136. "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
  137. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  138. "│ 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",
  139. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  140. "│ 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",
  141. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  142. "│ 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",
  143. "│ (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">BatchNormalization</span>) │ │ │\n",
  144. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  145. "│ 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",
  146. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  147. "│ 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",
  148. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  149. "│ 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",
  150. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  151. "│ 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",
  152. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  153. "│ 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",
  154. "└─────────────────────────────────┴────────────────────────┴───────────────┘\n",
  155. "</pre>\n"
  156. ],
  157. "text/plain": [
  158. "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\n",
  159. "┃\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",
  160. "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\n",
  161. "│ 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",
  162. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  163. "│ 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",
  164. "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
  165. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  166. "│ 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",
  167. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  168. "│ 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",
  169. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  170. "│ 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",
  171. "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
  172. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  173. "│ 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",
  174. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  175. "│ 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",
  176. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  177. "│ 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",
  178. "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
  179. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  180. "│ 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",
  181. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  182. "│ 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",
  183. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  184. "│ 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",
  185. "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
  186. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  187. "│ 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",
  188. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  189. "│ 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",
  190. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  191. "│ 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",
  192. "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n",
  193. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  194. "│ 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",
  195. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  196. "│ 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",
  197. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  198. "│ 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",
  199. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  200. "│ 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",
  201. "├─────────────────────────────────┼────────────────────────┼───────────────┤\n",
  202. "│ 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",
  203. "└─────────────────────────────────┴────────────────────────┴───────────────┘\n"
  204. ]
  205. },
  206. "metadata": {},
  207. "output_type": "display_data"
  208. },
  209. {
  210. "data": {
  211. "text/html": [
  212. "<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",
  213. "</pre>\n"
  214. ],
  215. "text/plain": [
  216. "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m8,138,457\u001b[0m (31.05 MB)\n"
  217. ]
  218. },
  219. "metadata": {},
  220. "output_type": "display_data"
  221. },
  222. {
  223. "data": {
  224. "text/html": [
  225. "<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",
  226. "</pre>\n"
  227. ],
  228. "text/plain": [
  229. "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m8,136,471\u001b[0m (31.04 MB)\n"
  230. ]
  231. },
  232. "metadata": {},
  233. "output_type": "display_data"
  234. },
  235. {
  236. "data": {
  237. "text/html": [
  238. "<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",
  239. "</pre>\n"
  240. ],
  241. "text/plain": [
  242. "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m1,984\u001b[0m (7.75 KB)\n"
  243. ]
  244. },
  245. "metadata": {},
  246. "output_type": "display_data"
  247. },
  248. {
  249. "data": {
  250. "text/html": [
  251. "<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",
  252. "</pre>\n"
  253. ],
  254. "text/plain": [
  255. "\u001b[1m Optimizer params: \u001b[0m\u001b[38;5;34m2\u001b[0m (12.00 B)\n"
  256. ]
  257. },
  258. "metadata": {},
  259. "output_type": "display_data"
  260. }
  261. ],
  262. "source": [
  263. "# Charger le modèle\n",
  264. "model = tf.keras.models.load_model('../../models/artifacts/yvan_jarvispore.h5')\n",
  265. "\n",
  266. "model.summary()"
  267. ]
  268. },
  269. {
  270. "cell_type": "code",
  271. "execution_count": 27,
  272. "metadata": {},
  273. "outputs": [
  274. {
  275. "name": "stdout",
  276. "output_type": "stream",
  277. "text": [
  278. "conv2d\n",
  279. "batch_normalization\n",
  280. "max_pooling2d\n",
  281. "conv2d_1\n",
  282. "batch_normalization_1\n",
  283. "max_pooling2d_1\n",
  284. "conv2d_2\n",
  285. "batch_normalization_2\n",
  286. "max_pooling2d_2\n",
  287. "conv2d_3\n",
  288. "batch_normalization_3\n",
  289. "max_pooling2d_3\n",
  290. "conv2d_4\n",
  291. "batch_normalization_4\n",
  292. "max_pooling2d_4\n",
  293. "flatten\n",
  294. "dense\n",
  295. "dropout\n",
  296. "dense_1\n"
  297. ]
  298. }
  299. ],
  300. "source": [
  301. "# Vérifier les noms des couches du modèle\n",
  302. "for layer in model.layers:\n",
  303. " print(layer.name)"
  304. ]
  305. },
  306. {
  307. "cell_type": "code",
  308. "execution_count": 28,
  309. "metadata": {},
  310. "outputs": [
  311. {
  312. "name": "stdout",
  313. "output_type": "stream",
  314. "text": [
  315. "[[[[46. 55. 10.]\n",
  316. " [48. 61. 5.]\n",
  317. " [45. 70. 4.]\n",
  318. " ...\n",
  319. " [22. 34. 10.]\n",
  320. " [24. 34. 9.]\n",
  321. " [24. 34. 7.]]\n",
  322. "\n",
  323. " [[46. 63. 8.]\n",
  324. " [43. 68. 2.]\n",
  325. " [44. 71. 0.]\n",
  326. " ...\n",
  327. " [23. 38. 7.]\n",
  328. " [17. 32. 3.]\n",
  329. " [25. 39. 13.]]\n",
  330. "\n",
  331. " [[46. 68. 3.]\n",
  332. " [42. 72. 0.]\n",
  333. " [42. 72. 0.]\n",
  334. " ...\n",
  335. " [17. 31. 6.]\n",
  336. " [18. 30. 6.]\n",
  337. " [18. 30. 6.]]\n",
  338. "\n",
  339. " ...\n",
  340. "\n",
  341. " [[57. 93. 6.]\n",
  342. " [53. 93. 5.]\n",
  343. " [55. 92. 14.]\n",
  344. " ...\n",
  345. " [40. 20. 13.]\n",
  346. " [54. 25. 11.]\n",
  347. " [74. 27. 9.]]\n",
  348. "\n",
  349. " [[53. 91. 6.]\n",
  350. " [57. 94. 16.]\n",
  351. " [53. 84. 8.]\n",
  352. " ...\n",
  353. " [58. 18. 6.]\n",
  354. " [71. 28. 11.]\n",
  355. " [70. 24. 9.]]\n",
  356. "\n",
  357. " [[56. 88. 12.]\n",
  358. " [55. 87. 11.]\n",
  359. " [55. 90. 10.]\n",
  360. " ...\n",
  361. " [70. 39. 19.]\n",
  362. " [76. 42. 17.]\n",
  363. " [72. 37. 15.]]]]\n"
  364. ]
  365. }
  366. ],
  367. "source": [
  368. "img_path = 'Stropharia_ambigua.jpg'\n",
  369. "img = tf.keras.utils.load_img(img_path, target_size=(224, 224))\n",
  370. "img_array = tf.keras.utils.img_to_array(img)\n",
  371. "img_array = np.expand_dims(img_array, axis=0)\n",
  372. "# img_array /= 255.0 <= Ne pas appliquer cette normalisation !\n",
  373. "\n",
  374. "print(img_array)"
  375. ]
  376. },
  377. {
  378. "cell_type": "code",
  379. "execution_count": 29,
  380. "metadata": {},
  381. "outputs": [
  382. {
  383. "name": "stdout",
  384. "output_type": "stream",
  385. "text": [
  386. "\u001b[1m1/1\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 28ms/step\n"
  387. ]
  388. },
  389. {
  390. "data": {
  391. "text/plain": [
  392. "array([[1.39423105e-15, 1.33577138e-09, 1.18861605e-11, 2.34543396e-13,\n",
  393. " 1.46086858e-11, 6.81908577e-13, 1.31949776e-15, 6.21433040e-14,\n",
  394. " 3.58152832e-03, 1.37310572e-05, 9.30511057e-10, 5.02229439e-11,\n",
  395. " 3.02496773e-07, 1.34497757e-09, 1.17063070e-14, 1.64082564e-16,\n",
  396. " 8.56261514e-13, 9.82579225e-14, 1.79859188e-16, 9.96404409e-01,\n",
  397. " 5.06198165e-12, 1.81432788e-12, 1.04054815e-16]], dtype=float32)"
  398. ]
  399. },
  400. "execution_count": 29,
  401. "metadata": {},
  402. "output_type": "execute_result"
  403. }
  404. ],
  405. "source": [
  406. "predictions = model.predict(img_array)\n",
  407. "\n",
  408. "predictions"
  409. ]
  410. },
  411. {
  412. "cell_type": "code",
  413. "execution_count": 30,
  414. "metadata": {},
  415. "outputs": [
  416. {
  417. "data": {
  418. "text/html": [
  419. "<div>\n",
  420. "<style scoped>\n",
  421. " .dataframe tbody tr th:only-of-type {\n",
  422. " vertical-align: middle;\n",
  423. " }\n",
  424. "\n",
  425. " .dataframe tbody tr th {\n",
  426. " vertical-align: top;\n",
  427. " }\n",
  428. "\n",
  429. " .dataframe thead th {\n",
  430. " text-align: right;\n",
  431. " }\n",
  432. "</style>\n",
  433. "<table border=\"1\" class=\"dataframe\">\n",
  434. " <thead>\n",
  435. " <tr style=\"text-align: right;\">\n",
  436. " <th></th>\n",
  437. " <th>0</th>\n",
  438. " </tr>\n",
  439. " </thead>\n",
  440. " <tbody>\n",
  441. " <tr>\n",
  442. " <th>0</th>\n",
  443. " <td>0.040466</td>\n",
  444. " </tr>\n",
  445. " <tr>\n",
  446. " <th>1</th>\n",
  447. " <td>0.040466</td>\n",
  448. " </tr>\n",
  449. " <tr>\n",
  450. " <th>2</th>\n",
  451. " <td>0.040466</td>\n",
  452. " </tr>\n",
  453. " <tr>\n",
  454. " <th>3</th>\n",
  455. " <td>0.040466</td>\n",
  456. " </tr>\n",
  457. " <tr>\n",
  458. " <th>4</th>\n",
  459. " <td>0.040466</td>\n",
  460. " </tr>\n",
  461. " <tr>\n",
  462. " <th>5</th>\n",
  463. " <td>0.040466</td>\n",
  464. " </tr>\n",
  465. " <tr>\n",
  466. " <th>6</th>\n",
  467. " <td>0.040466</td>\n",
  468. " </tr>\n",
  469. " <tr>\n",
  470. " <th>7</th>\n",
  471. " <td>0.040466</td>\n",
  472. " </tr>\n",
  473. " <tr>\n",
  474. " <th>8</th>\n",
  475. " <td>0.040611</td>\n",
  476. " </tr>\n",
  477. " <tr>\n",
  478. " <th>9</th>\n",
  479. " <td>0.040467</td>\n",
  480. " </tr>\n",
  481. " <tr>\n",
  482. " <th>10</th>\n",
  483. " <td>0.040466</td>\n",
  484. " </tr>\n",
  485. " <tr>\n",
  486. " <th>11</th>\n",
  487. " <td>0.040466</td>\n",
  488. " </tr>\n",
  489. " <tr>\n",
  490. " <th>12</th>\n",
  491. " <td>0.040466</td>\n",
  492. " </tr>\n",
  493. " <tr>\n",
  494. " <th>13</th>\n",
  495. " <td>0.040466</td>\n",
  496. " </tr>\n",
  497. " <tr>\n",
  498. " <th>14</th>\n",
  499. " <td>0.040466</td>\n",
  500. " </tr>\n",
  501. " <tr>\n",
  502. " <th>15</th>\n",
  503. " <td>0.040466</td>\n",
  504. " </tr>\n",
  505. " <tr>\n",
  506. " <th>16</th>\n",
  507. " <td>0.040466</td>\n",
  508. " </tr>\n",
  509. " <tr>\n",
  510. " <th>17</th>\n",
  511. " <td>0.040466</td>\n",
  512. " </tr>\n",
  513. " <tr>\n",
  514. " <th>18</th>\n",
  515. " <td>0.040466</td>\n",
  516. " </tr>\n",
  517. " <tr>\n",
  518. " <th>19</th>\n",
  519. " <td>0.109603</td>\n",
  520. " </tr>\n",
  521. " <tr>\n",
  522. " <th>20</th>\n",
  523. " <td>0.040466</td>\n",
  524. " </tr>\n",
  525. " <tr>\n",
  526. " <th>21</th>\n",
  527. " <td>0.040466</td>\n",
  528. " </tr>\n",
  529. " <tr>\n",
  530. " <th>22</th>\n",
  531. " <td>0.040466</td>\n",
  532. " </tr>\n",
  533. " </tbody>\n",
  534. "</table>\n",
  535. "</div>"
  536. ],
  537. "text/plain": [
  538. " 0\n",
  539. "0 0.040466\n",
  540. "1 0.040466\n",
  541. "2 0.040466\n",
  542. "3 0.040466\n",
  543. "4 0.040466\n",
  544. "5 0.040466\n",
  545. "6 0.040466\n",
  546. "7 0.040466\n",
  547. "8 0.040611\n",
  548. "9 0.040467\n",
  549. "10 0.040466\n",
  550. "11 0.040466\n",
  551. "12 0.040466\n",
  552. "13 0.040466\n",
  553. "14 0.040466\n",
  554. "15 0.040466\n",
  555. "16 0.040466\n",
  556. "17 0.040466\n",
  557. "18 0.040466\n",
  558. "19 0.109603\n",
  559. "20 0.040466\n",
  560. "21 0.040466\n",
  561. "22 0.040466"
  562. ]
  563. },
  564. "execution_count": 30,
  565. "metadata": {},
  566. "output_type": "execute_result"
  567. }
  568. ],
  569. "source": [
  570. "score = tf.nn.softmax(predictions[0])\n",
  571. "\n",
  572. "pd.DataFrame(tf.nn.softmax(predictions[0]))"
  573. ]
  574. },
  575. {
  576. "cell_type": "code",
  577. "execution_count": 31,
  578. "metadata": {},
  579. "outputs": [
  580. {
  581. "name": "stdout",
  582. "output_type": "stream",
  583. "text": [
  584. "\u001b[1m1/1\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m0s\u001b[0m 43ms/step\n",
  585. "Classe prédite : 19\n"
  586. ]
  587. }
  588. ],
  589. "source": [
  590. "# Faire la prédiction\n",
  591. "predictions = model.predict(img_array)\n",
  592. "\n",
  593. "# Afficher la classe prédite (ou la distribution des probabilités)\n",
  594. "predicted_class = np.argmax(predictions[0]) # Si le modèle a une sortie par classe\n",
  595. "print(f'Classe prédite : {predicted_class}')"
  596. ]
  597. }
  598. ],
  599. "metadata": {
  600. "kernelspec": {
  601. "display_name": "jarvis_env",
  602. "language": "python",
  603. "name": "python3"
  604. },
  605. "language_info": {
  606. "codemirror_mode": {
  607. "name": "ipython",
  608. "version": 3
  609. },
  610. "file_extension": ".py",
  611. "mimetype": "text/x-python",
  612. "name": "python",
  613. "nbconvert_exporter": "python",
  614. "pygments_lexer": "ipython3",
  615. "version": "3.11.9"
  616. }
  617. },
  618. "nbformat": 4,
  619. "nbformat_minor": 2
  620. }