{ "cells": [ { "cell_type": "markdown", "source": [ "[](http://edenlibrary.ai/)" ], "metadata": { "id": "cuR_mlPspqrs" } }, { "cell_type": "markdown", "source": [ "PP-YOLO and YOLO-NAS are both advancements in the field of object detection that build upon the original YOLO (You Only Look Once) framework, which is known for its speed and efficiency in detecting objects in images or video streams.\n", "\n", "### PP-YOLO\n", "\n", "PP-YOLO, or PaddlePaddle YOLO, is an enhanced version of the YOLO model developed by Baidu. It aims to improve the performance of the original YOLOv3 model in terms of both speed and accuracy. PP-YOLO incorporates several modifications and optimizations such as:\n", "- **Better backbone:** Uses ResNet50Vd as the backbone network instead of Darknet-53, improving feature extraction capabilities.\n", "- **Path aggregation network (PAN):** Enhances the fusion of features from different scales.\n", "- **Mish activation:** Replaces the traditional activation functions with Mish, which may help in reducing the risk of vanishing gradients.\n", "- **Larger batch size and learning rate warmup:** Improves the training process to achieve better accuracy.\n", "- **DropBlock regularization:** A form of structured dropout that helps in regularizing the model, particularly beneficial for convolutional networks.\n", "- **Enhanced data augmentation:** Incorporates strategies like mosaic augmentation and mixup to increase the diversity of training data, which can lead to better generalization.\n", "\n", "These improvements make PP-YOLO a competitive choice for real-time object detection, offering a good balance between speed and accuracy.\n", "\n", "### YOLO-NAS\n", "\n", "YOLO-NAS (Neural Architecture Search for YOLO) is an approach that applies neural architecture search (NAS) to the YOLO framework to automatically discover optimal network architectures for object detection tasks. NAS is a technique in machine learning that involves using algorithms (often reinforcement learning or evolutionary algorithms) to automate the design of neural network architectures.\n", "\n", "YOLO-NAS aims to optimize various aspects of the YOLO architecture, such as the backbone network, the feature pyramid networks (FPNs), and the head of the network for predicting bounding boxes and class probabilities. By searching for the most effective configurations and structures, YOLO-NAS seeks to enhance the performance of YOLO models without significantly increasing computational complexity. This can lead to more efficient models that maintain high accuracy while being faster or requiring fewer resources, making them suitable for deployment in environments with limited computational capacity.\n", "\n", "Both PP-YOLO and YOLO-NAS illustrate the ongoing efforts to improve object detection models by making them faster, more accurate, and more efficient, catering to the increasing demands of applications in surveillance, autonomous vehicles, and many other areas." ], "metadata": { "id": "zj3hyhiiqTJ0" } }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "QEpvD713L-WU", "outputId": "30b7fa86-fe89-407e-d6f6-f4090975d0ee" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.0/12.0 MB\u001b[0m \u001b[31m44.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m139.3/139.3 kB\u001b[0m \u001b[31m1.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m684.5/684.5 kB\u001b[0m \u001b[31m24.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.9/2.9 MB\u001b[0m \u001b[31m56.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.8/2.8 MB\u001b[0m \u001b[31m83.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m408.6/408.6 kB\u001b[0m \u001b[31m33.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m154.5/154.5 kB\u001b[0m \u001b[31m16.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m79.5/79.5 kB\u001b[0m \u001b[31m8.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.5/4.5 MB\u001b[0m \u001b[31m52.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.5/13.5 MB\u001b[0m \u001b[31m40.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m68.0/68.0 kB\u001b[0m \u001b[31m7.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n", " Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.0/17.0 MB\u001b[0m \u001b[31m52.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.4/3.4 MB\u001b[0m \u001b[31m51.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m29.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m459.5/459.5 kB\u001b[0m \u001b[31m41.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.0/46.0 kB\u001b[0m \u001b[31m5.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m11.9/11.9 MB\u001b[0m \u001b[31m101.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m82.1/82.1 kB\u001b[0m \u001b[31m10.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m108.3/108.3 kB\u001b[0m \u001b[31m14.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m176.0/176.0 kB\u001b[0m \u001b[31m22.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m433.2/433.2 kB\u001b[0m \u001b[31m44.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m109.4/109.4 kB\u001b[0m \u001b[31m15.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m278.2/278.2 kB\u001b[0m \u001b[31m33.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.8/2.8 MB\u001b[0m \u001b[31m56.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m913.9/913.9 kB\u001b[0m \u001b[31m63.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m117.0/117.0 kB\u001b[0m \u001b[31m16.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m575.5/575.5 kB\u001b[0m \u001b[31m46.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.8/2.8 MB\u001b[0m \u001b[31m97.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m121.1/121.1 kB\u001b[0m \u001b[31m15.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m86.8/86.8 kB\u001b[0m \u001b[31m10.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m120.0/120.0 kB\u001b[0m \u001b[31m17.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m83.5/83.5 kB\u001b[0m \u001b[31m11.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m99.2/99.2 kB\u001b[0m \u001b[31m13.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m89.4/89.4 kB\u001b[0m \u001b[31m12.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m92.7/92.7 kB\u001b[0m \u001b[31m12.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m105.0/105.0 kB\u001b[0m \u001b[31m13.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m46.2/46.2 kB\u001b[0m \u001b[31m5.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m194.6/194.6 kB\u001b[0m \u001b[31m25.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.1/58.1 kB\u001b[0m \u001b[31m7.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Building wheel for pycocotools (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for termcolor (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for treelib (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for coverage (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for xhtml2pdf (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for antlr4-python3-runtime (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for stringcase (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Building wheel for svglib (setup.py) ... \u001b[?25l\u001b[?25hdone\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", "lida 0.0.10 requires fastapi, which is not installed.\n", "lida 0.0.10 requires kaleido, which is not installed.\n", "lida 0.0.10 requires python-multipart, which is not installed.\n", "lida 0.0.10 requires uvicorn, which is not installed.\n", "tensorflow 2.15.0 requires numpy<2.0.0,>=1.23.5, but you have numpy 1.23.0 which is incompatible.\u001b[0m\u001b[31m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.5/77.5 kB\u001b[0m \u001b[31m1.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.1/49.1 MB\u001b[0m \u001b[31m29.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h" ] } ], "source": [ "!pip install -q super-gradients\n", "!pip install -q supervision" ] }, { "cell_type": "markdown", "source": [ "**Cell to avoid some temporal problems on Google Colab**" ], "metadata": { "id": "gsg9Q9NUeI8I" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "0vp_5VgoAS5U" }, "outputs": [], "source": [ "import os\n", "import locale\n", "os.environ['CUDA_LAUNCH_BLOCKING'] = \"1\"\n", "locale.getpreferredencoding = lambda: \"UTF-8\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "mDK1aW00Wktx", "outputId": "a599f496-fefe-4b5f-f97a-c5c6014db9c0" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[2024-01-17 13:09:14] INFO - crash_tips_setup.py - Crash tips is enabled. You can set your environment variable to CRASH_HANDLER=FALSE to disable it\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "The console stream is logged into /root/sg_logs/console.log\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[2024-01-17 13:09:14] WARNING - __init__.py - Failed to import pytorch_quantization\n", "[2024-01-17 13:09:14] INFO - utils.py - NumExpr defaulting to 8 threads.\n", "[2024-01-17 13:09:21] WARNING - calibrator.py - Failed to import pytorch_quantization\n", "[2024-01-17 13:09:21] WARNING - export.py - Failed to import pytorch_quantization\n", "[2024-01-17 13:09:21] WARNING - selective_quantization_utils.py - Failed to import pytorch_quantization\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: boto3 required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: deprecated required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: coverage required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: sphinx-rtd-theme required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: torchmetrics required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: hydra-core required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: omegaconf required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: onnxruntime required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: onnx required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: einops required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: treelib required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: stringcase required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: rapidfuzz required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: json-tricks required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: onnx-simplifier required but not found\u001b[0m\n", "[2024-01-17 13:09:21] WARNING - env_sanity_check.py - \u001b[31mFailed to verify installed packages: data-gradients required but not found\u001b[0m\n" ] } ], "source": [ "import torch\n", "from super_gradients.training import models\n", "from super_gradients.common.object_names import Models\n", "from super_gradients.training import dataloaders\n", "from super_gradients.training.dataloaders.dataloaders import coco_detection_yolo_format_train, coco_detection_yolo_format_val\n", "from super_gradients.training import Trainer\n", "from super_gradients.training.losses import YoloXDetectionLoss\n", "from super_gradients.training.losses import PPYoloELoss\n", "from super_gradients.training.metrics import DetectionMetrics_050\n", "from super_gradients.training.models.detection_models.pp_yolo_e import PPYoloEPostPredictionCallback\n", "\n", "import supervision as sv\n", "from tqdm import tqdm\n", "import cv2\n", "\n", "import random\n", "import shutil\n", "\n", "from IPython.display import clear_output\n", "random.seed(2024)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "X0nFEAePNjvb" }, "outputs": [], "source": [ "device = 'cuda' if torch.cuda.is_available() else \"cpu\"" ] }, { "cell_type": "markdown", "source": [ "**Cell to avoid some temporal problems on Google Colab**" ], "metadata": { "id": "IQNmE7kbebzC" } }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "uJjDbcM_LNam", "outputId": "b0d121e9-966d-46ca-9d65-b00913dc30de" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mounted at /content/gdrive/\n" ] } ], "source": [ "from google.colab import drive\n", "drive.mount(\"/content/gdrive/\")" ] }, { "cell_type": "markdown", "source": [ "**Select your own YOLO-structure FOLDER**\n", "\n", "Dataset **NOT** included in the shared folder" ], "metadata": { "id": "3fAuEOKheT9o" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "1ks-4ax8po3w" }, "outputs": [], "source": [ "%%capture\n", "!unzip \"/content/gdrive/MyDrive/Colab Notebooks/adata/detection/smart-droplets-rumex-yolo.zip\"\n", "!rm -rf __MACOSX" ] }, { "cell_type": "markdown", "source": [ "**Detection Hyper-parameters**" ], "metadata": { "id": "2rZaZVF6e__T" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Zs2vZVBFFtKh" }, "outputs": [], "source": [ "NUM_EXPERIMENTS = 1\n", "CONFIDENCE_TRESHOLD = 0.6\n", "MAX_IMAGE_COUNT = 10\n", "BATCH_SIZE = 16\n", "NUM_EPOCHS = 30" ] }, { "cell_type": "markdown", "source": [ "**Filesystem Metadata**" ], "metadata": { "id": "K3RPXKpNfEJ2" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "MQqqFuh1ga7M" }, "outputs": [], "source": [ "dataset_params = {\n", " 'data_dir':'/content/smart-droplets-rumex-yolo',\n", " 'train_images_dir':'train/images',\n", " 'train_labels_dir':'train/labels',\n", " 'val_images_dir':'valid/images',\n", " 'val_labels_dir':'valid/labels',\n", " 'test_images_dir':'test/images',\n", " 'test_labels_dir':'test/labels',\n", " 'classes': ['Rumex']\n", "}" ] }, { "cell_type": "markdown", "source": [ "**Dataset and DataLoaders Metadata**" ], "metadata": { "id": "8m-v4H1dfQPU" } }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "GO1AoZ1XhaeV" }, "outputs": [], "source": [ "train_data = coco_detection_yolo_format_train(\n", " dataset_params={\n", " 'data_dir': dataset_params['data_dir'],\n", " 'images_dir': dataset_params['train_images_dir'],\n", " 'labels_dir': dataset_params['train_labels_dir'],\n", " 'classes': dataset_params['classes']\n", " },\n", " dataloader_params={\n", " 'batch_size':BATCH_SIZE,\n", " 'num_workers':2\n", " }\n", ")\n", "\n", "val_data = coco_detection_yolo_format_val(\n", " dataset_params={\n", " 'data_dir': dataset_params['data_dir'],\n", " 'images_dir': dataset_params['val_images_dir'],\n", " 'labels_dir': dataset_params['val_labels_dir'],\n", " 'classes': dataset_params['classes']\n", " },\n", " dataloader_params={\n", " 'batch_size':BATCH_SIZE,\n", " 'num_workers':2\n", " }\n", ")\n", "\n", "test_data = coco_detection_yolo_format_val(\n", " dataset_params={\n", " 'data_dir': dataset_params['data_dir'],\n", " 'images_dir': dataset_params['test_images_dir'],\n", " 'labels_dir': dataset_params['test_labels_dir'],\n", " 'classes': dataset_params['classes']\n", " },\n", " dataloader_params={\n", " 'batch_size':BATCH_SIZE,\n", " 'num_workers':2\n", " }\n", ")\n", "\n", "clear_output()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "bpvsA76kVn5y" }, "outputs": [], "source": [ "#train_data.dataset.dataset_params['transforms'][1]['DetectionRandomAffine']['degrees'] = 10.42" ] }, { "cell_type": "markdown", "source": [ "**Training Hyper-parameters**" ], "metadata": { "id": "B0OWQY4Tfc2d" } }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "nTl0X_SDimqp", "outputId": "b705ae56-9e04-48c4-e59e-a392af1693dc" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\rIndexing dataset annotations: 0%| | 0/49 [00:00" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "best_model = models.get(Models.PP_YOLOE_L,\n", " num_classes=len(dataset_params['classes']),\n", " checkpoint_path=f'0_checkpoints/{EXPERIMENT_NAME}/{sorted(os.listdir(os.path.join(CHECKPOINT_DIR, EXPERIMENT_NAME)))[-1]}/ckpt_best.pth')\n", "\n", "ds = sv.DetectionDataset.from_yolo(\n", " images_directory_path=f\"{dataset_params['data_dir']}/test/images\",\n", " annotations_directory_path=f\"{dataset_params['data_dir']}/test/labels\",\n", " data_yaml_path=f\"{dataset_params['data_dir']}/data.yaml\",\n", " force_masks=False\n", ")\n", "\n", "predictions = get_predictions(ds, best_model)\n", "images, titles, n = get_images_titles(ds, predictions)\n", "%matplotlib inline\n", "sv.plot_images_grid(images=images, titles=titles, grid_size=(n, 2), size=(2 * 8, n * 8))" ] }, { "cell_type": "markdown", "source": [ "**Reference**: https://blog.roboflow.com/yolo-nas-how-to-train-on-custom-dataset/" ], "metadata": { "id": "V3TxlTpdgpLB" } } ], "metadata": { "accelerator": "GPU", "colab": { "machine_shape": "hm", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }