From 5b6933d16263cdda6d3667b18b5679df47cba91a Mon Sep 17 00:00:00 2001 From: praveenchalla Date: Thu, 3 Oct 2024 22:03:05 +0530 Subject: [PATCH 1/4] Drowsiness Detection --- .../Drowsiness Detection(1).ipynb | 861 ++++++++++++++++++ 1 file changed, 861 insertions(+) create mode 100644 Neural Networks/Drowsiness detection/Drowsiness Detection(1).ipynb diff --git a/Neural Networks/Drowsiness detection/Drowsiness Detection(1).ipynb b/Neural Networks/Drowsiness detection/Drowsiness Detection(1).ipynb new file mode 100644 index 00000000..f007bf40 --- /dev/null +++ b/Neural Networks/Drowsiness detection/Drowsiness Detection(1).ipynb @@ -0,0 +1,861 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "ffaddfd9", + "metadata": {}, + "source": [ + "# Install and import Dependencied" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "97c19bbd", + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: torch in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (2.2.2)\n", + "Requirement already satisfied: torchvision in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (0.17.2)\n", + "Requirement already satisfied: torchaudio in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (2.2.2)\n", + "Requirement already satisfied: filelock in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (3.9.0)\n", + "Requirement already satisfied: typing-extensions>=4.8.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (4.9.0)\n", + "Requirement already satisfied: sympy in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (1.11.1)\n", + "Requirement already satisfied: networkx in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (2.8.4)\n", + "Requirement already satisfied: jinja2 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (3.1.2)\n", + "Requirement already satisfied: fsspec in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (2023.4.0)\n", + "Requirement already satisfied: numpy in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torchvision) (1.24.3)\n", + "Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torchvision) (10.3.0)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from jinja2->torch) (2.1.1)\n", + "Requirement already satisfied: mpmath>=0.19 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from sympy->torch) (1.2.1)\n" + ] + } + ], + "source": [ + "!pip install torch torchvision torchaudio" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "4d3b462d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "fatal: destination path 'yolov5' already exists and is not an empty directory.\r\n" + ] + } + ], + "source": [ + "!git clone https://github.com/ultralytics/yolov5" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "bcd117c6", + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: gitpython>=3.1.30 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 5)) (3.1.41)\n", + "Requirement already satisfied: matplotlib>=3.3 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 6)) (3.7.1)\n", + "Requirement already satisfied: numpy>=1.23.5 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 7)) (1.24.3)\n", + "Requirement already satisfied: opencv-python>=4.1.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 8)) (4.9.0.80)\n", + "Requirement already satisfied: Pillow>=10.0.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 9)) (10.3.0)\n", + "Requirement already satisfied: psutil in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 10)) (5.9.0)\n", + "Requirement already satisfied: PyYAML>=5.3.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 11)) (6.0)\n", + "Requirement already satisfied: requests>=2.23.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 12)) (2.29.0)\n", + "Requirement already satisfied: scipy>=1.4.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 13)) (1.10.1)\n", + "Requirement already satisfied: thop>=0.1.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 14)) (0.1.1.post2209072238)\n", + "Requirement already satisfied: torch>=1.8.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 15)) (2.2.2)\n", + "Requirement already satisfied: torchvision>=0.9.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 16)) (0.17.2)\n", + "Requirement already satisfied: tqdm>=4.64.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 17)) (4.65.0)\n", + "Requirement already satisfied: ultralytics>=8.0.232 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 18)) (8.1.44)\n", + "Requirement already satisfied: pandas>=1.1.4 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 27)) (1.5.3)\n", + "Requirement already satisfied: seaborn>=0.11.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 28)) (0.12.2)\n", + "Requirement already satisfied: setuptools>=65.5.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 42)) (67.8.0)\n", + "Requirement already satisfied: gitdb<5,>=4.0.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from gitpython>=3.1.30->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 5)) (4.0.11)\n", + "Requirement already satisfied: contourpy>=1.0.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from matplotlib>=3.3->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 6)) (1.0.5)\n", + "Requirement already satisfied: cycler>=0.10 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from matplotlib>=3.3->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 6)) (0.11.0)\n", + "Requirement already satisfied: fonttools>=4.22.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from matplotlib>=3.3->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 6)) (4.25.0)\n", + "Requirement already satisfied: kiwisolver>=1.0.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from matplotlib>=3.3->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 6)) (1.4.4)\n", + "Requirement already satisfied: packaging>=20.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from matplotlib>=3.3->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 6)) (23.0)\n", + "Requirement already satisfied: pyparsing>=2.3.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from matplotlib>=3.3->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 6)) (3.0.9)\n", + "Requirement already satisfied: python-dateutil>=2.7 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from matplotlib>=3.3->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 6)) (2.8.2)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from requests>=2.23.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 12)) (2.0.4)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from requests>=2.23.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 12)) (3.4)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from requests>=2.23.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 12)) (1.26.16)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from requests>=2.23.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 12)) (2023.7.22)\n", + "Requirement already satisfied: filelock in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch>=1.8.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 15)) (3.9.0)\n", + "Requirement already satisfied: typing-extensions>=4.8.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch>=1.8.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 15)) (4.9.0)\n", + "Requirement already satisfied: sympy in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch>=1.8.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 15)) (1.11.1)\n", + "Requirement already satisfied: networkx in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch>=1.8.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 15)) (2.8.4)\n", + "Requirement already satisfied: jinja2 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch>=1.8.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 15)) (3.1.2)\n", + "Requirement already satisfied: fsspec in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch>=1.8.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 15)) (2023.4.0)\n", + "Requirement already satisfied: py-cpuinfo in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from ultralytics>=8.0.232->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 18)) (8.0.0)\n", + "Requirement already satisfied: pytz>=2020.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from pandas>=1.1.4->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 27)) (2022.7)\n", + "Requirement already satisfied: smmap<6,>=3.0.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from gitdb<5,>=4.0.1->gitpython>=3.1.30->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 5)) (5.0.1)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: six>=1.5 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib>=3.3->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 6)) (1.16.0)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from jinja2->torch>=1.8.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 15)) (2.1.1)\n", + "Requirement already satisfied: mpmath>=0.19 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from sympy->torch>=1.8.0->-r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt (line 15)) (1.2.1)\n" + ] + } + ], + "source": [ + "!cd yolov5 & pip install -r /Users/praveenchalla/Desktop/machine_Learning/yolov5/requirements.txt" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "469014ef", + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: GitPython in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (3.1.41)\n", + "Requirement already satisfied: gitdb<5,>=4.0.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from GitPython) (4.0.11)\n", + "Requirement already satisfied: smmap<6,>=3.0.1 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from gitdb<5,>=4.0.1->GitPython) (5.0.1)\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install --timeout=60 GitPython" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "0577ef0c", + "metadata": {}, + "outputs": [], + "source": [ + "import torch \n", + "from matplotlib import pyplot as plt\n", + "import numpy as np\n", + "import cv2" + ] + }, + { + "cell_type": "markdown", + "id": "01eb892c", + "metadata": {}, + "source": [ + "# Load Model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f78a7ee4", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "fb476212", + "metadata": {}, + "outputs": [], + "source": [ + "rm -rf /Users/praveenchalla/.cache/torch/hub" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "ce921740", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Downloading: \"https://github.com/ultralytics/yolov5/zipball/master\" to /Users/praveenchalla/.cache/torch/hub/master.zip\n", + "YOLOv5 🚀 2024-4-14 Python-3.11.3 torch-2.2.2 CPU\n", + "\n", + "Fusing layers... \n", + "YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients, 16.4 GFLOPs\n", + "Adding AutoShape... \n" + ] + } + ], + "source": [ + "model =torch.hub.load('ultralytics/yolov5','yolov5s')" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "7eb8a6c2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "AutoShape(\n", + " (model): DetectMultiBackend(\n", + " (model): DetectionModel(\n", + " (model): Sequential(\n", + " (0): Conv(\n", + " (conv): Conv2d(3, 32, kernel_size=(6, 6), stride=(2, 2), padding=(2, 2))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (1): Conv(\n", + " (conv): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (2): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(64, 32, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(64, 32, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(32, 32, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (3): Conv(\n", + " (conv): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (4): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(128, 64, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(128, 64, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (5): Conv(\n", + " (conv): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (6): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (1): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " (2): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (7): Conv(\n", + " (conv): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (8): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(512, 512, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (9): SPPF(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): MaxPool2d(kernel_size=5, stride=1, padding=2, dilation=1, ceil_mode=False)\n", + " )\n", + " (10): Conv(\n", + " (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (11): Upsample(scale_factor=2.0, mode='nearest')\n", + " (12): Concat()\n", + " (13): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (14): Conv(\n", + " (conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (15): Upsample(scale_factor=2.0, mode='nearest')\n", + " (16): Concat()\n", + " (17): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (18): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (19): Concat()\n", + " (20): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (21): Conv(\n", + " (conv): Conv2d(256, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (22): Concat()\n", + " (23): C3(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv3): Conv(\n", + " (conv): Conv2d(512, 512, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (m): Sequential(\n", + " (0): Bottleneck(\n", + " (cv1): Conv(\n", + " (conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " (cv2): Conv(\n", + " (conv): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", + " (act): SiLU(inplace=True)\n", + " )\n", + " )\n", + " )\n", + " )\n", + " (24): Detect(\n", + " (m): ModuleList(\n", + " (0): Conv2d(128, 255, kernel_size=(1, 1), stride=(1, 1))\n", + " (1): Conv2d(256, 255, kernel_size=(1, 1), stride=(1, 1))\n", + " (2): Conv2d(512, 255, kernel_size=(1, 1), stride=(1, 1))\n", + " )\n", + " )\n", + " )\n", + " )\n", + " )\n", + ")" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "model" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "d0a69a37", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: torch in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (2.2.2)\n", + "Requirement already satisfied: torchvision in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (0.17.2)\n", + "Requirement already satisfied: filelock in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (3.9.0)\n", + "Requirement already satisfied: typing-extensions>=4.8.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (4.9.0)\n", + "Requirement already satisfied: sympy in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (1.11.1)\n", + "Requirement already satisfied: networkx in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (2.8.4)\n", + "Requirement already satisfied: jinja2 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (3.1.2)\n", + "Requirement already satisfied: fsspec in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torch) (2023.4.0)\n", + "Requirement already satisfied: numpy in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torchvision) (1.24.3)\n", + "Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from torchvision) (10.3.0)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from jinja2->torch) (2.1.1)\n", + "Requirement already satisfied: mpmath>=0.19 in /Users/praveenchalla/anaconda3/lib/python3.11/site-packages (from sympy->torch) (1.2.1)\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + } + ], + "source": [ + "pip install --upgrade torch torchvision" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "136d7cc8", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "pip install --upgrade ultralytics" + ] + }, + { + "cell_type": "markdown", + "id": "14be5e35", + "metadata": {}, + "source": [ + "\n", + "# Make detection with images" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "200e7d34", + "metadata": {}, + "outputs": [], + "source": [ + "img='https://newsmeter.in/h-upload/2023/07/26/351034-whatsapp-image-2023-07-26-at-122903-pm.webp'" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "93ef8e0f", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "image 1/1: 1272x1280 11 persons, 22 cars, 7 motorcycles, 6 buss, 4 trucks, 1 umbrella\n", + "Speed: 876.0ms pre-process, 545.2ms inference, 11.8ms NMS per image at shape (1, 3, 640, 640)\n" + ] + } + ], + "source": [ + "results=model(img)\n", + "results.print()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4b03131b", + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "plt.imshow(np.squeeze(results.render()))\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a955178e", + "metadata": {}, + "outputs": [], + "source": [ + "plt.imshow(np.squeeze(results.render()))" + ] + }, + { + "cell_type": "markdown", + "id": "3f5dd0dd", + "metadata": {}, + "source": [ + "# Real time detection\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38df6781", + "metadata": {}, + "outputs": [], + "source": [ + "import cv2\n", + "cap=cv2.VideoCapture(0)\n", + "while cap.isOpened():\n", + " ret,frame = cap.read()\n", + " \n", + " #Make detections\n", + " results=model(frame)\n", + " \n", + " cv2.imshow('YOLO',np.squeeze(results.render()))\n", + " \n", + " \n", + " if cv2.waitKey(10) & 0xFF == ord('q'):\n", + " break\n", + "cap.release()\n", + "cv2.destroyAllWindows()" + ] + }, + { + "cell_type": "markdown", + "id": "a8fee930", + "metadata": {}, + "source": [ + "# Train from scrach" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ff83e1b7", + "metadata": {}, + "outputs": [], + "source": [ + "import uuid #Unique identify\n", + "import os \n", + "import time #taking time for each bit\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a7b0adac", + "metadata": {}, + "outputs": [], + "source": [ + "IMAGES_PATH=os.path.join('data','images') #/data/images\n", + "labels=['awake','drowsy'] #two classes\n", + "number_imgs=20" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a471c356", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "cap = cv2.VideoCapture(0)\n", + "#loop through labels\n", + "for label in labels:\n", + " print('Collecting images for {}'.format(label))\n", + " time.sleep(5)\n", + " \n", + " #loop through images\n", + " for img_num in range(number_imgs):\n", + " print('Collecting images for {}, image number {}'.format(label,img_num))\n", + " \n", + " #webcam feed\n", + " ret, frame=cap.read()\n", + " \n", + " #Naming out image path\n", + " imgname = os.path.join(IMAGES_PATH,label+','+str(uuid.uuid1())+\".jpg\")\n", + " \n", + " #writes out image to file\n", + " cv2.imwrite(imgname,frame)\n", + " \n", + " #render to the screen\n", + " cv2.imshow('Image Collection',frame)\n", + " \n", + " # 2 second delay between captures\n", + " time.sleep(3)\n", + " \n", + " if cv2.waitKey(10) & 0xFF == ord('q'):\n", + " break\n", + "cap.release()\n", + "cv2.destroyAllWindows()\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0c235b43", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "377eb5a5", + "metadata": {}, + "outputs": [], + "source": [ + "print(os.path.join(IMAGES_PATH,labels[0]+'.'+str(uuid.uuid1()) + '.jpg'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "800d8629", + "metadata": {}, + "outputs": [], + "source": [ + "labels[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bbb59cae", + "metadata": {}, + "outputs": [], + "source": [ + "for label in labels:\n", + " print('Collecting images for {}'.format(label))\n", + " for img_num in range(number_imgs):\n", + " print('Collecting images for {}, image number {}'.format(label,img_num))\n", + " imgname = os.path.join(IMAGES_PATH,label+'.'+str(uuid.uuid1())+\".jpg\")\n", + " print(imgname)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d1caf6c8", + "metadata": {}, + "outputs": [], + "source": [ + "!git clone https://github.com/HumanSignal/labelImg" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "68c2b418", + "metadata": {}, + "outputs": [], + "source": [ + "!pip install pyqt5 lxml --upgrade\n", + "!cd labelImg && pyrcc5 -o libs/resources.py resources.qrc" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0c78597b", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "!cd yolov5 && python train.py --img 320 --batch 16 --epochs 5 --data dataset.yaml --weights yolov5s.pt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "24d2c865", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5646cd8", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 397915cdb57587eb953435532bbb1fe189ad34c4 Mon Sep 17 00:00:00 2001 From: praveenchalla Date: Thu, 3 Oct 2024 22:21:48 +0530 Subject: [PATCH 2/4] Making slight changes --- .../Drowsiness detection/Drowsiness Detection(1).ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Neural Networks/Drowsiness detection/Drowsiness Detection(1).ipynb b/Neural Networks/Drowsiness detection/Drowsiness Detection(1).ipynb index f007bf40..317701b1 100644 --- a/Neural Networks/Drowsiness detection/Drowsiness Detection(1).ipynb +++ b/Neural Networks/Drowsiness detection/Drowsiness Detection(1).ipynb @@ -585,7 +585,7 @@ "metadata": {}, "source": [ "\n", - "# Make detection with images" + "# Make detection with images checking using a image but we can add any vedio in this link it will detect" ] }, { @@ -677,7 +677,7 @@ "id": "a8fee930", "metadata": {}, "source": [ - "# Train from scrach" + "# Train from scrach and Test " ] }, { From 9383bb2178e4ec9314a22e5c3596a199260d2777 Mon Sep 17 00:00:00 2001 From: praveenchalla Date: Thu, 3 Oct 2024 23:52:08 +0530 Subject: [PATCH 3/4] Added Read me File with results --- Neural Networks/.DS_Store | Bin 0 -> 6148 bytes .../Drowsiness detection/Drowsiness_README.md | 92 ++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 Neural Networks/.DS_Store create mode 100644 Neural Networks/Drowsiness detection/Drowsiness_README.md diff --git a/Neural Networks/.DS_Store b/Neural Networks/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5f15b6c4ddaf226def7de879efad33e6d22586b9 GIT binary patch literal 6148 zcmeHK!AiqG5S?wSO({YT6?$CoTClcNC|*LXKVU=;Dzz~IgEd>4lpIPSXZ<0+#P4xt zcUvgNtB9R}nK!#Lv&lZlZUz9va1opUGyuRsB^2Zo2u&A;N;X*_qT(6}L=Z!Wm=rAZ z7pLgmn=pboD9Ee1k{=~nD!ff1VUZ^;oL~%IR1yK-U%KdE=2Pzw?MI0o$)-wU8 z=G4ZG)^gcB9kgYy-(9uka?tIxWxsc}TGgDxqvP|d@yqlzR&R!6LHi;(FtD-j8;>1k zfEi#0n1Nkoz}^u~eOC$KeKP~hz>f^j`5;jVU5mLveRQDFEdXK#r?sF@y#&=ri>}4o zAVyGxDMd7;!nPQ~l;ga#d9KCWpeYAon-5{1yl!5Eembr%bvg*wAX{dD8Q5l^Y=#ZG z|1a^ADQxn$OL)W#Fa!UL0Z|!wqakj}-mTxZM|Z76eMBXpyqp{q^tXNja6sosO9xF{ bl8 Date: Fri, 4 Oct 2024 00:01:34 +0530 Subject: [PATCH 4/4] Add comments --- Neural Networks/Drowsiness detection/Drowsiness_README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Neural Networks/Drowsiness detection/Drowsiness_README.md b/Neural Networks/Drowsiness detection/Drowsiness_README.md index d87db3c7..c5fa3ad3 100644 --- a/Neural Networks/Drowsiness detection/Drowsiness_README.md +++ b/Neural Networks/Drowsiness detection/Drowsiness_README.md @@ -3,8 +3,7 @@ This repository consists of a drowsiness detection based on YOLOv5 implementation. You can reach the base repo [here](https://github.com/ultralytics/yolov5) - -## 1. Prepared Custom Data Set +## 1. Prepared Custom Data Set Even Using real Time data A custom data set was prepared for this project. Videos were taken from 21 different people in scenarios that could happen while driving. Three different categories were discussed in these videos: normal, yawning and head position. Various light conditions and the use of glasses were taken into account. A total of 63 videos were obtained and labeling was done according to the method to be used.