{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "C2JGBuAeUDi7", "outputId": "e4aef05a-52cf-43e9-accd-696e4c82ccd5" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Thu Aug 29 11:19:49 2024 \n", "+---------------------------------------------------------------------------------------+\n", "| NVIDIA-SMI 535.104.05 Driver Version: 535.104.05 CUDA Version: 12.2 |\n", "|-----------------------------------------+----------------------+----------------------+\n", "| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n", "| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n", "| | | MIG M. |\n", "|=========================================+======================+======================|\n", "| 0 NVIDIA A100-SXM4-40GB Off | 00000000:00:04.0 Off | 0 |\n", "| N/A 35C P0 45W / 400W | 2MiB / 40960MiB | 0% Default |\n", "| | | Disabled |\n", "+-----------------------------------------+----------------------+----------------------+\n", " \n", "+---------------------------------------------------------------------------------------+\n", "| Processes: |\n", "| GPU GI CI PID Type Process name GPU Memory |\n", "| ID ID Usage |\n", "|=======================================================================================|\n", "| No running processes found |\n", "+---------------------------------------------------------------------------------------+\n" ] } ], "source": [ "# Check GPU type\n", "!nvidia-smi" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "AK-6-eQqhTeV", "outputId": "8260324d-4ca5-4cd9-c5e1-efbf047d16d7" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "^C\n" ] } ], "source": [ "# Install ultralytics\n", "!pip -q install ultralytics" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "id": "YEIlI7wOGP-R" }, "outputs": [], "source": [ "# Import libraries\n", "import pandas as pd\n", "import os\n", "from pathlib import Path\n", "import shutil\n", "from sklearn.model_selection import train_test_split\n", "from tqdm.notebook import tqdm\n", "import cv2\n", "import yaml\n", "import matplotlib.pyplot as plt\n", "from ultralytics import YOLO\n", "import multiprocessing" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "Ozqm5yKJGuV4", "outputId": "c03df89f-24e4-405a-f241-fe6d7d05cf3d" }, "outputs": [ { "data": { "text/plain": [ "['Train.csv', 'Test.csv', 'SampleSubmission.csv', 'images.zip']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Path to where your data is stored\n", "DATA_DIR = Path('/content/drive/MyDrive/Lacuna')\n", "\n", "# Preview data files available\n", "os.listdir(DATA_DIR)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "id": "oYL1hmTCP6d0" }, "outputs": [], "source": [ "# Set up directoris for training a yolo model\n", "\n", "# Images directories\n", "DATASET_DIR = Path('datasets/dataset')\n", "IMAGES_DIR = DATASET_DIR / 'images'\n", "TRAIN_IMAGES_DIR = IMAGES_DIR / 'train'\n", "VAL_IMAGES_DIR = IMAGES_DIR / 'val'\n", "TEST_IMAGES_DIR = IMAGES_DIR / 'test'\n", "\n", "# Labels directories\n", "LABELS_DIR = DATASET_DIR / 'labels'\n", "TRAIN_LABELS_DIR = LABELS_DIR / 'train'\n", "VAL_LABELS_DIR = LABELS_DIR / 'val'\n", "TEST_LABELS_DIR = LABELS_DIR / 'test'" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "id": "COCyht5BGuQV" }, "outputs": [], "source": [ "# Unzip images to 'images' dir\n", "shutil.unpack_archive(DATA_DIR / 'images.zip', 'images')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 206 }, "id": "VIBthAgmRcYW", "outputId": "4e93bd01-df2d-46c9-f818-73ae70fc1f4e" }, "outputs": [ { "data": { "application/vnd.google.colaboratory.intrinsic+json": { "summary": "{\n \"name\": \"train\",\n \"rows\": 23530,\n \"fields\": [\n {\n \"column\": \"Image_ID\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2747,\n \"samples\": [\n \"id_g8q3grlu7l.jpg\",\n \"id_lrladi6gkk.jpg\",\n \"id_q6r7g45ots.jpg\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"class\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 3,\n \"samples\": [\n \"Trophozoite\",\n \"NEG\",\n \"WBC\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"confidence\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.0,\n \"min\": 1.0,\n \"max\": 1.0,\n \"num_unique_values\": 1,\n \"samples\": [\n 1.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"ymin\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 676,\n \"min\": 0,\n \"max\": 3012,\n \"num_unique_values\": 2151,\n \"samples\": [\n 932\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"xmin\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 860,\n \"min\": 0,\n \"max\": 4051,\n \"num_unique_values\": 2786,\n \"samples\": [\n 2360\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"ymax\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 704,\n \"min\": 0,\n \"max\": 3116,\n \"num_unique_values\": 2464,\n \"samples\": [\n 900\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"xmax\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 886,\n \"min\": 0,\n \"max\": 4155,\n \"num_unique_values\": 3139,\n \"samples\": [\n 3097\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"image_path\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2747,\n \"samples\": [\n \"images/id_g8q3grlu7l.jpg\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"class_id\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 2,\n \"num_unique_values\": 3,\n \"samples\": [\n 0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}", "type": "dataframe", "variable_name": "train" }, "text/html": [ "\n", "
\n", " | Image_ID | \n", "class | \n", "confidence | \n", "ymin | \n", "xmin | \n", "ymax | \n", "xmax | \n", "image_path | \n", "class_id | \n", "
---|---|---|---|---|---|---|---|---|---|
0 | \n", "id_u3q6jdck4j.jpg | \n", "Trophozoite | \n", "1.0 | \n", "712 | \n", "1241 | \n", "737 | \n", "1270 | \n", "images/id_u3q6jdck4j.jpg | \n", "0 | \n", "
1 | \n", "id_a6cl90trri.jpg | \n", "Trophozoite | \n", "1.0 | \n", "558 | \n", "1566 | \n", "600 | \n", "1604 | \n", "images/id_a6cl90trri.jpg | \n", "0 | \n", "
2 | \n", "id_qvc2le9sm8.jpg | \n", "Trophozoite | \n", "1.0 | \n", "1317 | \n", "2788 | \n", "1448 | \n", "2914 | \n", "images/id_qvc2le9sm8.jpg | \n", "0 | \n", "
3 | \n", "id_w8xnbd5rvm.jpg | \n", "Trophozoite | \n", "1.0 | \n", "925 | \n", "1744 | \n", "1041 | \n", "1823 | \n", "images/id_w8xnbd5rvm.jpg | \n", "0 | \n", "
4 | \n", "id_6dop09rk02.jpg | \n", "NEG | \n", "1.0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "images/id_6dop09rk02.jpg | \n", "2 | \n", "