{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Transfer Learning approach with the Tensorflow EfficientNet model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import des librairies" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2024-09-30 11:38:22.779561: 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-09-30 11:38:22.783091: 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-09-30 11:38:22.794062: 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-09-30 11:38:22.813315: 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-09-30 11:38:22.819202: 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-09-30 11:38:22.834455: 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-09-30 11:38:23.921894: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "tensorflow version 2.17.0\n", "Num GPUs Available: 0\n" ] } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "import os\n", "import cv2\n", "import pathlib\n", "import itertools\n", "import random\n", "import time\n", "import setuptools\n", "import datetime\n", "\n", "from PIL import Image\n", "\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt\n", "from matplotlib import cm\n", "\n", "from sklearn import metrics\n", "from sklearn.metrics import confusion_matrix\n", "\n", "import tensorflow as tf\n", "from tensorflow.keras.models import Sequential, Model\n", "from tensorflow.keras.utils import to_categorical\n", "from tensorflow.keras.applications import EfficientNetB1\n", "from tensorflow.keras import layers\n", "from tensorflow.keras.layers import Dense, Activation, Input\n", "from tensorflow.keras.layers import Dropout\n", "from tensorflow.keras.layers import Flatten\n", "from tensorflow.keras.layers import Conv2D\n", "from tensorflow.keras.layers import MaxPooling2D\n", "from tensorflow.keras.layers import GlobalAveragePooling2D\n", "from tensorflow.keras.callbacks import ReduceLROnPlateau\n", "from tensorflow.keras.callbacks import EarlyStopping\n", "from tensorflow.keras.callbacks import TensorBoard\n", "\n", "print(\"tensorflow version\",tf.__version__)\n", "print(\"Num GPUs Available: \", len(tf.config.list_physical_devices('GPU')))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Récupération des datas" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "16 classes\n" ] }, { "data": { "text/html": [ "
\n", " | name | \n", "
---|---|
id | \n", "\n", " |
42 | \n", "Trametes versicolor | \n", "
53 | \n", "Stropharia ambigua | \n", "
267 | \n", "Fuligo septica | \n", "
330 | \n", "Cantharellus cinnabarinus | \n", "
344 | \n", "Boletus edulis | \n", "
362 | \n", "Amanita velosa | \n", "
373 | \n", "Amanita muscaria | \n", "
382 | \n", "Amanita bisporigera | \n", "
401 | \n", "Agaricus augustus | \n", "
1174 | \n", "Ceratiomyxa fruticulosa | \n", "
1540 | \n", "Boletinellus merulioides | \n", "
15162 | \n", "Bolbitius titubans | \n", "
4920 | \n", "Craterellus fallax | \n", "
939 | \n", "Mycena haematopus | \n", "
407 | \n", "Ganoderma oregonense | \n", "
271 | \n", "Flammulina velutipes | \n", "