{ "cells": [ { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "view-in-github" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "id": "WvRyifGfTQQ2" }, "source": [ "# license plate object detection using YOLOv8" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### dataset : https://huggingface.co/datasets/keremberke/license-plate-object-detection\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "yVFdjWeRS8jh", "outputId": "6a9c0a99-5dc3-4705-aa8b-14ea3db5c04c" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting datasets\n", " Downloading datasets-3.2.0-py3-none-any.whl.metadata (20 kB)\n", "Collecting ultralytics\n", " Downloading ultralytics-8.3.68-py3-none-any.whl.metadata (35 kB)\n", "Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from datasets) (3.17.0)\n", "Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.11/dist-packages (from datasets) (1.26.4)\n", "Requirement already satisfied: pyarrow>=15.0.0 in /usr/local/lib/python3.11/dist-packages (from datasets) (17.0.0)\n", "Collecting dill<0.3.9,>=0.3.0 (from datasets)\n", " Downloading dill-0.3.8-py3-none-any.whl.metadata (10 kB)\n", "Requirement already satisfied: pandas in /usr/local/lib/python3.11/dist-packages (from datasets) (2.2.2)\n", "Requirement already satisfied: requests>=2.32.2 in /usr/local/lib/python3.11/dist-packages (from datasets) (2.32.3)\n", "Requirement already satisfied: tqdm>=4.66.3 in /usr/local/lib/python3.11/dist-packages (from datasets) (4.67.1)\n", "Collecting xxhash (from datasets)\n", " Downloading xxhash-3.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (12 kB)\n", "Collecting multiprocess<0.70.17 (from datasets)\n", " Downloading multiprocess-0.70.16-py311-none-any.whl.metadata (7.2 kB)\n", "Collecting fsspec<=2024.9.0,>=2023.1.0 (from fsspec[http]<=2024.9.0,>=2023.1.0->datasets)\n", " Downloading fsspec-2024.9.0-py3-none-any.whl.metadata (11 kB)\n", "Requirement already satisfied: aiohttp in /usr/local/lib/python3.11/dist-packages (from datasets) (3.11.11)\n", "Requirement already satisfied: huggingface-hub>=0.23.0 in /usr/local/lib/python3.11/dist-packages (from datasets) (0.27.1)\n", "Requirement already satisfied: packaging in /usr/local/lib/python3.11/dist-packages (from datasets) (24.2)\n", "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.11/dist-packages (from datasets) (6.0.2)\n", "Requirement already satisfied: matplotlib>=3.3.0 in /usr/local/lib/python3.11/dist-packages (from ultralytics) (3.10.0)\n", "Requirement already satisfied: opencv-python>=4.6.0 in /usr/local/lib/python3.11/dist-packages (from ultralytics) (4.10.0.84)\n", "Requirement already satisfied: pillow>=7.1.2 in /usr/local/lib/python3.11/dist-packages (from ultralytics) (11.1.0)\n", "Requirement already satisfied: scipy>=1.4.1 in /usr/local/lib/python3.11/dist-packages (from ultralytics) (1.13.1)\n", "Requirement already satisfied: torch>=1.8.0 in /usr/local/lib/python3.11/dist-packages (from ultralytics) (2.5.1+cu121)\n", "Requirement already satisfied: torchvision>=0.9.0 in /usr/local/lib/python3.11/dist-packages (from ultralytics) (0.20.1+cu121)\n", "Requirement already satisfied: psutil in /usr/local/lib/python3.11/dist-packages (from ultralytics) (5.9.5)\n", "Requirement already satisfied: py-cpuinfo in /usr/local/lib/python3.11/dist-packages (from ultralytics) (9.0.0)\n", "Requirement already satisfied: seaborn>=0.11.0 in /usr/local/lib/python3.11/dist-packages (from ultralytics) (0.13.2)\n", "Collecting ultralytics-thop>=2.0.0 (from ultralytics)\n", " Downloading ultralytics_thop-2.0.14-py3-none-any.whl.metadata (9.4 kB)\n", "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets) (2.4.4)\n", "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets) (1.3.2)\n", "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets) (24.3.0)\n", "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets) (1.5.0)\n", "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets) (6.1.0)\n", "Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets) (0.2.1)\n", "Requirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->datasets) (1.18.3)\n", "Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.11/dist-packages (from huggingface-hub>=0.23.0->datasets) (4.12.2)\n", "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.3.0->ultralytics) (1.3.1)\n", "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.3.0->ultralytics) (0.12.1)\n", "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.3.0->ultralytics) (4.55.5)\n", "Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.3.0->ultralytics) (1.4.8)\n", "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.3.0->ultralytics) (3.2.1)\n", "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.11/dist-packages (from matplotlib>=3.3.0->ultralytics) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas->datasets) (2024.2)\n", "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas->datasets) (2025.1)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets) (3.4.1)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets) (3.10)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets) (2.3.0)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests>=2.32.2->datasets) (2024.12.14)\n", "Requirement already satisfied: networkx in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (3.4.2)\n", "Requirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (3.1.5)\n", "Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (12.1.105)\n", "Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (12.1.105)\n", "Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (12.1.105)\n", "Requirement already satisfied: nvidia-cudnn-cu12==9.1.0.70 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (9.1.0.70)\n", "Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (12.1.3.1)\n", "Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (11.0.2.54)\n", "Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (10.3.2.106)\n", "Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (11.4.5.107)\n", "Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (12.1.0.106)\n", "Requirement already satisfied: nvidia-nccl-cu12==2.21.5 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (2.21.5)\n", "Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (12.1.105)\n", "Requirement already satisfied: triton==3.1.0 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (3.1.0)\n", "Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.11/dist-packages (from torch>=1.8.0->ultralytics) (1.13.1)\n", "Requirement already satisfied: nvidia-nvjitlink-cu12 in /usr/local/lib/python3.11/dist-packages (from nvidia-cusolver-cu12==11.4.5.107->torch>=1.8.0->ultralytics) (12.6.85)\n", "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from sympy==1.13.1->torch>=1.8.0->ultralytics) (1.3.0)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.7->matplotlib>=3.3.0->ultralytics) (1.17.0)\n", "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2->torch>=1.8.0->ultralytics) (3.0.2)\n", "Downloading datasets-3.2.0-py3-none-any.whl (480 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m480.6/480.6 kB\u001b[0m \u001b[31m9.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading ultralytics-8.3.68-py3-none-any.whl (913 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m913.6/913.6 kB\u001b[0m \u001b[31m34.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading dill-0.3.8-py3-none-any.whl (116 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m116.3/116.3 kB\u001b[0m \u001b[31m9.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading fsspec-2024.9.0-py3-none-any.whl (179 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m179.3/179.3 kB\u001b[0m \u001b[31m14.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading multiprocess-0.70.16-py311-none-any.whl (143 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m143.5/143.5 kB\u001b[0m \u001b[31m11.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading ultralytics_thop-2.0.14-py3-none-any.whl (26 kB)\n", "Downloading xxhash-3.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (194 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m194.8/194.8 kB\u001b[0m \u001b[31m15.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hInstalling collected packages: xxhash, fsspec, dill, multiprocess, ultralytics-thop, datasets, ultralytics\n", " Attempting uninstall: fsspec\n", " Found existing installation: fsspec 2024.10.0\n", " Uninstalling fsspec-2024.10.0:\n", " Successfully uninstalled fsspec-2024.10.0\n", "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", "gcsfs 2024.10.0 requires fsspec==2024.10.0, but you have fsspec 2024.9.0 which is incompatible.\u001b[0m\u001b[31m\n", "\u001b[0mSuccessfully installed datasets-3.2.0 dill-0.3.8 fsspec-2024.9.0 multiprocess-0.70.16 ultralytics-8.3.68 ultralytics-thop-2.0.14 xxhash-3.5.0\n" ] } ], "source": [ "! pip install datasets ultralytics" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 402, "referenced_widgets": [ "045c5a90a4e44c62bff82074ea0a4206", "b79e766f1f8e4542b3570ab748546a10", "af1f4069ccaf4bb3a827598a2766b756", "9381a9a338a9490d82ebabca0381a53e", "425e7bd48ff4460383de2ab0eb38967e", "743d23f277814df7acf58e99769fa995", "a60a905fca554d6dbc8e0bc0d7ebed0b", "7d66f81978ea48e3aba3abe4bc34a362", "51f0663f1b79496cbe8ce3d38d1ef5a4", "7d5ab77c50b84eb38e3a2c22a92ca88e", "eb91f17764f2478cb897e741eeae58ca", "8a8a814623b1471f8d9b3c49c72592ef", "e3321090379145e180e46744ce050c89", "0e351ff0b22d4aada497b0ca28c176c0", "58f60d66a8a1475c9b9c00c2e5ee23b9", "e6c66c0d935d4d978e8f80d3186688dd", "281b7dcb7f9c49dd9b0f37d08a4c7128", "5efea1066ce24da3a99aba14dfce9783", "2d51a4cc03804634a091282f126af34e", "3bda2f93d975401fa19f19bdfa50cbc9", "f42284f2326542f8bd723d612f9d1958", "cf76ed363c8c4803adfdd93ad76eaf74", "f735de1ab77140dbb4c72207b8ebb514", "c9f48974fd874e5c925f631fbbfd5237", "43f8f78aeae04edda400b863b2c6083b", "f6abb798974d491c8e0d82f2b101d55e", "fe34a93384d04276ab176dbb51276a31", "a945dd404eeb4b418051e33aa3985a7e", "9b8d306074524c4b8f3cadaa569035ca", "ce3185a77edd4e54b5246f295b95f135", "224cc58849bc42f2b5a883e06616a3da", "b9729d44ca98490ba230eb4c60444ea5", "5ad4797273bc411489a835b267c999be", "78ace055e9fb4d4f893f636f81c37c58", "d39b084356424c76a031b3353f406f92", "4e36f85990a04502a5781f5d8c2bfb71", "52125a8e46314bd7aeb8455db82d9f0b", "eed222dabb214d3d8c53e74900a1cd5e", "a802f9c6e8444c11b1bbef4c0cb3f1a3", "d125618b3bb74b638ee02d7871cc82b9", "404f2f2822bb4d1fa0b2316def55f9c9", "2ee4059e62b5489b8ec887bf2ea99430", "247ca90330cf4f5eb6e19556ad4a1e8c", "7be0a5449c2b4d63b12b72afbb395dc4", "9b5bebb7d4d44af4b466e152520f46b0", "196b240165764c24a538011e5e621fe8", "031ced2c6b694a3b8776505f310cce41", "dbcbc21e84c2408ebae6fd497c82bd9f", "0797084f7647413ab9a504b6593c0a32", "148b98c041434feeb0317d1011f477f3", "7ab18382ff57418e807e29e7eb29b5f9", "4a029944d7af46edbe012b98304991c7", "206ed7f680fa4221b5aab3e43f178a2b", "17e2fbaf98964eb9bf1b757d8b38cc98", "9c89394e72e64c1e8d66ac67b5b97f00", "031ad2790ce14930a576fbb5a70aa6ac", "519f5224463440b3bc68e29278358fb8", "a8411f4b2e144c4c9cbb02333ecc9cf6", "1b3e894a8e4940189a407fca1f2d9928", "6be43682c0b34f79b96f491140b3ca08", "13dcd001c23b48deb862e0e51513e2f7", "ae4cc09971e44debaec05ae39e9930a3", "cc6bca626dbf4b1a8476616781d37e91", "0c994560365a4a34b70e924a74a735fc", "491b7bdb3768406c85fe5116b72720ad", "c90495736064439d951a9e3a99d1c69b", "95e2c81b520742bbb26480a87d26daaa", "51a57359a0f948989a236681e7e0288c", "ef900119072b40439fc89c63a939e766", "1d83fe7833e64b3a9ff816b9a72f30ab", "468d0430026b4070b3897267fa993594", "f3156888b2644b9c88284f5fbe2f6883", "3ab0bcbd68294e99b34faf3fc5f02b53", "ee442a157c72446f9db8359ca590b202", "ea096a2828f94674979b9c77fc1372b0", "0834f8a046f64c6e8e7f90a0dc5dce98", "a486f99686834a7c8ca1819b93d8a017", "6e8a5580a981464e842c56ee88fdc29d", "1d5bd353a7764b078902a3626f4db345", "99ffb36c5c4f47769e1661bfcee86808", "efd09f30af42475dad4a8d14423d9f57", "c9cc9da8696f4f86b791d515e3f94af1", "b6f6ad3a8c204a08b1bd04539938f190", "f0b5371a218449ac8a09a750d985930b", "0ba67d6a1251492ab1c52bd32fff16cf", "a7f348ab9b4840529cfcb7baa8d5eba0", "71e2028d2470473286b6ddc41e2a9300", "7697bd1df7a6462284177dfa8ee4d24c" ] }, "id": "jnJT1oEGVV6d", "outputId": "2f509f0a-4f9c-4c05-855f-4caa059f23b6" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.11/dist-packages/huggingface_hub/utils/_auth.py:94: UserWarning: \n", "The secret `HF_TOKEN` does not exist in your Colab secrets.\n", "To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.\n", "You will be able to reuse this secret in all of your notebooks.\n", "Please note that authentication is recommended but still optional to access public models or datasets.\n", " warnings.warn(\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "045c5a90a4e44c62bff82074ea0a4206", "version_major": 2, "version_minor": 0 }, "text/plain": [ "README.md: 0%| | 0.00/1.88k [00:00\n", "RangeIndex: 6176 entries, 0 to 6175\n", "Data columns (total 5 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 image_id 6176 non-null int64 \n", " 1 image 6176 non-null object\n", " 2 width 6176 non-null int32 \n", " 3 height 6176 non-null int32 \n", " 4 objects 6176 non-null object\n", "dtypes: int32(2), int64(1), object(2)\n", "memory usage: 193.1+ KB\n" ] }, { "data": { "application/vnd.google.colaboratory.intrinsic+json": { "summary": "{\n \"name\": \"df_train\",\n \"rows\": 6176,\n \"fields\": [\n {\n \"column\": \"image_id\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 1783,\n \"min\": 0,\n \"max\": 6175,\n \"num_unique_values\": 6176,\n \"samples\": [\n 2669,\n 2934,\n 5218\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"image\",\n \"properties\": {\n \"dtype\": \"object\",\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"width\",\n \"properties\": {\n \"dtype\": \"int32\",\n \"num_unique_values\": 80,\n \"samples\": [\n 300,\n 472,\n 370\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"height\",\n \"properties\": {\n \"dtype\": \"int32\",\n \"num_unique_values\": 205,\n \"samples\": [\n 342,\n 427,\n 512\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"objects\",\n \"properties\": {\n \"dtype\": \"object\",\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}", "type": "dataframe", "variable_name": "df_train" }, "text/html": [ "\n", "
\n", "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
image_idimagewidthheightobjects
06152{'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x...472303{'id': [6388], 'area': [2604], 'bbox': [[261.0...
15500{'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x...472303{'id': [5719], 'area': [742], 'bbox': [[263.0,...
21188{'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x...400240{'id': [1231], 'area': [2701], 'bbox': [[147.0...
33524{'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x...540405{'id': [3651], 'area': [800], 'bbox': [[217.0,...
45049{'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x...472303{'id': [5242], 'area': [2112], 'bbox': [[145.0...
\n", "
\n", "
\n", "\n", "
\n", " \n", "\n", " \n", "\n", " \n", "
\n", "\n", "\n", "
\n", " \n", "\n", "\n", "\n", " \n", "
\n", "\n", "
\n", "
\n" ], "text/plain": [ " image_id image width height \\\n", "0 6152 {'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x... 472 303 \n", "1 5500 {'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x... 472 303 \n", "2 1188 {'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x... 400 240 \n", "3 3524 {'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x... 540 405 \n", "4 5049 {'bytes': b'\\xff\\xd8\\xff\\xe0\\x00\\x10JFIF\\x00\\x... 472 303 \n", "\n", " objects \n", "0 {'id': [6388], 'area': [2604], 'bbox': [[261.0... \n", "1 {'id': [5719], 'area': [742], 'bbox': [[263.0,... \n", "2 {'id': [1231], 'area': [2701], 'bbox': [[147.0... \n", "3 {'id': [3651], 'area': [800], 'bbox': [[217.0,... \n", "4 {'id': [5242], 'area': [2112], 'bbox': [[145.0... " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_train = ds['train'].to_pandas()\n", "df_val = ds['validation'].to_pandas()\n", "df_test = ds['test'].to_pandas()\n", "df_train.info()\n", "df_train.head()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "5gxgevPxZU26", "outputId": "58a58ccb-985c-4098-ab72-a9ac4b57e566" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading https://github.com/ultralytics/assets/releases/download/v8.3.0/yolov8n.pt to 'yolov8n.pt'...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 6.25M/6.25M [00:00<00:00, 76.2MB/s]\n" ] } ], "source": [ "# Load a pre-trained YOLOv8 model\n", "model = YOLO('yolov8n.pt') # 'yolov8n.pt' is a small model, you can choose others like 'yolov8" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "SORMPYhvZb4Z", "outputId": "365feb67-da37-4a29-afe1-3155667a1bbe" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'id': array([6388]), 'area': array([2604]), 'bbox': array([array([ 261, 203, 93, 28], dtype=float32)], dtype=object), 'category': array([0])}\n" ] } ], "source": [ "import os\n", "import cv2\n", "print(df_train[\"objects\"][0])\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "id": "3Hff3i23bPE4" }, "outputs": [], "source": [ "# Output directories\n", "image_dir = 'dataset/images/train'\n", "label_dir = 'dataset/labels/train'\n", "os.makedirs(image_dir, exist_ok=True)\n", "os.makedirs(label_dir, exist_ok=True)\n", "\n", "for idx, row in df_train.iterrows():\n", " # Convert byte string to image\n", " image = np.frombuffer(row['image'].get('bytes'), dtype=np.uint8)\n", " image = cv2.imdecode(image, cv2.IMREAD_COLOR)\n", "\n", " if image is not None:\n", " image_height, image_width = image.shape[:2]\n", " else:\n", " continue\n", "\n", " # Save image\n", " image_path = os.path.join(image_dir, f'image_{idx}.jpg')\n", " cv2.imwrite(image_path, image)\n", "\n", " # Convert bbox to YOLO format\n", " # Extract bounding box and class ID\n", " bbox = row['objects'].get(\"bbox\") # [x_min, y_min, width, height]\n", " class_id = 0 # Class ID\n", "\n", " # Normalize bbox coordinates\n", " x_min, y_min, width, height = bbox[0]\n", " x_center = (x_min + width / 2) / image_width\n", " y_center = (y_min + height / 2) / image_height\n", " bbox_width = width / image_width\n", " bbox_height = height / image_height\n", "\n", " # Save label file\n", " label_path = os.path.join(label_dir, f'image_{idx}.txt')\n", " with open(label_path, 'w') as f:\n", " f.write(f'{class_id} {x_center} {y_center} {bbox_width} {bbox_height}\\n')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "id": "f_J9xp_hpenL" }, "outputs": [], "source": [ "# Output directories\n", "image_dir = 'dataset/images/val'\n", "label_dir = 'dataset/labels/val'\n", "os.makedirs(image_dir, exist_ok=True)\n", "os.makedirs(label_dir, exist_ok=True)\n", "\n", "for idx, row in df_val.iterrows():\n", " # Convert byte string to image\n", " image = np.frombuffer(row['image'].get('bytes'), dtype=np.uint8)\n", " image = cv2.imdecode(image, cv2.IMREAD_COLOR)\n", "\n", " if image is not None:\n", " image_height, image_width = image.shape[:2]\n", " else:\n", " continue\n", "\n", " # Save image\n", " image_path = os.path.join(image_dir, f'image_{idx}.jpg')\n", " cv2.imwrite(image_path, image)\n", "\n", " # Convert bbox to YOLO format\n", " # Extract bounding box and class ID\n", " bbox = row['objects'].get(\"bbox\") # [x_min, y_min, width, height]\n", " class_id = 0 # Class ID\n", "\n", "\n", " # Normalize bbox coordinates\n", " x_min, y_min, width, height = bbox[0]\n", " x_center = (x_min + width / 2) / image_width\n", " y_center = (y_min + height / 2) / image_height\n", " bbox_width = width / image_width\n", " bbox_height = height / image_height\n", "\n", " # Save label file\n", " label_path = os.path.join(label_dir, f'image_{idx}.txt')\n", " with open(label_path, 'w') as f:\n", " f.write(f'{class_id} {x_center} {y_center} {bbox_width} {bbox_height}\\n')" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "UpfV5l2Dom3t", "outputId": "78e0a3c8-34cc-4f92-f31d-62b4b06a132a" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Ultralytics 8.3.68 🚀 Python-3.11.11 torch-2.5.1+cu121 CUDA:0 (NVIDIA A100-SXM4-40GB, 40514MiB)\n", "\u001b[34m\u001b[1mengine/trainer: \u001b[0mtask=detect, mode=train, model=yolov8n.pt, data=dataset.yaml, epochs=75, time=None, patience=100, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train3, exist_ok=False, pretrained=True, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=True, opset=None, workspace=None, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, copy_paste_mode=flip, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=runs/detect/train3\n", "\n", " from n params module arguments \n", " 0 -1 1 464 ultralytics.nn.modules.conv.Conv [3, 16, 3, 2] \n", " 1 -1 1 4672 ultralytics.nn.modules.conv.Conv [16, 32, 3, 2] \n", " 2 -1 1 7360 ultralytics.nn.modules.block.C2f [32, 32, 1, True] \n", " 3 -1 1 18560 ultralytics.nn.modules.conv.Conv [32, 64, 3, 2] \n", " 4 -1 2 49664 ultralytics.nn.modules.block.C2f [64, 64, 2, True] \n", " 5 -1 1 73984 ultralytics.nn.modules.conv.Conv [64, 128, 3, 2] \n", " 6 -1 2 197632 ultralytics.nn.modules.block.C2f [128, 128, 2, True] \n", " 7 -1 1 295424 ultralytics.nn.modules.conv.Conv [128, 256, 3, 2] \n", " 8 -1 1 460288 ultralytics.nn.modules.block.C2f [256, 256, 1, True] \n", " 9 -1 1 164608 ultralytics.nn.modules.block.SPPF [256, 256, 5] \n", " 10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n", " 11 [-1, 6] 1 0 ultralytics.nn.modules.conv.Concat [1] \n", " 12 -1 1 148224 ultralytics.nn.modules.block.C2f [384, 128, 1] \n", " 13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n", " 14 [-1, 4] 1 0 ultralytics.nn.modules.conv.Concat [1] \n", " 15 -1 1 37248 ultralytics.nn.modules.block.C2f [192, 64, 1] \n", " 16 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2] \n", " 17 [-1, 12] 1 0 ultralytics.nn.modules.conv.Concat [1] \n", " 18 -1 1 123648 ultralytics.nn.modules.block.C2f [192, 128, 1] \n", " 19 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3, 2] \n", " 20 [-1, 9] 1 0 ultralytics.nn.modules.conv.Concat [1] \n", " 21 -1 1 493056 ultralytics.nn.modules.block.C2f [384, 256, 1] \n", " 22 [15, 18, 21] 1 751507 ultralytics.nn.modules.head.Detect [1, [64, 128, 256]] \n", "Model summary: 225 layers, 3,011,043 parameters, 3,011,027 gradients, 8.2 GFLOPs\n", "\n", "Transferred 355/355 items from pretrained weights\n", "\u001b[34m\u001b[1mTensorBoard: \u001b[0mStart with 'tensorboard --logdir runs/detect/train3', view at http://localhost:6006/\n", "Freezing layer 'model.22.dfl.conv.weight'\n", "\u001b[34m\u001b[1mAMP: \u001b[0mrunning Automatic Mixed Precision (AMP) checks...\n", "\u001b[34m\u001b[1mAMP: \u001b[0mchecks passed ✅\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mtrain: \u001b[0mScanning /content/dataset/labels/train.cache... 6176 images, 0 backgrounds, 0 corrupt: 100%|██████████| 6176/6176 [00:00