diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..ede0629cc3c37d22103a581d4043ce9f8f162109 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +numpy +tensorflow +matplotlib +keras +pandas \ No newline at end of file diff --git a/src/PC/sign_language_detector.ipynb b/src/PC/sign_language_detector.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..576434268599c5f3884f0c29649da02ca72baa31 --- /dev/null +++ b/src/PC/sign_language_detector.ipynb @@ -0,0 +1,170 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# SIGN LANGUAGE TRANSLATOR" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import tensorflow as tf\n", + "import matplotlib.pyplot as plt\n", + "import pandas as pd\n", + "import random\n", + "\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Get data and label from train and test dataset." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "train_path = \"dataset/sign_mnist_train.csv\"\n", + "test_path = \"dataset/sign_mnist_test.csv\"\n", + "\n", + "train = pd.read_csv(train_path)\n", + "test = pd.read_csv(test_path)\n", + "\n", + "train_data = np.array(train)[:, 1:]\n", + "train_label = np.array(train)[:, 0]\n", + "\n", + "test_data = np.array(test)[:, 1:]\n", + "test_label = np.array(test)[:, 0]\n", + "\n", + "train_data = np.reshape(train_data, (-1, 28, 28, 1))\n", + "test_data = np.reshape(test_data, (-1, 28, 28, 1))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Show random image from train dataset." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "alphabet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n", + "\n", + "rand_i = random.randint(1, train_data.shape[0])\n", + "img = train_data[rand_i]\n", + "print(f\"Letter : {alphabet[train_label[rand_i]]}\")\n", + "plt.imshow(img, cmap='gray')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# CNN\n", + "Entrainement et evaluation du modèle." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from tensorflow.keras.models import Sequential\n", + "from tensorflow.keras.layers import Conv2D, Dense, MaxPool2D, Flatten, Rescaling, Dropout\n", + "from tensorflow.keras.losses import SparseCategoricalCrossentropy\n", + "\n", + "\n", + "CLASS_COUNT = int(np.max(train_label) + 1)\n", + "INPUT_SHAPE = train_data.shape[1]\n", + "BATCH_SIZE = 32#train_data.shape[0] // 4\n", + "EPOCHS = 15\n", + "\n", + "train_label = tf.keras.utils.to_categorical(train_label, CLASS_COUNT)\n", + "test_label = tf.keras.utils.to_categorical(test_label, CLASS_COUNT)\n", + "\n", + "model = Sequential()\n", + "model.add(Rescaling(1./255, input_shape=(INPUT_SHAPE, INPUT_SHAPE, 1)))\n", + "model.add(Conv2D(filters=32, kernel_size=3, padding=\"same\", activation='relu'))\n", + "model.add(MaxPool2D())\n", + "model.add(Conv2D(filters=64, kernel_size=3, padding=\"same\", activation='relu'))\n", + "model.add(MaxPool2D())\n", + "model.add(Flatten())\n", + "model.add(Dropout(0.5))\n", + "model.add(Dense(CLASS_COUNT, activation=\"softmax\"))\n", + "model.summary()\n", + "\n", + "model.compile(optimizer='adam', loss=\"categorical_crossentropy\", metrics=['accuracy'])\n", + "history = model.fit(train_data, train_label, batch_size=BATCH_SIZE, epochs=EPOCHS)\n", + "\n", + "plt.plot(history.history[\"loss\"])\n", + "plt.xlabel(\"Epochs\")\n", + "plt.ylabel(\"Loss value\")\n", + "plt.title(\"Evolution of Loss\")\n", + "plt.show()\n", + "\n", + "plt.plot(history.history[\"accuracy\"])\n", + "plt.xlabel(\"Epochs\")\n", + "plt.ylabel(\"Accuracy\")\n", + "plt.title(\"Evolution of Accuracy\")\n", + "plt.show()\n", + "\n", + "evaluate = model.evaluate(test_data, test_label, verbose=2) # ~58%\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Export as Keras model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "model.save('sign_model.keras')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "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.8" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/src/PC/sign_model.keras b/src/PC/sign_model.keras new file mode 100644 index 0000000000000000000000000000000000000000..6911691ac48bfb0e01cee948c4ba89270fbe1b38 Binary files /dev/null and b/src/PC/sign_model.keras differ