|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "0e0946b2-7b7f-43d8-aa7d-eccb51a9cf2d", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Fine-Tuning YOLOv10 Models" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "markdown", |
| 13 | + "id": "638c4b07-7254-45eb-831d-8e8fa800377a", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "Code written by Pranav Durai" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "markdown", |
| 21 | + "id": "160484c3-71da-4a2f-9e89-e85795d7de30", |
| 22 | + "metadata": {}, |
| 23 | + "source": [ |
| 24 | + "### Library Imports" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": null, |
| 30 | + "id": "297dd27f-e88c-4256-863f-8147899868f6", |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [], |
| 33 | + "source": [ |
| 34 | + "import os\n", |
| 35 | + "import json\n", |
| 36 | + "import random\n", |
| 37 | + "import requests\n", |
| 38 | + "import zipfile" |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "markdown", |
| 43 | + "id": "93a83d8a-0832-4472-8add-332a8242816e", |
| 44 | + "metadata": {}, |
| 45 | + "source": [ |
| 46 | + "### Clone the Official YOLOv10 Repository" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": null, |
| 52 | + "id": "851eb608-bca0-4a0c-8189-6b1ef0488c2e", |
| 53 | + "metadata": {}, |
| 54 | + "outputs": [], |
| 55 | + "source": [ |
| 56 | + "HOME = os.getcwd()" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": null, |
| 62 | + "id": "b0144625-7180-464a-9167-2213b76b6d22", |
| 63 | + "metadata": {}, |
| 64 | + "outputs": [], |
| 65 | + "source": [ |
| 66 | + "!pip install -q git+https://github.com/THU-MIG/yolov10.git\n", |
| 67 | + "!pip install huggingface_hub" |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "markdown", |
| 72 | + "id": "217cb43d-03b6-4ec4-b4a9-74946d1cce1b", |
| 73 | + "metadata": {}, |
| 74 | + "source": [ |
| 75 | + "### Download Kidney Stone Detection Dataset" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "code", |
| 80 | + "execution_count": null, |
| 81 | + "id": "90179d09-1236-47d0-9348-da68256cb580", |
| 82 | + "metadata": {}, |
| 83 | + "outputs": [], |
| 84 | + "source": [ |
| 85 | + "def download_and_unzip(dropbox_link):\n", |
| 86 | + " \n", |
| 87 | + " # Set the output directory path\n", |
| 88 | + " output_dir = '/content'\n", |
| 89 | + "\n", |
| 90 | + " # Extract the filename from the Dropbox link\n", |
| 91 | + " filename = dropbox_link.split('/')[-1]\n", |
| 92 | + "\n", |
| 93 | + " # Download the zip file\n", |
| 94 | + " response = requests.get(dropbox_link)\n", |
| 95 | + " zip_path = os.path.join(output_dir, filename)\n", |
| 96 | + " with open(zip_path, 'wb') as f:\n", |
| 97 | + " f.write(response.content)\n", |
| 98 | + "\n", |
| 99 | + " # Extract the contents of the zip file\n", |
| 100 | + " with zipfile.ZipFile(zip_path, 'r') as zip_ref:\n", |
| 101 | + " zip_ref.extractall(output_dir)\n", |
| 102 | + "\n", |
| 103 | + " # Remove the zip file\n", |
| 104 | + " os.remove(zip_path)\n", |
| 105 | + "\n", |
| 106 | + " # Print success message\n", |
| 107 | + " print(f\"Zip file downloaded and extracted to: {output_dir}\")" |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + "cell_type": "code", |
| 112 | + "execution_count": null, |
| 113 | + "id": "f145e10c-adb7-40c0-8e01-52b0f0c30e44", |
| 114 | + "metadata": {}, |
| 115 | + "outputs": [], |
| 116 | + "source": [ |
| 117 | + "# Function call to dowload_and_unzip() - ORIGINAL DATASET\n", |
| 118 | + "dropbox_link = \"https://www.dropbox.com/scl/fi/1xrhftpzvkw43rv0dbabg/KIDNEY_STONE_DATASET.zip?rlkey=56iykq3o4aclssdeymmyw78jb&st=s6x9qmko&dl=1\"\n", |
| 119 | + "download_and_unzip(dropbox_link)" |
| 120 | + ] |
| 121 | + }, |
| 122 | + { |
| 123 | + "cell_type": "markdown", |
| 124 | + "id": "4613f2aa-a1ac-4fb4-9428-109962b25719", |
| 125 | + "metadata": {}, |
| 126 | + "source": [ |
| 127 | + "### Pull YOLOv10 Model Weights" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "code", |
| 132 | + "execution_count": null, |
| 133 | + "id": "94eabbe7-3763-431e-b674-b797190911b4", |
| 134 | + "metadata": {}, |
| 135 | + "outputs": [], |
| 136 | + "source": [ |
| 137 | + "!mkdir -p {HOME}/weights\n", |
| 138 | + "!wget -P {HOME}/weights -q https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10n.pt\n", |
| 139 | + "!wget -P {HOME}/weights -q https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10s.pt\n", |
| 140 | + "!wget -P {HOME}/weights -q https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10m.pt\n", |
| 141 | + "!wget -P {HOME}/weights -q https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10b.pt\n", |
| 142 | + "!wget -P {HOME}/weights -q https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10x.pt\n", |
| 143 | + "!wget -P {HOME}/weights -q https://github.com/THU-MIG/yolov10/releases/download/v1.1/yolov10l.pt\n", |
| 144 | + "!ls -lh {HOME}/weights" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "markdown", |
| 149 | + "id": "713011dc-b284-4f14-9479-618b5a60deb1", |
| 150 | + "metadata": {}, |
| 151 | + "source": [ |
| 152 | + "### Training" |
| 153 | + ] |
| 154 | + }, |
| 155 | + { |
| 156 | + "cell_type": "code", |
| 157 | + "execution_count": null, |
| 158 | + "id": "d9e6a2b9-4703-49fa-9a26-24dbebe895b0", |
| 159 | + "metadata": {}, |
| 160 | + "outputs": [], |
| 161 | + "source": [ |
| 162 | + "%cd {HOME}" |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | + "cell_type": "code", |
| 167 | + "execution_count": null, |
| 168 | + "id": "3c2acb3c-f949-4cb9-9f95-f24497f3d422", |
| 169 | + "metadata": {}, |
| 170 | + "outputs": [], |
| 171 | + "source": [ |
| 172 | + "!yolo task=detect mode=train epochs=100 batch=24 plots=True \\\n", |
| 173 | + "model=/weights/yolov10l.pt \\\n", |
| 174 | + "data=/MODIFIED_DATASET/data.yaml" |
| 175 | + ] |
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "markdown", |
| 179 | + "id": "be70527b-9623-4abd-9ac3-2462dff3c383", |
| 180 | + "metadata": {}, |
| 181 | + "source": [ |
| 182 | + "### Inference" |
| 183 | + ] |
| 184 | + }, |
| 185 | + { |
| 186 | + "cell_type": "code", |
| 187 | + "execution_count": null, |
| 188 | + "id": "3b5a49cc-f625-4571-9833-0c902d23d471", |
| 189 | + "metadata": {}, |
| 190 | + "outputs": [], |
| 191 | + "source": [ |
| 192 | + "!yolo task=detect mode=predict conf=0.25 save=True show_labels=False \\\n", |
| 193 | + "model=best.pt \\\n", |
| 194 | + "source=test/images" |
| 195 | + ] |
| 196 | + } |
| 197 | + ], |
| 198 | + "metadata": { |
| 199 | + "kernelspec": { |
| 200 | + "display_name": "Python 3 (ipykernel)", |
| 201 | + "language": "python", |
| 202 | + "name": "python3" |
| 203 | + }, |
| 204 | + "language_info": { |
| 205 | + "codemirror_mode": { |
| 206 | + "name": "ipython", |
| 207 | + "version": 3 |
| 208 | + }, |
| 209 | + "file_extension": ".py", |
| 210 | + "mimetype": "text/x-python", |
| 211 | + "name": "python", |
| 212 | + "nbconvert_exporter": "python", |
| 213 | + "pygments_lexer": "ipython3", |
| 214 | + "version": "3.9.19" |
| 215 | + } |
| 216 | + }, |
| 217 | + "nbformat": 4, |
| 218 | + "nbformat_minor": 5 |
| 219 | +} |
0 commit comments