149 lines
147 KiB
Plaintext
149 lines
147 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"import numpy as np\n",
|
|||
|
"import PIL.Image\n",
|
|||
|
"import glob\n",
|
|||
|
"import os"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"IMAGE_SIZE = (150, 400, 3)\n",
|
|||
|
"DATASET_PATH = \"./dataset/\"\n",
|
|||
|
"DATASET_PATH = os.path.abspath(DATASET_PATH)\n",
|
|||
|
"CLASSES = glob.glob(f\"{DATASET_PATH}/*\")\n",
|
|||
|
"CLASSES = list(map(lambda f: f.split(\"/\")[-1], CLASSES))\n",
|
|||
|
"\n",
|
|||
|
"print(DATASET_PATH)\n",
|
|||
|
"print(CLASSES)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"def load_data():\n",
|
|||
|
" # Récupération des fichiers\n",
|
|||
|
" files = glob.glob(f\"{DATASET_PATH}/**/*.jpg\", recursive = True)\n",
|
|||
|
"\n",
|
|||
|
" # Initialise les structures de données\n",
|
|||
|
" x = np.zeros((len(files), *IMAGE_SIZE))\n",
|
|||
|
" y = np.zeros((len(files), 1))\n",
|
|||
|
"\n",
|
|||
|
" for i, path in enumerate(files):\n",
|
|||
|
" # Lecture de l'image\n",
|
|||
|
" img = PIL.Image.open(path)\n",
|
|||
|
" \n",
|
|||
|
" # Remplissage de la variable x\n",
|
|||
|
" x[i] = np.asarray(img)\n",
|
|||
|
"\n",
|
|||
|
" # On récupère l'index dans le path\n",
|
|||
|
" class_label = path.split(\"/\")[-2]\n",
|
|||
|
"\n",
|
|||
|
" # On récupère le numéro de la classe à partir du string\n",
|
|||
|
" class_label = CLASSES.index(class_label)\n",
|
|||
|
" \n",
|
|||
|
" # Remplissage de la variable y\n",
|
|||
|
" y[i] = class_label\n",
|
|||
|
"\n",
|
|||
|
" return x, y"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"x, y = load_data()\n",
|
|||
|
"x = x / 255"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 11,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stderr",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
|
|||
|
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
|
|||
|
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
|
|||
|
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
|
|||
|
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
|
|||
|
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
|
|||
|
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
|
|||
|
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
|
|||
|
"Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1gAAAHRCAYAAAB3vxiRAAAAOXRFWHRTb2Z0d2FyZQBNYX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Y/66zgzq1Ek3m0ooAznKb1wRIlHrWbwBwoqILCpqnC98C/4u4emEhL8ZU4Ua8ioX8mgDrp9Aqj5T/sOpJ1B9MvNGMKMwiJK5gq21vyAW+gjZsrcLzSw7pl//RWhLsMPeRGeFLJrL0OBHHCY8YZoJdRxPkZtB/6ocMVOw+JKHRUJC5ac0TVNWliJNM1MiFxJWRKUxsD6wqK5qs/Sfk4X+aBcKPdEidBIMr4eE52nbJY6BT4cwtTtH1V50TBEffsh++yUG1uolRkNB4ykvvwhF6KdJBFtCwjpIthAkX9CZDweQ1ZrfpnLWM/znO86bGQyll4WMoM+FJpaN0VvQeXbHzpbRc+Um3Bx8NZ+iV5w+4FkhZTkTuVQ5kEMjXCxYb4m8SUhIyLBIh2m7vB0TElCJDKySyomb4N8lbK+Cy5dzrl67L/u1A5bVHSNhGcRC6ky7lTjHl4ImtDLDFrcQutdcJvzrr/nGCuVjgdBWuNmaXsjfmu+FAEhnpY+JLhSCLM2LbZuPmUpuxkMIpNREy3KtcmX5UeiOt5ZQtRY34ObvGLcNzauSsz1bP0Dfd8g+mh7CD8tuGLbMp1oq/KyHXkXbelu8zdIhwZ7KzBT+dT+39htYLSXypvKSEsoYivdKzBRyPUqjoFXEE7piGSuk164ptlDqIeNrPVOFdMXKRiJzqEQGVkJlZpyVE98P4N4KWMfGghd6jMo9n2Z55AqJr4nwWZP8jklC5Lu0BlaeEFUvbmAtFP41l2VgjRbcCmvGwBptb
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 864x504 with 9 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"needs_background": "light"
|
|||
|
},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"%matplotlib inline\n",
|
|||
|
"\n",
|
|||
|
"# Randomisation des indices et affichage de 9 images alétoires de la base d'apprentissage\n",
|
|||
|
"indices = np.arange(x.shape[0])\n",
|
|||
|
"np.random.shuffle(indices)\n",
|
|||
|
"\n",
|
|||
|
"plt.figure(figsize=(12, 7))\n",
|
|||
|
"for i in range(0, 9):\n",
|
|||
|
" plt.subplot(3, 3, i+1)\n",
|
|||
|
" plt.title(CLASSES[int(y[i])])\n",
|
|||
|
" plt.imshow(x[i])\n",
|
|||
|
"\n",
|
|||
|
"plt.tight_layout()\n",
|
|||
|
"plt.show()"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"kernelspec": {
|
|||
|
"display_name": ".env",
|
|||
|
"language": "python",
|
|||
|
"name": ".env"
|
|||
|
},
|
|||
|
"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.8.10"
|
|||
|
},
|
|||
|
"orig_nbformat": 4
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 2
|
|||
|
}
|