Datasets:
Bappadala Rohith Kumar Naidu commited on
Commit ·
198bb3d
1
Parent(s): ae454c7
fix: sync scripts/data with main repo, fix import patterns
Browse files- _overpass_utils.py: remove stale ROOT_DIR export, add **kwargs to
fetch_elements() and normalize_row() to match main repo signatures
- fetch_hospitals/ambulance/police/fire/blood_banks.py: stop importing
ROOT_DIR from _overpass_utils; define ROOT_DIR locally per-script
(mirrors the pattern used in the main SafeVisionAI repo)
- bootstrap_local_data.py: remove unused 'import tempfile'
- Add __init__.py to scripts/scripts/data/ and scripts/backend/data/
for Python package consistency
- README.md +18 -8
- notebooks/Accident_EDA_&_Hotspot_Generator_chatbot_service_data_accidents_3.ipynb +66 -445
- notebooks/ChromaDB_RAG_Vectorstore_Build_chatbot_service_data_chroma_db_2.ipynb +0 -0
- notebooks/Risk_Model_ONNX_Training_frontend_public_models_5.ipynb +93 -186
- notebooks/Roads_Data_Processing_backend_data_4.ipynb +25 -306
- notebooks/YOLOv8_Pothole_Detector_Training_frontend_public_models_1.ipynb +191 -877
- scripts/backend/data/__init__.py +1 -0
- scripts/scripts/data/__init__.py +1 -0
- scripts/scripts/data/_overpass_utils.py +2 -3
- scripts/scripts/data/bootstrap_local_data.py +0 -1
- scripts/scripts/data/fetch_ambulance.py +4 -1
- scripts/scripts/data/fetch_blood_banks.py +4 -1
- scripts/scripts/data/fetch_fire.py +4 -1
- scripts/scripts/data/fetch_hospitals.py +4 -1
- scripts/scripts/data/fetch_police.py +4 -1
README.md
CHANGED
|
@@ -50,12 +50,10 @@ SafeVisionAI-Dataset-Hub/
|
|
| 50 |
│ ├── chatbot_service/data/ ← Legal PDFs, GIS CSVs, accident data, models
|
| 51 |
│ └── backend/datasets/ ← Challan rules, road infrastructure
|
| 52 |
│
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
│
|
| 58 |
-
└── notebooks/ ← Research notebooks and analysis
|
| 59 |
```
|
| 60 |
|
| 61 |
---
|
|
@@ -144,9 +142,21 @@ python scripts/scripts/data/verify_data.py
|
|
| 144 |
|
| 145 |
---
|
| 146 |
|
| 147 |
-
## 📓 Notebooks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
-
|
| 150 |
|
| 151 |
---
|
| 152 |
|
|
|
|
| 50 |
│ ├── chatbot_service/data/ ← Legal PDFs, GIS CSVs, accident data, models
|
| 51 |
│ └── backend/datasets/ ← Challan rules, road infrastructure
|
| 52 |
│
|
| 53 |
+
└── scripts/ ← Reproducible data acquisition pipeline
|
| 54 |
+
├── scripts/data/ ← Root-level data scripts (fetchers, extractors)
|
| 55 |
+
├── backend/data/ ← Backend data transforms (pure Python)
|
| 56 |
+
└── chatbot_service/data/ ← Pro Overpass GIS fetchers
|
|
|
|
|
|
|
| 57 |
```
|
| 58 |
|
| 59 |
---
|
|
|
|
| 142 |
|
| 143 |
---
|
| 144 |
|
| 145 |
+
## 📓 Research Notebooks — Open in Colab
|
| 146 |
+
|
| 147 |
+
> We advise running all notebooks through **Google Colab** for the easiest setup. Colab gives you a free T4 GPU with 16 GB of VRAM. All notebooks were built and tested on Colab, so it is the most stable platform. Any other cloud provider should work too.
|
| 148 |
+
|
| 149 |
+
| # | Notebook | What It Produces | Open in Colab |
|
| 150 |
+
|---|---|---|---|
|
| 151 |
+
| 1 | **YOLOv8 Pothole Detector Training** | ONNX road damage model | [](https://colab.research.google.com/drive/1oe4Gk899lFB_vbRMUuOh4dqpsa3bbycI) |
|
| 152 |
+
| 2 | **ChromaDB RAG Vectorstore Build** | ChromaDB index for legal RAG | [](https://colab.research.google.com/drive/1AzPdN9xjcjW20ko0shTYn0mvbxTUw57Q) |
|
| 153 |
+
| 3 | **Accident EDA & Hotspot Generator** | Blackspot seed CSV + heatmap | [](https://colab.research.google.com/drive/1xh_lwv_B_jc0_83dvuNppWQRtVhqExTS) |
|
| 154 |
+
| 4 | **Roads Data Processing** | Sampled PMGSY GeoJSON | [](https://colab.research.google.com/drive/10_WfTlbbxW9A7ceQBZGaKF5UkydlUDin#scrollTo=z4XxGZmx0ymX) |
|
| 155 |
+
| 5 | **Risk Model ONNX Training** | Risk scoring ONNX model | [](https://colab.research.google.com/drive/16IH-rn3CedYtfIpJP4iLa_KUjvfy8hAY) |
|
| 156 |
+
|
| 157 |
+
**Recommended run order:** `1 → 2 → 3 → 4 → 5`
|
| 158 |
|
| 159 |
+
> Each notebook auto-clones this Hub at the start — no manual data setup needed.
|
| 160 |
|
| 161 |
---
|
| 162 |
|
notebooks/Accident_EDA_&_Hotspot_Generator_chatbot_service_data_accidents_3.ipynb
CHANGED
|
@@ -1,70 +1,41 @@
|
|
| 1 |
{
|
| 2 |
-
"nbformat": 4,
|
| 3 |
-
"nbformat_minor": 0,
|
| 4 |
-
"metadata": {
|
| 5 |
-
"colab": {
|
| 6 |
-
"provenance": []
|
| 7 |
-
},
|
| 8 |
-
"kernelspec": {
|
| 9 |
-
"name": "python3",
|
| 10 |
-
"display_name": "Python 3"
|
| 11 |
-
},
|
| 12 |
-
"language_info": {
|
| 13 |
-
"name": "python"
|
| 14 |
-
}
|
| 15 |
-
},
|
| 16 |
"cells": [
|
| 17 |
{
|
| 18 |
"cell_type": "markdown",
|
| 19 |
"metadata": {},
|
| 20 |
"source": [
|
| 21 |
-
"#
|
| 22 |
"\n",
|
| 23 |
-
"**
|
| 24 |
-
"**Output:** `accidents_summary.json` + `blackspot_seed.csv` → seeded to the backend database\n",
|
| 25 |
"\n",
|
| 26 |
-
"This notebook processes the
|
| 27 |
"to produce two key intelligence artifacts:\n",
|
| 28 |
"\n",
|
| 29 |
-
"1. **`accidents_summary.json`**
|
| 30 |
-
"2. **`blackspot_seed.csv`**
|
| 31 |
"\n",
|
| 32 |
"---\n",
|
| 33 |
-
"###
|
| 34 |
"- **Source:** Kaggle India Road Accidents dataset\n",
|
| 35 |
-
"- **Size:** ~1,048,575 rows
|
| 36 |
-
"- **Acquired via:** `setup_kaggle.ps1` + `scripts/data/seed_blackspots.py`\n",
|
| 37 |
"\n",
|
| 38 |
-
"###
|
| 39 |
-
"``
|
| 40 |
-
"Raw CSV → Normalize columns → State summary → GPS cluster → blackspot_seed.csv\n",
|
| 41 |
-
"```"
|
| 42 |
]
|
| 43 |
},
|
| 44 |
{
|
| 45 |
"cell_type": "markdown",
|
| 46 |
"metadata": {},
|
| 47 |
"source": [
|
| 48 |
-
"##
|
| 49 |
"\n",
|
| 50 |
"Upload `kaggle_india_accidents.csv` from:\n",
|
| 51 |
-
"``
|
| 52 |
-
"chatbot_service/data/accidents/kaggle_india_accidents.csv\n",
|
| 53 |
-
"```\n",
|
| 54 |
-
"\n",
|
| 55 |
-
"> ⚠️ This file is ~450MB. The Hub stores it via Git LFS."
|
| 56 |
]
|
| 57 |
},
|
| 58 |
{
|
| 59 |
"cell_type": "code",
|
| 60 |
-
"
|
| 61 |
-
"# Cell 0 — Upload Dataset\n",
|
| 62 |
-
"from google.colab import files\n",
|
| 63 |
-
"print(\"▶ UPLOAD your accidents CSV dataset NOW:\")\n",
|
| 64 |
-
"uploaded = files.upload()\n",
|
| 65 |
-
"filename = list(uploaded.keys())[0]\n",
|
| 66 |
-
"print(f\"✅ Uploaded {filename}\")\n"
|
| 67 |
-
],
|
| 68 |
"metadata": {
|
| 69 |
"colab": {
|
| 70 |
"base_uri": "https://localhost:8080/",
|
|
@@ -74,229 +45,24 @@
|
|
| 74 |
"id": "wTQPiBKuOGj6",
|
| 75 |
"outputId": "567b68a9-fb9e-43b3-faae-75d66a415c7e"
|
| 76 |
},
|
| 77 |
-
"
|
| 78 |
-
"
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
},
|
| 86 |
-
{
|
| 87 |
-
"output_type": "display_data",
|
| 88 |
-
"data": {
|
| 89 |
-
"text/plain": [
|
| 90 |
-
"<IPython.core.display.HTML object>"
|
| 91 |
-
],
|
| 92 |
-
"text/html": [
|
| 93 |
-
"\n",
|
| 94 |
-
" <input type=\"file\" id=\"files-01711289-8cfe-4504-80ed-65a482b6a4c7\" name=\"files[]\" multiple disabled\n",
|
| 95 |
-
" style=\"border:none\" />\n",
|
| 96 |
-
" <output id=\"result-01711289-8cfe-4504-80ed-65a482b6a4c7\">\n",
|
| 97 |
-
" Upload widget is only available when the cell has been executed in the\n",
|
| 98 |
-
" current browser session. Please rerun this cell to enable.\n",
|
| 99 |
-
" </output>\n",
|
| 100 |
-
" <script>// Copyright 2017 Google LLC\n",
|
| 101 |
-
"//\n",
|
| 102 |
-
"// Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
| 103 |
-
"// you may not use this file except in compliance with the License.\n",
|
| 104 |
-
"// You may obtain a copy of the License at\n",
|
| 105 |
-
"//\n",
|
| 106 |
-
"// http://www.apache.org/licenses/LICENSE-2.0\n",
|
| 107 |
-
"//\n",
|
| 108 |
-
"// Unless required by applicable law or agreed to in writing, software\n",
|
| 109 |
-
"// distributed under the License is distributed on an \"AS IS\" BASIS,\n",
|
| 110 |
-
"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
|
| 111 |
-
"// See the License for the specific language governing permissions and\n",
|
| 112 |
-
"// limitations under the License.\n",
|
| 113 |
-
"\n",
|
| 114 |
-
"/**\n",
|
| 115 |
-
" * @fileoverview Helpers for google.colab Python module.\n",
|
| 116 |
-
" */\n",
|
| 117 |
-
"(function(scope) {\n",
|
| 118 |
-
"function span(text, styleAttributes = {}) {\n",
|
| 119 |
-
" const element = document.createElement('span');\n",
|
| 120 |
-
" element.textContent = text;\n",
|
| 121 |
-
" for (const key of Object.keys(styleAttributes)) {\n",
|
| 122 |
-
" element.style[key] = styleAttributes[key];\n",
|
| 123 |
-
" }\n",
|
| 124 |
-
" return element;\n",
|
| 125 |
-
"}\n",
|
| 126 |
-
"\n",
|
| 127 |
-
"// Max number of bytes which will be uploaded at a time.\n",
|
| 128 |
-
"const MAX_PAYLOAD_SIZE = 100 * 1024;\n",
|
| 129 |
-
"\n",
|
| 130 |
-
"function _uploadFiles(inputId, outputId) {\n",
|
| 131 |
-
" const steps = uploadFilesStep(inputId, outputId);\n",
|
| 132 |
-
" const outputElement = document.getElementById(outputId);\n",
|
| 133 |
-
" // Cache steps on the outputElement to make it available for the next call\n",
|
| 134 |
-
" // to uploadFilesContinue from Python.\n",
|
| 135 |
-
" outputElement.steps = steps;\n",
|
| 136 |
-
"\n",
|
| 137 |
-
" return _uploadFilesContinue(outputId);\n",
|
| 138 |
-
"}\n",
|
| 139 |
-
"\n",
|
| 140 |
-
"// This is roughly an async generator (not supported in the browser yet),\n",
|
| 141 |
-
"// where there are multiple asynchronous steps and the Python side is going\n",
|
| 142 |
-
"// to poll for completion of each step.\n",
|
| 143 |
-
"// This uses a Promise to block the python side on completion of each step,\n",
|
| 144 |
-
"// then passes the result of the previous step as the input to the next step.\n",
|
| 145 |
-
"function _uploadFilesContinue(outputId) {\n",
|
| 146 |
-
" const outputElement = document.getElementById(outputId);\n",
|
| 147 |
-
" const steps = outputElement.steps;\n",
|
| 148 |
-
"\n",
|
| 149 |
-
" const next = steps.next(outputElement.lastPromiseValue);\n",
|
| 150 |
-
" return Promise.resolve(next.value.promise).then((value) => {\n",
|
| 151 |
-
" // Cache the last promise value to make it available to the next\n",
|
| 152 |
-
" // step of the generator.\n",
|
| 153 |
-
" outputElement.lastPromiseValue = value;\n",
|
| 154 |
-
" return next.value.response;\n",
|
| 155 |
-
" });\n",
|
| 156 |
-
"}\n",
|
| 157 |
-
"\n",
|
| 158 |
-
"/**\n",
|
| 159 |
-
" * Generator function which is called between each async step of the upload\n",
|
| 160 |
-
" * process.\n",
|
| 161 |
-
" * @param {string} inputId Element ID of the input file picker element.\n",
|
| 162 |
-
" * @param {string} outputId Element ID of the output display.\n",
|
| 163 |
-
" * @return {!Iterable<!Object>} Iterable of next steps.\n",
|
| 164 |
-
" */\n",
|
| 165 |
-
"function* uploadFilesStep(inputId, outputId) {\n",
|
| 166 |
-
" const inputElement = document.getElementById(inputId);\n",
|
| 167 |
-
" inputElement.disabled = false;\n",
|
| 168 |
-
"\n",
|
| 169 |
-
" const outputElement = document.getElementById(outputId);\n",
|
| 170 |
-
" outputElement.innerHTML = '';\n",
|
| 171 |
-
"\n",
|
| 172 |
-
" const pickedPromise = new Promise((resolve) => {\n",
|
| 173 |
-
" inputElement.addEventListener('change', (e) => {\n",
|
| 174 |
-
" resolve(e.target.files);\n",
|
| 175 |
-
" });\n",
|
| 176 |
-
" });\n",
|
| 177 |
-
"\n",
|
| 178 |
-
" const cancel = document.createElement('button');\n",
|
| 179 |
-
" inputElement.parentElement.appendChild(cancel);\n",
|
| 180 |
-
" cancel.textContent = 'Cancel upload';\n",
|
| 181 |
-
" const cancelPromise = new Promise((resolve) => {\n",
|
| 182 |
-
" cancel.onclick = () => {\n",
|
| 183 |
-
" resolve(null);\n",
|
| 184 |
-
" };\n",
|
| 185 |
-
" });\n",
|
| 186 |
-
"\n",
|
| 187 |
-
" // Wait for the user to pick the files.\n",
|
| 188 |
-
" const files = yield {\n",
|
| 189 |
-
" promise: Promise.race([pickedPromise, cancelPromise]),\n",
|
| 190 |
-
" response: {\n",
|
| 191 |
-
" action: 'starting',\n",
|
| 192 |
-
" }\n",
|
| 193 |
-
" };\n",
|
| 194 |
-
"\n",
|
| 195 |
-
" cancel.remove();\n",
|
| 196 |
-
"\n",
|
| 197 |
-
" // Disable the input element since further picks are not allowed.\n",
|
| 198 |
-
" inputElement.disabled = true;\n",
|
| 199 |
-
"\n",
|
| 200 |
-
" if (!files) {\n",
|
| 201 |
-
" return {\n",
|
| 202 |
-
" response: {\n",
|
| 203 |
-
" action: 'complete',\n",
|
| 204 |
-
" }\n",
|
| 205 |
-
" };\n",
|
| 206 |
-
" }\n",
|
| 207 |
-
"\n",
|
| 208 |
-
" for (const file of files) {\n",
|
| 209 |
-
" const li = document.createElement('li');\n",
|
| 210 |
-
" li.append(span(file.name, {fontWeight: 'bold'}));\n",
|
| 211 |
-
" li.append(span(\n",
|
| 212 |
-
" `(${file.type || 'n/a'}) - ${file.size} bytes, ` +\n",
|
| 213 |
-
" `last modified: ${\n",
|
| 214 |
-
" file.lastModifiedDate ? file.lastModifiedDate.toLocaleDateString() :\n",
|
| 215 |
-
" 'n/a'} - `));\n",
|
| 216 |
-
" const percent = span('0% done');\n",
|
| 217 |
-
" li.appendChild(percent);\n",
|
| 218 |
-
"\n",
|
| 219 |
-
" outputElement.appendChild(li);\n",
|
| 220 |
-
"\n",
|
| 221 |
-
" const fileDataPromise = new Promise((resolve) => {\n",
|
| 222 |
-
" const reader = new FileReader();\n",
|
| 223 |
-
" reader.onload = (e) => {\n",
|
| 224 |
-
" resolve(e.target.result);\n",
|
| 225 |
-
" };\n",
|
| 226 |
-
" reader.readAsArrayBuffer(file);\n",
|
| 227 |
-
" });\n",
|
| 228 |
-
" // Wait for the data to be ready.\n",
|
| 229 |
-
" let fileData = yield {\n",
|
| 230 |
-
" promise: fileDataPromise,\n",
|
| 231 |
-
" response: {\n",
|
| 232 |
-
" action: 'continue',\n",
|
| 233 |
-
" }\n",
|
| 234 |
-
" };\n",
|
| 235 |
-
"\n",
|
| 236 |
-
" // Use a chunked sending to avoid message size limits. See b/62115660.\n",
|
| 237 |
-
" let position = 0;\n",
|
| 238 |
-
" do {\n",
|
| 239 |
-
" const length = Math.min(fileData.byteLength - position, MAX_PAYLOAD_SIZE);\n",
|
| 240 |
-
" const chunk = new Uint8Array(fileData, position, length);\n",
|
| 241 |
-
" position += length;\n",
|
| 242 |
-
"\n",
|
| 243 |
-
" const base64 = btoa(String.fromCharCode.apply(null, chunk));\n",
|
| 244 |
-
" yield {\n",
|
| 245 |
-
" response: {\n",
|
| 246 |
-
" action: 'append',\n",
|
| 247 |
-
" file: file.name,\n",
|
| 248 |
-
" data: base64,\n",
|
| 249 |
-
" },\n",
|
| 250 |
-
" };\n",
|
| 251 |
-
"\n",
|
| 252 |
-
" let percentDone = fileData.byteLength === 0 ?\n",
|
| 253 |
-
" 100 :\n",
|
| 254 |
-
" Math.round((position / fileData.byteLength) * 100);\n",
|
| 255 |
-
" percent.textContent = `${percentDone}% done`;\n",
|
| 256 |
-
"\n",
|
| 257 |
-
" } while (position < fileData.byteLength);\n",
|
| 258 |
-
" }\n",
|
| 259 |
-
"\n",
|
| 260 |
-
" // All done.\n",
|
| 261 |
-
" yield {\n",
|
| 262 |
-
" response: {\n",
|
| 263 |
-
" action: 'complete',\n",
|
| 264 |
-
" }\n",
|
| 265 |
-
" };\n",
|
| 266 |
-
"}\n",
|
| 267 |
-
"\n",
|
| 268 |
-
"scope.google = scope.google || {};\n",
|
| 269 |
-
"scope.google.colab = scope.google.colab || {};\n",
|
| 270 |
-
"scope.google.colab._files = {\n",
|
| 271 |
-
" _uploadFiles,\n",
|
| 272 |
-
" _uploadFilesContinue,\n",
|
| 273 |
-
"};\n",
|
| 274 |
-
"})(self);\n",
|
| 275 |
-
"</script> "
|
| 276 |
-
]
|
| 277 |
-
},
|
| 278 |
-
"metadata": {}
|
| 279 |
-
},
|
| 280 |
-
{
|
| 281 |
-
"output_type": "stream",
|
| 282 |
-
"name": "stdout",
|
| 283 |
-
"text": [
|
| 284 |
-
"Saving kaggle_india_accidents.csv to kaggle_india_accidents.csv\n",
|
| 285 |
-
"✅ Uploaded kaggle_india_accidents.csv\n"
|
| 286 |
-
]
|
| 287 |
-
}
|
| 288 |
]
|
| 289 |
},
|
| 290 |
{
|
| 291 |
"cell_type": "markdown",
|
| 292 |
"metadata": {},
|
| 293 |
"source": [
|
| 294 |
-
"##
|
| 295 |
"\n",
|
| 296 |
"Reads the CSV and normalizes all column names to lowercase snake_case.\n",
|
| 297 |
-
"Result: **1,048,575 rows** of accident records across Indian states.
|
| 298 |
-
"\n",
|
| 299 |
-
"> 💡 The mixed-type DtypeWarning is expected for columns with mixed numeric/string data."
|
| 300 |
]
|
| 301 |
},
|
| 302 |
{
|
|
@@ -309,23 +75,7 @@
|
|
| 309 |
"id": "4HztHudkL-4I",
|
| 310 |
"outputId": "c7c242da-9ff8-43f7-aa30-65260e9e11f6"
|
| 311 |
},
|
| 312 |
-
"outputs": [
|
| 313 |
-
{
|
| 314 |
-
"output_type": "stream",
|
| 315 |
-
"name": "stderr",
|
| 316 |
-
"text": [
|
| 317 |
-
"/tmp/ipykernel_3268/1948449410.py:3: DtypeWarning: Columns (8,10,28,29) have mixed types. Specify dtype option on import or set low_memory=False.\n",
|
| 318 |
-
" df = pd.read_csv(filename)\n"
|
| 319 |
-
]
|
| 320 |
-
},
|
| 321 |
-
{
|
| 322 |
-
"output_type": "stream",
|
| 323 |
-
"name": "stdout",
|
| 324 |
-
"text": [
|
| 325 |
-
"Loaded accidents dataset with 1048575 rows.\n"
|
| 326 |
-
]
|
| 327 |
-
}
|
| 328 |
-
],
|
| 329 |
"source": [
|
| 330 |
"# Cell 1 — Read baseline datasets\n",
|
| 331 |
"import pandas as pd, json\n",
|
|
@@ -338,18 +88,28 @@
|
|
| 338 |
"cell_type": "markdown",
|
| 339 |
"metadata": {},
|
| 340 |
"source": [
|
| 341 |
-
"##
|
| 342 |
"\n",
|
| 343 |
"Auto-detects the `state` and `accident` columns using flexible column name matching,\n",
|
| 344 |
"then computes:\n",
|
| 345 |
-
"- **National total**
|
| 346 |
-
"- **Top 10 states**
|
| 347 |
"\n",
|
| 348 |
-
"Exports `accidents_summary.json`
|
| 349 |
]
|
| 350 |
},
|
| 351 |
{
|
| 352 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
"source": [
|
| 354 |
"# Cell 2 — Generate Summary JSON\n",
|
| 355 |
"state_col = next((c for c in df.columns if 'state' in c), None)\n",
|
|
@@ -365,104 +125,33 @@
|
|
| 365 |
"\n",
|
| 366 |
"from google.colab import files\n",
|
| 367 |
"files.download('accidents_summary.json')\n"
|
| 368 |
-
],
|
| 369 |
-
"metadata": {
|
| 370 |
-
"colab": {
|
| 371 |
-
"base_uri": "https://localhost:8080/",
|
| 372 |
-
"height": 17
|
| 373 |
-
},
|
| 374 |
-
"id": "IgLUOAYzQBEv",
|
| 375 |
-
"outputId": "8edb7410-47fb-40bb-cdc9-7920ce04ab94"
|
| 376 |
-
},
|
| 377 |
-
"execution_count": null,
|
| 378 |
-
"outputs": [
|
| 379 |
-
{
|
| 380 |
-
"output_type": "display_data",
|
| 381 |
-
"data": {
|
| 382 |
-
"text/plain": [
|
| 383 |
-
"<IPython.core.display.Javascript object>"
|
| 384 |
-
],
|
| 385 |
-
"application/javascript": [
|
| 386 |
-
"\n",
|
| 387 |
-
" async function download(id, filename, size) {\n",
|
| 388 |
-
" if (!google.colab.kernel.accessAllowed) {\n",
|
| 389 |
-
" return;\n",
|
| 390 |
-
" }\n",
|
| 391 |
-
" const div = document.createElement('div');\n",
|
| 392 |
-
" const label = document.createElement('label');\n",
|
| 393 |
-
" label.textContent = `Downloading \"${filename}\": `;\n",
|
| 394 |
-
" div.appendChild(label);\n",
|
| 395 |
-
" const progress = document.createElement('progress');\n",
|
| 396 |
-
" progress.max = size;\n",
|
| 397 |
-
" div.appendChild(progress);\n",
|
| 398 |
-
" document.body.appendChild(div);\n",
|
| 399 |
-
"\n",
|
| 400 |
-
" const buffers = [];\n",
|
| 401 |
-
" let downloaded = 0;\n",
|
| 402 |
-
"\n",
|
| 403 |
-
" const channel = await google.colab.kernel.comms.open(id);\n",
|
| 404 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 405 |
-
" channel.send({})\n",
|
| 406 |
-
"\n",
|
| 407 |
-
" for await (const message of channel.messages) {\n",
|
| 408 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 409 |
-
" channel.send({})\n",
|
| 410 |
-
" if (message.buffers) {\n",
|
| 411 |
-
" for (const buffer of message.buffers) {\n",
|
| 412 |
-
" buffers.push(buffer);\n",
|
| 413 |
-
" downloaded += buffer.byteLength;\n",
|
| 414 |
-
" progress.value = downloaded;\n",
|
| 415 |
-
" }\n",
|
| 416 |
-
" }\n",
|
| 417 |
-
" }\n",
|
| 418 |
-
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
|
| 419 |
-
" const a = document.createElement('a');\n",
|
| 420 |
-
" a.href = window.URL.createObjectURL(blob);\n",
|
| 421 |
-
" a.download = filename;\n",
|
| 422 |
-
" div.appendChild(a);\n",
|
| 423 |
-
" a.click();\n",
|
| 424 |
-
" div.remove();\n",
|
| 425 |
-
" }\n",
|
| 426 |
-
" "
|
| 427 |
-
]
|
| 428 |
-
},
|
| 429 |
-
"metadata": {}
|
| 430 |
-
},
|
| 431 |
-
{
|
| 432 |
-
"output_type": "display_data",
|
| 433 |
-
"data": {
|
| 434 |
-
"text/plain": [
|
| 435 |
-
"<IPython.core.display.Javascript object>"
|
| 436 |
-
],
|
| 437 |
-
"application/javascript": [
|
| 438 |
-
"download(\"download_2b3f12d6-506f-4044-ae13-0e57fca04323\", \"accidents_summary.json\", 34)"
|
| 439 |
-
]
|
| 440 |
-
},
|
| 441 |
-
"metadata": {}
|
| 442 |
-
}
|
| 443 |
]
|
| 444 |
},
|
| 445 |
{
|
| 446 |
"cell_type": "markdown",
|
| 447 |
"metadata": {},
|
| 448 |
"source": [
|
| 449 |
-
"##
|
| 450 |
"\n",
|
| 451 |
-
"Groups accident records by rounded GPS coordinates (2 decimal places
|
| 452 |
"then counts accidents per grid cell.\n",
|
| 453 |
"\n",
|
| 454 |
"Result: **4,134 blackspot clusters** exported as `blackspot_seed.csv`\n",
|
| 455 |
-
"
|
| 456 |
-
"\n",
|
| 457 |
-
"| Column | Description |\n",
|
| 458 |
-
"|--------|-------------|\n",
|
| 459 |
-
"| `lat_r` | Rounded latitude (±0.01°) |\n",
|
| 460 |
-
"| `lon_r` | Rounded longitude (±0.01°) |\n",
|
| 461 |
-
"| `accident_count` | Number of accidents in this 1km² cell |"
|
| 462 |
]
|
| 463 |
},
|
| 464 |
{
|
| 465 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
"source": [
|
| 467 |
"# Cell 3 — Process raw GPS tags into hotspot clusters\n",
|
| 468 |
"lat_col = next((c for c in df.columns if 'lat' in c), None)\n",
|
|
@@ -481,89 +170,21 @@
|
|
| 481 |
" files.download('blackspot_seed.csv')\n",
|
| 482 |
"else:\n",
|
| 483 |
" print(\"⚠️ No Latitude/Longitude column found in dataset, skipping cluster generation.\")\n"
|
| 484 |
-
],
|
| 485 |
-
"metadata": {
|
| 486 |
-
"id": "m_EfTgwrQKqn",
|
| 487 |
-
"outputId": "8bbe7036-74e1-4b45-87af-c7991f50a72a",
|
| 488 |
-
"colab": {
|
| 489 |
-
"base_uri": "https://localhost:8080/",
|
| 490 |
-
"height": 34
|
| 491 |
-
}
|
| 492 |
-
},
|
| 493 |
-
"execution_count": null,
|
| 494 |
-
"outputs": [
|
| 495 |
-
{
|
| 496 |
-
"output_type": "stream",
|
| 497 |
-
"name": "stdout",
|
| 498 |
-
"text": [
|
| 499 |
-
"✅ Generated blackspot_seed.csv with 4134 clusters\n"
|
| 500 |
-
]
|
| 501 |
-
},
|
| 502 |
-
{
|
| 503 |
-
"output_type": "display_data",
|
| 504 |
-
"data": {
|
| 505 |
-
"text/plain": [
|
| 506 |
-
"<IPython.core.display.Javascript object>"
|
| 507 |
-
],
|
| 508 |
-
"application/javascript": [
|
| 509 |
-
"\n",
|
| 510 |
-
" async function download(id, filename, size) {\n",
|
| 511 |
-
" if (!google.colab.kernel.accessAllowed) {\n",
|
| 512 |
-
" return;\n",
|
| 513 |
-
" }\n",
|
| 514 |
-
" const div = document.createElement('div');\n",
|
| 515 |
-
" const label = document.createElement('label');\n",
|
| 516 |
-
" label.textContent = `Downloading \"${filename}\": `;\n",
|
| 517 |
-
" div.appendChild(label);\n",
|
| 518 |
-
" const progress = document.createElement('progress');\n",
|
| 519 |
-
" progress.max = size;\n",
|
| 520 |
-
" div.appendChild(progress);\n",
|
| 521 |
-
" document.body.appendChild(div);\n",
|
| 522 |
-
"\n",
|
| 523 |
-
" const buffers = [];\n",
|
| 524 |
-
" let downloaded = 0;\n",
|
| 525 |
-
"\n",
|
| 526 |
-
" const channel = await google.colab.kernel.comms.open(id);\n",
|
| 527 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 528 |
-
" channel.send({})\n",
|
| 529 |
-
"\n",
|
| 530 |
-
" for await (const message of channel.messages) {\n",
|
| 531 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 532 |
-
" channel.send({})\n",
|
| 533 |
-
" if (message.buffers) {\n",
|
| 534 |
-
" for (const buffer of message.buffers) {\n",
|
| 535 |
-
" buffers.push(buffer);\n",
|
| 536 |
-
" downloaded += buffer.byteLength;\n",
|
| 537 |
-
" progress.value = downloaded;\n",
|
| 538 |
-
" }\n",
|
| 539 |
-
" }\n",
|
| 540 |
-
" }\n",
|
| 541 |
-
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
|
| 542 |
-
" const a = document.createElement('a');\n",
|
| 543 |
-
" a.href = window.URL.createObjectURL(blob);\n",
|
| 544 |
-
" a.download = filename;\n",
|
| 545 |
-
" div.appendChild(a);\n",
|
| 546 |
-
" a.click();\n",
|
| 547 |
-
" div.remove();\n",
|
| 548 |
-
" }\n",
|
| 549 |
-
" "
|
| 550 |
-
]
|
| 551 |
-
},
|
| 552 |
-
"metadata": {}
|
| 553 |
-
},
|
| 554 |
-
{
|
| 555 |
-
"output_type": "display_data",
|
| 556 |
-
"data": {
|
| 557 |
-
"text/plain": [
|
| 558 |
-
"<IPython.core.display.Javascript object>"
|
| 559 |
-
],
|
| 560 |
-
"application/javascript": [
|
| 561 |
-
"download(\"download_62de5a95-9cc1-4094-b715-fd75a0df45d2\", \"blackspot_seed.csv\", 84624)"
|
| 562 |
-
]
|
| 563 |
-
},
|
| 564 |
-
"metadata": {}
|
| 565 |
-
}
|
| 566 |
]
|
| 567 |
}
|
| 568 |
-
]
|
| 569 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "markdown",
|
| 5 |
"metadata": {},
|
| 6 |
"source": [
|
| 7 |
+
"# Accident EDA & Blackspot Hotspot Generator\n",
|
| 8 |
"\n",
|
| 9 |
+
"**Output:** `accidents_summary.json` + `blackspot_seed.csv` -> seeded to the backend database\n",
|
|
|
|
| 10 |
"\n",
|
| 11 |
+
"This notebook processes the Kaggle India Road Accidents dataset\n",
|
| 12 |
"to produce two key intelligence artifacts:\n",
|
| 13 |
"\n",
|
| 14 |
+
"1. **`accidents_summary.json`** - National total + top 10 states by accident count\n",
|
| 15 |
+
"2. **`blackspot_seed.csv`** - GPS clusters with accident counts for map hotspot visualization\n",
|
| 16 |
"\n",
|
| 17 |
"---\n",
|
| 18 |
+
"### Dataset\n",
|
| 19 |
"- **Source:** Kaggle India Road Accidents dataset\n",
|
| 20 |
+
"- **Size:** ~1,048,575 rows x 30+ columns\n",
|
|
|
|
| 21 |
"\n",
|
| 22 |
+
"### Pipeline\n",
|
| 23 |
+
"`Raw CSV -> Normalize columns -> State summary -> GPS cluster -> blackspot_seed.csv`"
|
|
|
|
|
|
|
| 24 |
]
|
| 25 |
},
|
| 26 |
{
|
| 27 |
"cell_type": "markdown",
|
| 28 |
"metadata": {},
|
| 29 |
"source": [
|
| 30 |
+
"## Step 0 - Upload Accidents Dataset\n",
|
| 31 |
"\n",
|
| 32 |
"Upload `kaggle_india_accidents.csv` from:\n",
|
| 33 |
+
"`chatbot_service/data/accidents/kaggle_india_accidents.csv`"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
]
|
| 35 |
},
|
| 36 |
{
|
| 37 |
"cell_type": "code",
|
| 38 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
"metadata": {
|
| 40 |
"colab": {
|
| 41 |
"base_uri": "https://localhost:8080/",
|
|
|
|
| 45 |
"id": "wTQPiBKuOGj6",
|
| 46 |
"outputId": "567b68a9-fb9e-43b3-faae-75d66a415c7e"
|
| 47 |
},
|
| 48 |
+
"outputs": [],
|
| 49 |
+
"source": [
|
| 50 |
+
"# Cell 0 — Upload Dataset\n",
|
| 51 |
+
"from google.colab import files\n",
|
| 52 |
+
"print(\"▶ UPLOAD your accidents CSV dataset NOW:\")\n",
|
| 53 |
+
"uploaded = files.upload()\n",
|
| 54 |
+
"filename = list(uploaded.keys())[0]\n",
|
| 55 |
+
"print(f\"✅ Uploaded {filename}\")\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
]
|
| 57 |
},
|
| 58 |
{
|
| 59 |
"cell_type": "markdown",
|
| 60 |
"metadata": {},
|
| 61 |
"source": [
|
| 62 |
+
"## Step 1 - Load & Normalize Dataset\n",
|
| 63 |
"\n",
|
| 64 |
"Reads the CSV and normalizes all column names to lowercase snake_case.\n",
|
| 65 |
+
"Result: **1,048,575 rows** of accident records across Indian states."
|
|
|
|
|
|
|
| 66 |
]
|
| 67 |
},
|
| 68 |
{
|
|
|
|
| 75 |
"id": "4HztHudkL-4I",
|
| 76 |
"outputId": "c7c242da-9ff8-43f7-aa30-65260e9e11f6"
|
| 77 |
},
|
| 78 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
"source": [
|
| 80 |
"# Cell 1 — Read baseline datasets\n",
|
| 81 |
"import pandas as pd, json\n",
|
|
|
|
| 88 |
"cell_type": "markdown",
|
| 89 |
"metadata": {},
|
| 90 |
"source": [
|
| 91 |
+
"## Step 2 - Generate National Summary JSON\n",
|
| 92 |
"\n",
|
| 93 |
"Auto-detects the `state` and `accident` columns using flexible column name matching,\n",
|
| 94 |
"then computes:\n",
|
| 95 |
+
"- **National total** - sum of all accident counts\n",
|
| 96 |
+
"- **Top 10 states** - ranked by accident volume\n",
|
| 97 |
"\n",
|
| 98 |
+
"Exports `accidents_summary.json` - used by the chatbot to answer national stats queries."
|
| 99 |
]
|
| 100 |
},
|
| 101 |
{
|
| 102 |
"cell_type": "code",
|
| 103 |
+
"execution_count": null,
|
| 104 |
+
"metadata": {
|
| 105 |
+
"colab": {
|
| 106 |
+
"base_uri": "https://localhost:8080/",
|
| 107 |
+
"height": 17
|
| 108 |
+
},
|
| 109 |
+
"id": "IgLUOAYzQBEv",
|
| 110 |
+
"outputId": "8edb7410-47fb-40bb-cdc9-7920ce04ab94"
|
| 111 |
+
},
|
| 112 |
+
"outputs": [],
|
| 113 |
"source": [
|
| 114 |
"# Cell 2 — Generate Summary JSON\n",
|
| 115 |
"state_col = next((c for c in df.columns if 'state' in c), None)\n",
|
|
|
|
| 125 |
"\n",
|
| 126 |
"from google.colab import files\n",
|
| 127 |
"files.download('accidents_summary.json')\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
]
|
| 129 |
},
|
| 130 |
{
|
| 131 |
"cell_type": "markdown",
|
| 132 |
"metadata": {},
|
| 133 |
"source": [
|
| 134 |
+
"## Step 3 - Generate GPS Blackspot Clusters\n",
|
| 135 |
"\n",
|
| 136 |
+
"Groups accident records by rounded GPS coordinates (2 decimal places = ~1km^2),\n",
|
| 137 |
"then counts accidents per grid cell.\n",
|
| 138 |
"\n",
|
| 139 |
"Result: **4,134 blackspot clusters** exported as `blackspot_seed.csv`\n",
|
| 140 |
+
"-> This CSV is loaded by `backend/scripts/app/seed_emergency.py` to populate the PostGIS accident layer."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
]
|
| 142 |
},
|
| 143 |
{
|
| 144 |
"cell_type": "code",
|
| 145 |
+
"execution_count": null,
|
| 146 |
+
"metadata": {
|
| 147 |
+
"colab": {
|
| 148 |
+
"base_uri": "https://localhost:8080/",
|
| 149 |
+
"height": 34
|
| 150 |
+
},
|
| 151 |
+
"id": "m_EfTgwrQKqn",
|
| 152 |
+
"outputId": "8bbe7036-74e1-4b45-87af-c7991f50a72a"
|
| 153 |
+
},
|
| 154 |
+
"outputs": [],
|
| 155 |
"source": [
|
| 156 |
"# Cell 3 — Process raw GPS tags into hotspot clusters\n",
|
| 157 |
"lat_col = next((c for c in df.columns if 'lat' in c), None)\n",
|
|
|
|
| 170 |
" files.download('blackspot_seed.csv')\n",
|
| 171 |
"else:\n",
|
| 172 |
" print(\"⚠️ No Latitude/Longitude column found in dataset, skipping cluster generation.\")\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
]
|
| 174 |
}
|
| 175 |
+
],
|
| 176 |
+
"metadata": {
|
| 177 |
+
"colab": {
|
| 178 |
+
"provenance": []
|
| 179 |
+
},
|
| 180 |
+
"kernelspec": {
|
| 181 |
+
"display_name": "Python 3",
|
| 182 |
+
"name": "python3"
|
| 183 |
+
},
|
| 184 |
+
"language_info": {
|
| 185 |
+
"name": "python"
|
| 186 |
+
}
|
| 187 |
+
},
|
| 188 |
+
"nbformat": 4,
|
| 189 |
+
"nbformat_minor": 0
|
| 190 |
+
}
|
notebooks/ChromaDB_RAG_Vectorstore_Build_chatbot_service_data_chroma_db_2.ipynb
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/Risk_Model_ONNX_Training_frontend_public_models_5.ipynb
CHANGED
|
@@ -1,111 +1,99 @@
|
|
| 1 |
{
|
| 2 |
-
"nbformat": 4,
|
| 3 |
-
"nbformat_minor": 0,
|
| 4 |
-
"metadata": {
|
| 5 |
-
"colab": {
|
| 6 |
-
"provenance": []
|
| 7 |
-
},
|
| 8 |
-
"kernelspec": {
|
| 9 |
-
"name": "python3",
|
| 10 |
-
"display_name": "Python 3"
|
| 11 |
-
},
|
| 12 |
-
"language_info": {
|
| 13 |
-
"name": "python"
|
| 14 |
-
}
|
| 15 |
-
},
|
| 16 |
"cells": [
|
| 17 |
{
|
| 18 |
"cell_type": "markdown",
|
| 19 |
-
"metadata": {
|
|
|
|
|
|
|
| 20 |
"source": [
|
| 21 |
-
"#
|
| 22 |
"\n",
|
| 23 |
-
"**
|
| 24 |
-
"**Output:** `risk_model.onnx` (~21KB) → deployed to `frontend/public/models/`\n",
|
| 25 |
"\n",
|
| 26 |
"This notebook trains a **GradientBoosting classifier** to predict real-time road risk\n",
|
| 27 |
-
"and exports it as ONNX for **in-browser inference**
|
| 28 |
"\n",
|
| 29 |
"---\n",
|
| 30 |
-
"###
|
| 31 |
"| Component | Details |\n",
|
| 32 |
"|-----------|--------|\n",
|
| 33 |
"| Algorithm | GradientBoostingClassifier |\n",
|
| 34 |
"| Input features | 5 (road type, hour, rain, speed limit, prev accidents) |\n",
|
| 35 |
-
"| Output | Binary:
|
| 36 |
-
"| Export | ONNX via
|
| 37 |
-
"| Size | ~21KB
|
| 38 |
"\n",
|
| 39 |
-
"###
|
| 40 |
-
"
|
| 41 |
-
"Synthetic data generation → GBM training → ONNX conversion → Download\n",
|
| 42 |
-
"```\n",
|
| 43 |
"\n",
|
| 44 |
-
">
|
| 45 |
]
|
| 46 |
},
|
| 47 |
{
|
| 48 |
"cell_type": "markdown",
|
| 49 |
-
"metadata": {
|
|
|
|
|
|
|
| 50 |
"source": [
|
| 51 |
-
"##
|
| 52 |
"\n",
|
| 53 |
"Installs the minimum stack needed for training and ONNX export:\n",
|
| 54 |
-
"-
|
| 55 |
-
"-
|
| 56 |
-
"-
|
| 57 |
]
|
| 58 |
},
|
| 59 |
{
|
| 60 |
"cell_type": "code",
|
| 61 |
"execution_count": null,
|
| 62 |
"metadata": {
|
| 63 |
-
"id": "3o_vWikZQvNu",
|
| 64 |
"colab": {
|
| 65 |
"base_uri": "https://localhost:8080/"
|
| 66 |
},
|
| 67 |
"collapsed": true,
|
|
|
|
| 68 |
"outputId": "93304cbf-747d-46f7-b4c3-7ceeb5be730a"
|
| 69 |
},
|
| 70 |
-
"outputs": [
|
| 71 |
-
{
|
| 72 |
-
"output_type": "stream",
|
| 73 |
-
"name": "stdout",
|
| 74 |
-
"text": [
|
| 75 |
-
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m317.2/317.2 kB\u001b[0m \u001b[31m5.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 76 |
-
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.6/17.6 MB\u001b[0m \u001b[31m39.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 77 |
-
"\u001b[?25h✅ Toolkit installed\n"
|
| 78 |
-
]
|
| 79 |
-
}
|
| 80 |
-
],
|
| 81 |
"source": [
|
| 82 |
-
"# Cell 1 — Install ML Toolkit\n",
|
| 83 |
"!pip install scikit-learn skl2onnx pandas numpy -q\n",
|
| 84 |
"print(\"✅ Toolkit installed\")\n"
|
| 85 |
]
|
| 86 |
},
|
| 87 |
{
|
| 88 |
"cell_type": "markdown",
|
| 89 |
-
"metadata": {
|
|
|
|
|
|
|
| 90 |
"source": [
|
| 91 |
-
"##
|
| 92 |
"\n",
|
| 93 |
"Generates 5,000 synthetic road sensor records matching the live app's data structure:\n",
|
| 94 |
"\n",
|
| 95 |
"| Feature | Values | Description |\n",
|
| 96 |
"|---------|--------|-------------|\n",
|
| 97 |
-
"|
|
| 98 |
-
"|
|
| 99 |
-
"|
|
| 100 |
-
"|
|
| 101 |
-
"|
|
| 102 |
"\n",
|
| 103 |
-
"**Label logic:**
|
| 104 |
"This reflects real-world patterns from the India accident dataset."
|
| 105 |
]
|
| 106 |
},
|
| 107 |
{
|
| 108 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
"source": [
|
| 110 |
"# Cell 2 — Build synthetic data matching sensor ingestion structure\n",
|
| 111 |
"import pandas as pd, numpy as np\n",
|
|
@@ -126,47 +114,25 @@
|
|
| 126 |
"y = df['high_risk']\n",
|
| 127 |
"\n",
|
| 128 |
"print(\"✅ Data matrix ready. Rows:\", len(X))\n"
|
| 129 |
-
],
|
| 130 |
-
"metadata": {
|
| 131 |
-
"colab": {
|
| 132 |
-
"base_uri": "https://localhost:8080/"
|
| 133 |
-
},
|
| 134 |
-
"id": "9Z-Ne1O6RWL4",
|
| 135 |
-
"outputId": "54542fc2-6ea3-443c-8660-20c5c04f1f32"
|
| 136 |
-
},
|
| 137 |
-
"execution_count": null,
|
| 138 |
-
"outputs": [
|
| 139 |
-
{
|
| 140 |
-
"output_type": "stream",
|
| 141 |
-
"name": "stdout",
|
| 142 |
-
"text": [
|
| 143 |
-
"✅ Data matrix ready. Rows: 5000\n"
|
| 144 |
-
]
|
| 145 |
-
}
|
| 146 |
]
|
| 147 |
},
|
| 148 |
{
|
| 149 |
"cell_type": "markdown",
|
| 150 |
-
"metadata": {
|
|
|
|
|
|
|
| 151 |
"source": [
|
| 152 |
-
"##
|
| 153 |
"\n",
|
| 154 |
"Trains a GBM with 50 estimators and max depth 4:\n",
|
| 155 |
-
"-
|
| 156 |
-
"-
|
| 157 |
-
"-
|
| 158 |
]
|
| 159 |
},
|
| 160 |
{
|
| 161 |
"cell_type": "code",
|
| 162 |
-
"
|
| 163 |
-
"# Cell 3 — Train the GradientBoosting Classifier\n",
|
| 164 |
-
"from sklearn.ensemble import GradientBoostingClassifier\n",
|
| 165 |
-
"\n",
|
| 166 |
-
"model = GradientBoostingClassifier(n_estimators=50, max_depth=4)\n",
|
| 167 |
-
"model.fit(X, y)\n",
|
| 168 |
-
"print(\"✅ Risk AI Training finished\")\n"
|
| 169 |
-
],
|
| 170 |
"metadata": {
|
| 171 |
"colab": {
|
| 172 |
"base_uri": "https://localhost:8080/"
|
|
@@ -174,39 +140,48 @@
|
|
| 174 |
"id": "u44C8piURguc",
|
| 175 |
"outputId": "1c4cd374-a46b-4585-fc76-3bf53a455a36"
|
| 176 |
},
|
| 177 |
-
"
|
| 178 |
-
"
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
}
|
| 186 |
]
|
| 187 |
},
|
| 188 |
{
|
| 189 |
"cell_type": "markdown",
|
| 190 |
-
"metadata": {
|
|
|
|
|
|
|
| 191 |
"source": [
|
| 192 |
-
"##
|
| 193 |
"\n",
|
| 194 |
-
"Converts the trained sklearn model to ONNX format using
|
| 195 |
-
"-
|
| 196 |
-
"-
|
| 197 |
"\n",
|
| 198 |
-
"Download
|
| 199 |
-
"```\n",
|
| 200 |
"frontend/public/models/risk_model.onnx\n",
|
| 201 |
-
"```\n",
|
| 202 |
"\n",
|
| 203 |
"The Next.js PWA loads this at startup and runs inference on each map segment click.\n",
|
| 204 |
"\n",
|
| 205 |
-
">
|
| 206 |
]
|
| 207 |
},
|
| 208 |
{
|
| 209 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
"source": [
|
| 211 |
"# Cell 4 — Package as ONNX and Export\n",
|
| 212 |
"from skl2onnx import convert_sklearn\n",
|
|
@@ -221,89 +196,21 @@
|
|
| 221 |
"\n",
|
| 222 |
"print(f\"✅ Executed. Output size: {len(onx.SerializeToString())//1024} KB\")\n",
|
| 223 |
"files.download('risk_model.onnx')\n"
|
| 224 |
-
],
|
| 225 |
-
"metadata": {
|
| 226 |
-
"colab": {
|
| 227 |
-
"base_uri": "https://localhost:8080/",
|
| 228 |
-
"height": 34
|
| 229 |
-
},
|
| 230 |
-
"id": "6P3PgQeLRk3l",
|
| 231 |
-
"outputId": "60c8d868-91d5-411a-ec9d-5eed21132fb4"
|
| 232 |
-
},
|
| 233 |
-
"execution_count": null,
|
| 234 |
-
"outputs": [
|
| 235 |
-
{
|
| 236 |
-
"output_type": "stream",
|
| 237 |
-
"name": "stdout",
|
| 238 |
-
"text": [
|
| 239 |
-
"✅ Executed. Output size: 21 KB\n"
|
| 240 |
-
]
|
| 241 |
-
},
|
| 242 |
-
{
|
| 243 |
-
"output_type": "display_data",
|
| 244 |
-
"data": {
|
| 245 |
-
"text/plain": [
|
| 246 |
-
"<IPython.core.display.Javascript object>"
|
| 247 |
-
],
|
| 248 |
-
"application/javascript": [
|
| 249 |
-
"\n",
|
| 250 |
-
" async function download(id, filename, size) {\n",
|
| 251 |
-
" if (!google.colab.kernel.accessAllowed) {\n",
|
| 252 |
-
" return;\n",
|
| 253 |
-
" }\n",
|
| 254 |
-
" const div = document.createElement('div');\n",
|
| 255 |
-
" const label = document.createElement('label');\n",
|
| 256 |
-
" label.textContent = `Downloading \"${filename}\": `;\n",
|
| 257 |
-
" div.appendChild(label);\n",
|
| 258 |
-
" const progress = document.createElement('progress');\n",
|
| 259 |
-
" progress.max = size;\n",
|
| 260 |
-
" div.appendChild(progress);\n",
|
| 261 |
-
" document.body.appendChild(div);\n",
|
| 262 |
-
"\n",
|
| 263 |
-
" const buffers = [];\n",
|
| 264 |
-
" let downloaded = 0;\n",
|
| 265 |
-
"\n",
|
| 266 |
-
" const channel = await google.colab.kernel.comms.open(id);\n",
|
| 267 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 268 |
-
" channel.send({})\n",
|
| 269 |
-
"\n",
|
| 270 |
-
" for await (const message of channel.messages) {\n",
|
| 271 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 272 |
-
" channel.send({})\n",
|
| 273 |
-
" if (message.buffers) {\n",
|
| 274 |
-
" for (const buffer of message.buffers) {\n",
|
| 275 |
-
" buffers.push(buffer);\n",
|
| 276 |
-
" downloaded += buffer.byteLength;\n",
|
| 277 |
-
" progress.value = downloaded;\n",
|
| 278 |
-
" }\n",
|
| 279 |
-
" }\n",
|
| 280 |
-
" }\n",
|
| 281 |
-
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
|
| 282 |
-
" const a = document.createElement('a');\n",
|
| 283 |
-
" a.href = window.URL.createObjectURL(blob);\n",
|
| 284 |
-
" a.download = filename;\n",
|
| 285 |
-
" div.appendChild(a);\n",
|
| 286 |
-
" a.click();\n",
|
| 287 |
-
" div.remove();\n",
|
| 288 |
-
" }\n",
|
| 289 |
-
" "
|
| 290 |
-
]
|
| 291 |
-
},
|
| 292 |
-
"metadata": {}
|
| 293 |
-
},
|
| 294 |
-
{
|
| 295 |
-
"output_type": "display_data",
|
| 296 |
-
"data": {
|
| 297 |
-
"text/plain": [
|
| 298 |
-
"<IPython.core.display.Javascript object>"
|
| 299 |
-
],
|
| 300 |
-
"application/javascript": [
|
| 301 |
-
"download(\"download_59bb67d1-88b7-4e30-b14c-3e17e37cdf7b\", \"risk_model.onnx\", 22021)"
|
| 302 |
-
]
|
| 303 |
-
},
|
| 304 |
-
"metadata": {}
|
| 305 |
-
}
|
| 306 |
]
|
| 307 |
}
|
| 308 |
-
]
|
| 309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "markdown",
|
| 5 |
+
"metadata": {
|
| 6 |
+
"id": "oTSGY7DGoU40"
|
| 7 |
+
},
|
| 8 |
"source": [
|
| 9 |
+
"# Road Risk Scoring Model - ONNX Training Pipeline\n",
|
| 10 |
"\n",
|
| 11 |
+
"**Output:** risk_model.onnx (~21KB) -> deployed to frontend/public/models/\n",
|
|
|
|
| 12 |
"\n",
|
| 13 |
"This notebook trains a **GradientBoosting classifier** to predict real-time road risk\n",
|
| 14 |
+
"and exports it as ONNX for **in-browser inference** - no server call needed.\n",
|
| 15 |
"\n",
|
| 16 |
"---\n",
|
| 17 |
+
"### Model Architecture\n",
|
| 18 |
"| Component | Details |\n",
|
| 19 |
"|-----------|--------|\n",
|
| 20 |
"| Algorithm | GradientBoostingClassifier |\n",
|
| 21 |
"| Input features | 5 (road type, hour, rain, speed limit, prev accidents) |\n",
|
| 22 |
+
"| Output | Binary: high_risk (0 or 1) |\n",
|
| 23 |
+
"| Export | ONNX via skl2onnx |\n",
|
| 24 |
+
"| Size | ~21KB - loads in milliseconds in browser |\n",
|
| 25 |
"\n",
|
| 26 |
+
"### Pipeline\n",
|
| 27 |
+
"Synthetic data generation -> GBM training -> ONNX conversion -> Download\n",
|
|
|
|
|
|
|
| 28 |
"\n",
|
| 29 |
+
"> The model runs entirely client-side in the SafeVisionAI PWA using onnxruntime-web."
|
| 30 |
]
|
| 31 |
},
|
| 32 |
{
|
| 33 |
"cell_type": "markdown",
|
| 34 |
+
"metadata": {
|
| 35 |
+
"id": "n-fQwvTSpkuQ"
|
| 36 |
+
},
|
| 37 |
"source": [
|
| 38 |
+
"## Step 1 - Install ML Toolkit\n",
|
| 39 |
"\n",
|
| 40 |
"Installs the minimum stack needed for training and ONNX export:\n",
|
| 41 |
+
"- scikit-learn - GradientBoostingClassifier\n",
|
| 42 |
+
"- skl2onnx - converts sklearn models to ONNX format\n",
|
| 43 |
+
"- pandas + numpy - data generation and manipulation"
|
| 44 |
]
|
| 45 |
},
|
| 46 |
{
|
| 47 |
"cell_type": "code",
|
| 48 |
"execution_count": null,
|
| 49 |
"metadata": {
|
|
|
|
| 50 |
"colab": {
|
| 51 |
"base_uri": "https://localhost:8080/"
|
| 52 |
},
|
| 53 |
"collapsed": true,
|
| 54 |
+
"id": "3o_vWikZQvNu",
|
| 55 |
"outputId": "93304cbf-747d-46f7-b4c3-7ceeb5be730a"
|
| 56 |
},
|
| 57 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
"source": [
|
| 59 |
+
"# Cell 1 — Install ML Toolkit#\n",
|
| 60 |
"!pip install scikit-learn skl2onnx pandas numpy -q\n",
|
| 61 |
"print(\"✅ Toolkit installed\")\n"
|
| 62 |
]
|
| 63 |
},
|
| 64 |
{
|
| 65 |
"cell_type": "markdown",
|
| 66 |
+
"metadata": {
|
| 67 |
+
"id": "qfw5vFUup0FI"
|
| 68 |
+
},
|
| 69 |
"source": [
|
| 70 |
+
"## Step 2 - Build Synthetic Training Data\n",
|
| 71 |
"\n",
|
| 72 |
"Generates 5,000 synthetic road sensor records matching the live app's data structure:\n",
|
| 73 |
"\n",
|
| 74 |
"| Feature | Values | Description |\n",
|
| 75 |
"|---------|--------|-------------|\n",
|
| 76 |
+
"| road_type | 0-3 | NH=0, SH=1, MDR=2, VR=3 |\n",
|
| 77 |
+
"| hour | 0-23 | Hour of day |\n",
|
| 78 |
+
"| is_rain | 0/1 | Weather condition |\n",
|
| 79 |
+
"| speed_limit | 40/60/80/100 | Posted speed (km/h) |\n",
|
| 80 |
+
"| prev_accidents | Poisson(2) | Historical accident count |\n",
|
| 81 |
"\n",
|
| 82 |
+
"**Label logic:** high_risk = 1 when: Night hours (10pm-4am) + National/State Highway + Raining\n",
|
| 83 |
"This reflects real-world patterns from the India accident dataset."
|
| 84 |
]
|
| 85 |
},
|
| 86 |
{
|
| 87 |
"cell_type": "code",
|
| 88 |
+
"execution_count": null,
|
| 89 |
+
"metadata": {
|
| 90 |
+
"colab": {
|
| 91 |
+
"base_uri": "https://localhost:8080/"
|
| 92 |
+
},
|
| 93 |
+
"id": "9Z-Ne1O6RWL4",
|
| 94 |
+
"outputId": "54542fc2-6ea3-443c-8660-20c5c04f1f32"
|
| 95 |
+
},
|
| 96 |
+
"outputs": [],
|
| 97 |
"source": [
|
| 98 |
"# Cell 2 — Build synthetic data matching sensor ingestion structure\n",
|
| 99 |
"import pandas as pd, numpy as np\n",
|
|
|
|
| 114 |
"y = df['high_risk']\n",
|
| 115 |
"\n",
|
| 116 |
"print(\"✅ Data matrix ready. Rows:\", len(X))\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
]
|
| 118 |
},
|
| 119 |
{
|
| 120 |
"cell_type": "markdown",
|
| 121 |
+
"metadata": {
|
| 122 |
+
"id": "VPDAt6HIp99N"
|
| 123 |
+
},
|
| 124 |
"source": [
|
| 125 |
+
"## Step 3 - Train GradientBoosting Classifier\n",
|
| 126 |
"\n",
|
| 127 |
"Trains a GBM with 50 estimators and max depth 4:\n",
|
| 128 |
+
"- Fast: <10 seconds on CPU\n",
|
| 129 |
+
"- Accurate: Handles non-linear risk patterns well\n",
|
| 130 |
+
"- Tiny: Converts to 21KB ONNX - ideal for edge/PWA deployment"
|
| 131 |
]
|
| 132 |
},
|
| 133 |
{
|
| 134 |
"cell_type": "code",
|
| 135 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
"metadata": {
|
| 137 |
"colab": {
|
| 138 |
"base_uri": "https://localhost:8080/"
|
|
|
|
| 140 |
"id": "u44C8piURguc",
|
| 141 |
"outputId": "1c4cd374-a46b-4585-fc76-3bf53a455a36"
|
| 142 |
},
|
| 143 |
+
"outputs": [],
|
| 144 |
+
"source": [
|
| 145 |
+
"# Cell 3 — Train the GradientBoosting Classifier\n",
|
| 146 |
+
"from sklearn.ensemble import GradientBoostingClassifier\n",
|
| 147 |
+
"\n",
|
| 148 |
+
"model = GradientBoostingClassifier(n_estimators=50, max_depth=4)\n",
|
| 149 |
+
"model.fit(X, y)\n",
|
| 150 |
+
"print(\"✅ Risk AI Training finished\")\n"
|
|
|
|
| 151 |
]
|
| 152 |
},
|
| 153 |
{
|
| 154 |
"cell_type": "markdown",
|
| 155 |
+
"metadata": {
|
| 156 |
+
"id": "W8suzsAJqEom"
|
| 157 |
+
},
|
| 158 |
"source": [
|
| 159 |
+
"## Step 4 - Export to ONNX & Download\n",
|
| 160 |
"\n",
|
| 161 |
+
"Converts the trained sklearn model to ONNX format using skl2onnx:\n",
|
| 162 |
+
"- Input: FloatTensorType([None, 5]) - batch of 5-feature vectors\n",
|
| 163 |
+
"- Output: Risk probability + binary class label\n",
|
| 164 |
"\n",
|
| 165 |
+
"Download risk_model.onnx and place at:\n",
|
|
|
|
| 166 |
"frontend/public/models/risk_model.onnx\n",
|
|
|
|
| 167 |
"\n",
|
| 168 |
"The Next.js PWA loads this at startup and runs inference on each map segment click.\n",
|
| 169 |
"\n",
|
| 170 |
+
"> Final output: ~21KB ONNX model - ready for browser deployment"
|
| 171 |
]
|
| 172 |
},
|
| 173 |
{
|
| 174 |
"cell_type": "code",
|
| 175 |
+
"execution_count": null,
|
| 176 |
+
"metadata": {
|
| 177 |
+
"colab": {
|
| 178 |
+
"base_uri": "https://localhost:8080/",
|
| 179 |
+
"height": 34
|
| 180 |
+
},
|
| 181 |
+
"id": "6P3PgQeLRk3l",
|
| 182 |
+
"outputId": "60c8d868-91d5-411a-ec9d-5eed21132fb4"
|
| 183 |
+
},
|
| 184 |
+
"outputs": [],
|
| 185 |
"source": [
|
| 186 |
"# Cell 4 — Package as ONNX and Export\n",
|
| 187 |
"from skl2onnx import convert_sklearn\n",
|
|
|
|
| 196 |
"\n",
|
| 197 |
"print(f\"✅ Executed. Output size: {len(onx.SerializeToString())//1024} KB\")\n",
|
| 198 |
"files.download('risk_model.onnx')\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
]
|
| 200 |
}
|
| 201 |
+
],
|
| 202 |
+
"metadata": {
|
| 203 |
+
"colab": {
|
| 204 |
+
"provenance": []
|
| 205 |
+
},
|
| 206 |
+
"kernelspec": {
|
| 207 |
+
"display_name": "Python 3",
|
| 208 |
+
"name": "python3"
|
| 209 |
+
},
|
| 210 |
+
"language_info": {
|
| 211 |
+
"name": "python"
|
| 212 |
+
}
|
| 213 |
+
},
|
| 214 |
+
"nbformat": 4,
|
| 215 |
+
"nbformat_minor": 0
|
| 216 |
+
}
|
notebooks/Roads_Data_Processing_backend_data_4.ipynb
CHANGED
|
@@ -1,53 +1,33 @@
|
|
| 1 |
{
|
| 2 |
-
"nbformat": 4,
|
| 3 |
-
"nbformat_minor": 0,
|
| 4 |
-
"metadata": {
|
| 5 |
-
"colab": {
|
| 6 |
-
"provenance": []
|
| 7 |
-
},
|
| 8 |
-
"kernelspec": {
|
| 9 |
-
"name": "python3",
|
| 10 |
-
"display_name": "Python 3"
|
| 11 |
-
},
|
| 12 |
-
"language_info": {
|
| 13 |
-
"name": "python"
|
| 14 |
-
}
|
| 15 |
-
},
|
| 16 |
"cells": [
|
| 17 |
{
|
| 18 |
"cell_type": "markdown",
|
| 19 |
"metadata": {},
|
| 20 |
"source": [
|
| 21 |
-
"#
|
| 22 |
"\n",
|
| 23 |
-
"**
|
| 24 |
-
"**Output:** `toll_plazas_lite.json` → deployed to `backend/data/roads/`\n",
|
| 25 |
"\n",
|
| 26 |
"This notebook processes the **NHAI Toll Plaza dataset** to produce a lightweight JSON\n",
|
| 27 |
"suitable for the SafeVisionAI backend API and offline PWA map layer.\n",
|
| 28 |
"\n",
|
| 29 |
"---\n",
|
| 30 |
-
"###
|
| 31 |
"- **Source:** NHAI Open Data / custom toll_plazas.csv\n",
|
| 32 |
"- **Fields:** Name, NH Number, Latitude, Longitude\n",
|
| 33 |
"- **Coverage:** All operational toll plazas on National Highways\n",
|
| 34 |
"\n",
|
| 35 |
-
"###
|
| 36 |
-
"``
|
| 37 |
-
"toll_plazas.csv → Select key columns → Rename headers → Export toll_plazas_lite.json\n",
|
| 38 |
-
"```"
|
| 39 |
]
|
| 40 |
},
|
| 41 |
{
|
| 42 |
"cell_type": "markdown",
|
| 43 |
"metadata": {},
|
| 44 |
"source": [
|
| 45 |
-
"##
|
| 46 |
"\n",
|
| 47 |
-
"Upload `toll_plazas.csv` from
|
| 48 |
-
"```\n",
|
| 49 |
-
"backend/data/roads/toll_plazas.csv\n",
|
| 50 |
-
"```\n",
|
| 51 |
"\n",
|
| 52 |
"The processing pipeline:\n",
|
| 53 |
"1. Reads the CSV with `pandas`\n",
|
|
@@ -57,9 +37,7 @@
|
|
| 57 |
"5. Exports as `toll_plazas_lite.json`\n",
|
| 58 |
"\n",
|
| 59 |
"The resulting JSON is consumed by the backend `/api/roads/tolls` endpoint\n",
|
| 60 |
-
"and the offline PWA map layer for toll overlay rendering.
|
| 61 |
-
"\n",
|
| 62 |
-
"> 📦 Output size: ~65KB (vs 2MB+ raw CSV)"
|
| 63 |
]
|
| 64 |
},
|
| 65 |
{
|
|
@@ -73,280 +51,7 @@
|
|
| 73 |
"id": "RjBm7RAZO-O0",
|
| 74 |
"outputId": "beacaaad-3b29-4737-8664-ee8c2d92a645"
|
| 75 |
},
|
| 76 |
-
"outputs": [
|
| 77 |
-
{
|
| 78 |
-
"output_type": "stream",
|
| 79 |
-
"name": "stdout",
|
| 80 |
-
"text": [
|
| 81 |
-
"▶ UPLOAD your toll_plazas.csv NOW:\n"
|
| 82 |
-
]
|
| 83 |
-
},
|
| 84 |
-
{
|
| 85 |
-
"output_type": "display_data",
|
| 86 |
-
"data": {
|
| 87 |
-
"text/plain": [
|
| 88 |
-
"<IPython.core.display.HTML object>"
|
| 89 |
-
],
|
| 90 |
-
"text/html": [
|
| 91 |
-
"\n",
|
| 92 |
-
" <input type=\"file\" id=\"files-0ae94269-bb4f-4460-9755-4fbbca3368bb\" name=\"files[]\" multiple disabled\n",
|
| 93 |
-
" style=\"border:none\" />\n",
|
| 94 |
-
" <output id=\"result-0ae94269-bb4f-4460-9755-4fbbca3368bb\">\n",
|
| 95 |
-
" Upload widget is only available when the cell has been executed in the\n",
|
| 96 |
-
" current browser session. Please rerun this cell to enable.\n",
|
| 97 |
-
" </output>\n",
|
| 98 |
-
" <script>// Copyright 2017 Google LLC\n",
|
| 99 |
-
"//\n",
|
| 100 |
-
"// Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
| 101 |
-
"// you may not use this file except in compliance with the License.\n",
|
| 102 |
-
"// You may obtain a copy of the License at\n",
|
| 103 |
-
"//\n",
|
| 104 |
-
"// http://www.apache.org/licenses/LICENSE-2.0\n",
|
| 105 |
-
"//\n",
|
| 106 |
-
"// Unless required by applicable law or agreed to in writing, software\n",
|
| 107 |
-
"// distributed under the License is distributed on an \"AS IS\" BASIS,\n",
|
| 108 |
-
"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
|
| 109 |
-
"// See the License for the specific language governing permissions and\n",
|
| 110 |
-
"// limitations under the License.\n",
|
| 111 |
-
"\n",
|
| 112 |
-
"/**\n",
|
| 113 |
-
" * @fileoverview Helpers for google.colab Python module.\n",
|
| 114 |
-
" */\n",
|
| 115 |
-
"(function(scope) {\n",
|
| 116 |
-
"function span(text, styleAttributes = {}) {\n",
|
| 117 |
-
" const element = document.createElement('span');\n",
|
| 118 |
-
" element.textContent = text;\n",
|
| 119 |
-
" for (const key of Object.keys(styleAttributes)) {\n",
|
| 120 |
-
" element.style[key] = styleAttributes[key];\n",
|
| 121 |
-
" }\n",
|
| 122 |
-
" return element;\n",
|
| 123 |
-
"}\n",
|
| 124 |
-
"\n",
|
| 125 |
-
"// Max number of bytes which will be uploaded at a time.\n",
|
| 126 |
-
"const MAX_PAYLOAD_SIZE = 100 * 1024;\n",
|
| 127 |
-
"\n",
|
| 128 |
-
"function _uploadFiles(inputId, outputId) {\n",
|
| 129 |
-
" const steps = uploadFilesStep(inputId, outputId);\n",
|
| 130 |
-
" const outputElement = document.getElementById(outputId);\n",
|
| 131 |
-
" // Cache steps on the outputElement to make it available for the next call\n",
|
| 132 |
-
" // to uploadFilesContinue from Python.\n",
|
| 133 |
-
" outputElement.steps = steps;\n",
|
| 134 |
-
"\n",
|
| 135 |
-
" return _uploadFilesContinue(outputId);\n",
|
| 136 |
-
"}\n",
|
| 137 |
-
"\n",
|
| 138 |
-
"// This is roughly an async generator (not supported in the browser yet),\n",
|
| 139 |
-
"// where there are multiple asynchronous steps and the Python side is going\n",
|
| 140 |
-
"// to poll for completion of each step.\n",
|
| 141 |
-
"// This uses a Promise to block the python side on completion of each step,\n",
|
| 142 |
-
"// then passes the result of the previous step as the input to the next step.\n",
|
| 143 |
-
"function _uploadFilesContinue(outputId) {\n",
|
| 144 |
-
" const outputElement = document.getElementById(outputId);\n",
|
| 145 |
-
" const steps = outputElement.steps;\n",
|
| 146 |
-
"\n",
|
| 147 |
-
" const next = steps.next(outputElement.lastPromiseValue);\n",
|
| 148 |
-
" return Promise.resolve(next.value.promise).then((value) => {\n",
|
| 149 |
-
" // Cache the last promise value to make it available to the next\n",
|
| 150 |
-
" // step of the generator.\n",
|
| 151 |
-
" outputElement.lastPromiseValue = value;\n",
|
| 152 |
-
" return next.value.response;\n",
|
| 153 |
-
" });\n",
|
| 154 |
-
"}\n",
|
| 155 |
-
"\n",
|
| 156 |
-
"/**\n",
|
| 157 |
-
" * Generator function which is called between each async step of the upload\n",
|
| 158 |
-
" * process.\n",
|
| 159 |
-
" * @param {string} inputId Element ID of the input file picker element.\n",
|
| 160 |
-
" * @param {string} outputId Element ID of the output display.\n",
|
| 161 |
-
" * @return {!Iterable<!Object>} Iterable of next steps.\n",
|
| 162 |
-
" */\n",
|
| 163 |
-
"function* uploadFilesStep(inputId, outputId) {\n",
|
| 164 |
-
" const inputElement = document.getElementById(inputId);\n",
|
| 165 |
-
" inputElement.disabled = false;\n",
|
| 166 |
-
"\n",
|
| 167 |
-
" const outputElement = document.getElementById(outputId);\n",
|
| 168 |
-
" outputElement.innerHTML = '';\n",
|
| 169 |
-
"\n",
|
| 170 |
-
" const pickedPromise = new Promise((resolve) => {\n",
|
| 171 |
-
" inputElement.addEventListener('change', (e) => {\n",
|
| 172 |
-
" resolve(e.target.files);\n",
|
| 173 |
-
" });\n",
|
| 174 |
-
" });\n",
|
| 175 |
-
"\n",
|
| 176 |
-
" const cancel = document.createElement('button');\n",
|
| 177 |
-
" inputElement.parentElement.appendChild(cancel);\n",
|
| 178 |
-
" cancel.textContent = 'Cancel upload';\n",
|
| 179 |
-
" const cancelPromise = new Promise((resolve) => {\n",
|
| 180 |
-
" cancel.onclick = () => {\n",
|
| 181 |
-
" resolve(null);\n",
|
| 182 |
-
" };\n",
|
| 183 |
-
" });\n",
|
| 184 |
-
"\n",
|
| 185 |
-
" // Wait for the user to pick the files.\n",
|
| 186 |
-
" const files = yield {\n",
|
| 187 |
-
" promise: Promise.race([pickedPromise, cancelPromise]),\n",
|
| 188 |
-
" response: {\n",
|
| 189 |
-
" action: 'starting',\n",
|
| 190 |
-
" }\n",
|
| 191 |
-
" };\n",
|
| 192 |
-
"\n",
|
| 193 |
-
" cancel.remove();\n",
|
| 194 |
-
"\n",
|
| 195 |
-
" // Disable the input element since further picks are not allowed.\n",
|
| 196 |
-
" inputElement.disabled = true;\n",
|
| 197 |
-
"\n",
|
| 198 |
-
" if (!files) {\n",
|
| 199 |
-
" return {\n",
|
| 200 |
-
" response: {\n",
|
| 201 |
-
" action: 'complete',\n",
|
| 202 |
-
" }\n",
|
| 203 |
-
" };\n",
|
| 204 |
-
" }\n",
|
| 205 |
-
"\n",
|
| 206 |
-
" for (const file of files) {\n",
|
| 207 |
-
" const li = document.createElement('li');\n",
|
| 208 |
-
" li.append(span(file.name, {fontWeight: 'bold'}));\n",
|
| 209 |
-
" li.append(span(\n",
|
| 210 |
-
" `(${file.type || 'n/a'}) - ${file.size} bytes, ` +\n",
|
| 211 |
-
" `last modified: ${\n",
|
| 212 |
-
" file.lastModifiedDate ? file.lastModifiedDate.toLocaleDateString() :\n",
|
| 213 |
-
" 'n/a'} - `));\n",
|
| 214 |
-
" const percent = span('0% done');\n",
|
| 215 |
-
" li.appendChild(percent);\n",
|
| 216 |
-
"\n",
|
| 217 |
-
" outputElement.appendChild(li);\n",
|
| 218 |
-
"\n",
|
| 219 |
-
" const fileDataPromise = new Promise((resolve) => {\n",
|
| 220 |
-
" const reader = new FileReader();\n",
|
| 221 |
-
" reader.onload = (e) => {\n",
|
| 222 |
-
" resolve(e.target.result);\n",
|
| 223 |
-
" };\n",
|
| 224 |
-
" reader.readAsArrayBuffer(file);\n",
|
| 225 |
-
" });\n",
|
| 226 |
-
" // Wait for the data to be ready.\n",
|
| 227 |
-
" let fileData = yield {\n",
|
| 228 |
-
" promise: fileDataPromise,\n",
|
| 229 |
-
" response: {\n",
|
| 230 |
-
" action: 'continue',\n",
|
| 231 |
-
" }\n",
|
| 232 |
-
" };\n",
|
| 233 |
-
"\n",
|
| 234 |
-
" // Use a chunked sending to avoid message size limits. See b/62115660.\n",
|
| 235 |
-
" let position = 0;\n",
|
| 236 |
-
" do {\n",
|
| 237 |
-
" const length = Math.min(fileData.byteLength - position, MAX_PAYLOAD_SIZE);\n",
|
| 238 |
-
" const chunk = new Uint8Array(fileData, position, length);\n",
|
| 239 |
-
" position += length;\n",
|
| 240 |
-
"\n",
|
| 241 |
-
" const base64 = btoa(String.fromCharCode.apply(null, chunk));\n",
|
| 242 |
-
" yield {\n",
|
| 243 |
-
" response: {\n",
|
| 244 |
-
" action: 'append',\n",
|
| 245 |
-
" file: file.name,\n",
|
| 246 |
-
" data: base64,\n",
|
| 247 |
-
" },\n",
|
| 248 |
-
" };\n",
|
| 249 |
-
"\n",
|
| 250 |
-
" let percentDone = fileData.byteLength === 0 ?\n",
|
| 251 |
-
" 100 :\n",
|
| 252 |
-
" Math.round((position / fileData.byteLength) * 100);\n",
|
| 253 |
-
" percent.textContent = `${percentDone}% done`;\n",
|
| 254 |
-
"\n",
|
| 255 |
-
" } while (position < fileData.byteLength);\n",
|
| 256 |
-
" }\n",
|
| 257 |
-
"\n",
|
| 258 |
-
" // All done.\n",
|
| 259 |
-
" yield {\n",
|
| 260 |
-
" response: {\n",
|
| 261 |
-
" action: 'complete',\n",
|
| 262 |
-
" }\n",
|
| 263 |
-
" };\n",
|
| 264 |
-
"}\n",
|
| 265 |
-
"\n",
|
| 266 |
-
"scope.google = scope.google || {};\n",
|
| 267 |
-
"scope.google.colab = scope.google.colab || {};\n",
|
| 268 |
-
"scope.google.colab._files = {\n",
|
| 269 |
-
" _uploadFiles,\n",
|
| 270 |
-
" _uploadFilesContinue,\n",
|
| 271 |
-
"};\n",
|
| 272 |
-
"})(self);\n",
|
| 273 |
-
"</script> "
|
| 274 |
-
]
|
| 275 |
-
},
|
| 276 |
-
"metadata": {}
|
| 277 |
-
},
|
| 278 |
-
{
|
| 279 |
-
"output_type": "stream",
|
| 280 |
-
"name": "stdout",
|
| 281 |
-
"text": [
|
| 282 |
-
"Saving toll_plazas.csv to toll_plazas (1).csv\n"
|
| 283 |
-
]
|
| 284 |
-
},
|
| 285 |
-
{
|
| 286 |
-
"output_type": "display_data",
|
| 287 |
-
"data": {
|
| 288 |
-
"text/plain": [
|
| 289 |
-
"<IPython.core.display.Javascript object>"
|
| 290 |
-
],
|
| 291 |
-
"application/javascript": [
|
| 292 |
-
"\n",
|
| 293 |
-
" async function download(id, filename, size) {\n",
|
| 294 |
-
" if (!google.colab.kernel.accessAllowed) {\n",
|
| 295 |
-
" return;\n",
|
| 296 |
-
" }\n",
|
| 297 |
-
" const div = document.createElement('div');\n",
|
| 298 |
-
" const label = document.createElement('label');\n",
|
| 299 |
-
" label.textContent = `Downloading \"${filename}\": `;\n",
|
| 300 |
-
" div.appendChild(label);\n",
|
| 301 |
-
" const progress = document.createElement('progress');\n",
|
| 302 |
-
" progress.max = size;\n",
|
| 303 |
-
" div.appendChild(progress);\n",
|
| 304 |
-
" document.body.appendChild(div);\n",
|
| 305 |
-
"\n",
|
| 306 |
-
" const buffers = [];\n",
|
| 307 |
-
" let downloaded = 0;\n",
|
| 308 |
-
"\n",
|
| 309 |
-
" const channel = await google.colab.kernel.comms.open(id);\n",
|
| 310 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 311 |
-
" channel.send({})\n",
|
| 312 |
-
"\n",
|
| 313 |
-
" for await (const message of channel.messages) {\n",
|
| 314 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 315 |
-
" channel.send({})\n",
|
| 316 |
-
" if (message.buffers) {\n",
|
| 317 |
-
" for (const buffer of message.buffers) {\n",
|
| 318 |
-
" buffers.push(buffer);\n",
|
| 319 |
-
" downloaded += buffer.byteLength;\n",
|
| 320 |
-
" progress.value = downloaded;\n",
|
| 321 |
-
" }\n",
|
| 322 |
-
" }\n",
|
| 323 |
-
" }\n",
|
| 324 |
-
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
|
| 325 |
-
" const a = document.createElement('a');\n",
|
| 326 |
-
" a.href = window.URL.createObjectURL(blob);\n",
|
| 327 |
-
" a.download = filename;\n",
|
| 328 |
-
" div.appendChild(a);\n",
|
| 329 |
-
" a.click();\n",
|
| 330 |
-
" div.remove();\n",
|
| 331 |
-
" }\n",
|
| 332 |
-
" "
|
| 333 |
-
]
|
| 334 |
-
},
|
| 335 |
-
"metadata": {}
|
| 336 |
-
},
|
| 337 |
-
{
|
| 338 |
-
"output_type": "display_data",
|
| 339 |
-
"data": {
|
| 340 |
-
"text/plain": [
|
| 341 |
-
"<IPython.core.display.Javascript object>"
|
| 342 |
-
],
|
| 343 |
-
"application/javascript": [
|
| 344 |
-
"download(\"download_210eae57-c408-497c-977e-ce6e97b30a77\", \"toll_plazas_lite.json\", 65010)"
|
| 345 |
-
]
|
| 346 |
-
},
|
| 347 |
-
"metadata": {}
|
| 348 |
-
}
|
| 349 |
-
],
|
| 350 |
"source": [
|
| 351 |
"# Cell 1 — Toll Plazas Lite\n",
|
| 352 |
"import pandas as pd, json\n",
|
|
@@ -370,5 +75,19 @@
|
|
| 370 |
"files.download('toll_plazas_lite.json')\n"
|
| 371 |
]
|
| 372 |
}
|
| 373 |
-
]
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "markdown",
|
| 5 |
"metadata": {},
|
| 6 |
"source": [
|
| 7 |
+
"# Roads & Toll Plaza Data Processing\n",
|
| 8 |
"\n",
|
| 9 |
+
"**Output:** `toll_plazas_lite.json` -> deployed to `backend/data/roads/`\n",
|
|
|
|
| 10 |
"\n",
|
| 11 |
"This notebook processes the **NHAI Toll Plaza dataset** to produce a lightweight JSON\n",
|
| 12 |
"suitable for the SafeVisionAI backend API and offline PWA map layer.\n",
|
| 13 |
"\n",
|
| 14 |
"---\n",
|
| 15 |
+
"### Dataset\n",
|
| 16 |
"- **Source:** NHAI Open Data / custom toll_plazas.csv\n",
|
| 17 |
"- **Fields:** Name, NH Number, Latitude, Longitude\n",
|
| 18 |
"- **Coverage:** All operational toll plazas on National Highways\n",
|
| 19 |
"\n",
|
| 20 |
+
"### Pipeline\n",
|
| 21 |
+
"`toll_plazas.csv -> Select key columns -> Rename headers -> Export toll_plazas_lite.json`"
|
|
|
|
|
|
|
| 22 |
]
|
| 23 |
},
|
| 24 |
{
|
| 25 |
"cell_type": "markdown",
|
| 26 |
"metadata": {},
|
| 27 |
"source": [
|
| 28 |
+
"## Step 1 - Upload & Process Toll Plaza CSV\n",
|
| 29 |
"\n",
|
| 30 |
+
"Upload `toll_plazas.csv` from `backend/data/roads/toll_plazas.csv`\n",
|
|
|
|
|
|
|
|
|
|
| 31 |
"\n",
|
| 32 |
"The processing pipeline:\n",
|
| 33 |
"1. Reads the CSV with `pandas`\n",
|
|
|
|
| 37 |
"5. Exports as `toll_plazas_lite.json`\n",
|
| 38 |
"\n",
|
| 39 |
"The resulting JSON is consumed by the backend `/api/roads/tolls` endpoint\n",
|
| 40 |
+
"and the offline PWA map layer for toll overlay rendering."
|
|
|
|
|
|
|
| 41 |
]
|
| 42 |
},
|
| 43 |
{
|
|
|
|
| 51 |
"id": "RjBm7RAZO-O0",
|
| 52 |
"outputId": "beacaaad-3b29-4737-8664-ee8c2d92a645"
|
| 53 |
},
|
| 54 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
"source": [
|
| 56 |
"# Cell 1 — Toll Plazas Lite\n",
|
| 57 |
"import pandas as pd, json\n",
|
|
|
|
| 75 |
"files.download('toll_plazas_lite.json')\n"
|
| 76 |
]
|
| 77 |
}
|
| 78 |
+
],
|
| 79 |
+
"metadata": {
|
| 80 |
+
"colab": {
|
| 81 |
+
"provenance": []
|
| 82 |
+
},
|
| 83 |
+
"kernelspec": {
|
| 84 |
+
"display_name": "Python 3",
|
| 85 |
+
"name": "python3"
|
| 86 |
+
},
|
| 87 |
+
"language_info": {
|
| 88 |
+
"name": "python"
|
| 89 |
+
}
|
| 90 |
+
},
|
| 91 |
+
"nbformat": 4,
|
| 92 |
+
"nbformat_minor": 0
|
| 93 |
+
}
|
notebooks/YOLOv8_Pothole_Detector_Training_frontend_public_models_1.ipynb
CHANGED
|
@@ -1,47 +1,37 @@
|
|
| 1 |
{
|
| 2 |
-
"nbformat": 4,
|
| 3 |
-
"nbformat_minor": 0,
|
| 4 |
-
"metadata": {
|
| 5 |
-
"colab": {
|
| 6 |
-
"provenance": [],
|
| 7 |
-
"gpuType": "T4"
|
| 8 |
-
},
|
| 9 |
-
"kernelspec": {
|
| 10 |
-
"name": "python3",
|
| 11 |
-
"display_name": "Python 3"
|
| 12 |
-
},
|
| 13 |
-
"language_info": {
|
| 14 |
-
"name": "python"
|
| 15 |
-
},
|
| 16 |
-
"accelerator": "GPU"
|
| 17 |
-
},
|
| 18 |
"cells": [
|
| 19 |
{
|
| 20 |
"cell_type": "markdown",
|
| 21 |
-
"metadata": {
|
|
|
|
|
|
|
| 22 |
"source": [
|
| 23 |
-
"#
|
| 24 |
"\n",
|
| 25 |
-
"**
|
| 26 |
-
"**Output:** `pothole_v1/weights/best.onnx` → deployed to `frontend/public/models/`\n",
|
| 27 |
"\n",
|
| 28 |
-
"This notebook trains a
|
| 29 |
-
"
|
| 30 |
"\n",
|
| 31 |
"---\n",
|
| 32 |
-
"###
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
"
|
| 37 |
-
"| 3 | Extract the zip into `/content/pothole_data/` |\n",
|
| 38 |
-
"| 4 | Create master merged directory structure |\n",
|
| 39 |
-
"| 5 | Merge all dataset images + labels into one folder |\n",
|
| 40 |
-
"| 6 | Write `data.yaml` for 3-class detection |\n",
|
| 41 |
-
"| 7 | Train YOLOv8n for 50 epochs on T4 GPU (~45 min) |\n",
|
| 42 |
-
"| 8 | Export best weights to ONNX |\n",
|
| 43 |
"\n",
|
| 44 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
]
|
| 46 |
},
|
| 47 |
{
|
|
@@ -56,31 +46,7 @@
|
|
| 56 |
"id": "uwTMRE_8C740",
|
| 57 |
"outputId": "ecfb62d6-9b10-4bc0-caa0-971da9a80c3e"
|
| 58 |
},
|
| 59 |
-
"outputs": [
|
| 60 |
-
{
|
| 61 |
-
"output_type": "display_data",
|
| 62 |
-
"data": {
|
| 63 |
-
"text/plain": [
|
| 64 |
-
"<IPython.core.display.Javascript object>"
|
| 65 |
-
],
|
| 66 |
-
"application/javascript": [
|
| 67 |
-
"\n",
|
| 68 |
-
" function ClickConnect(){\n",
|
| 69 |
-
" document.querySelector('#top-toolbar > colab-connect-button').click()\n",
|
| 70 |
-
" }\n",
|
| 71 |
-
" setInterval(ClickConnect, 60000)\n"
|
| 72 |
-
]
|
| 73 |
-
},
|
| 74 |
-
"metadata": {}
|
| 75 |
-
},
|
| 76 |
-
{
|
| 77 |
-
"output_type": "stream",
|
| 78 |
-
"name": "stdout",
|
| 79 |
-
"text": [
|
| 80 |
-
"Anti-disconnect activated\n"
|
| 81 |
-
]
|
| 82 |
-
}
|
| 83 |
-
],
|
| 84 |
"source": [
|
| 85 |
"import time\n",
|
| 86 |
"from IPython.display import Javascript\n",
|
|
@@ -95,22 +61,19 @@
|
|
| 95 |
},
|
| 96 |
{
|
| 97 |
"cell_type": "markdown",
|
| 98 |
-
"metadata": {
|
|
|
|
|
|
|
| 99 |
"source": [
|
| 100 |
-
"##
|
| 101 |
"\n",
|
| 102 |
-
"
|
| 103 |
-
"
|
| 104 |
-
"- `roboflow` — dataset management (optional augmentation)\n",
|
| 105 |
-
"- `onnx` + `onnxruntime` — ONNX export and validation"
|
| 106 |
]
|
| 107 |
},
|
| 108 |
{
|
| 109 |
"cell_type": "code",
|
| 110 |
-
"
|
| 111 |
-
"!pip install ultralytics roboflow -q\n",
|
| 112 |
-
"!pip install onnx onnxruntime -q"
|
| 113 |
-
],
|
| 114 |
"metadata": {
|
| 115 |
"colab": {
|
| 116 |
"base_uri": "https://localhost:8080/"
|
|
@@ -119,42 +82,27 @@
|
|
| 119 |
"id": "I0GBSI74DVJI",
|
| 120 |
"outputId": "a71f5e00-bbe6-458c-c79d-5e9d75c8931f"
|
| 121 |
},
|
| 122 |
-
"
|
| 123 |
-
"
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
"name": "stdout",
|
| 127 |
-
"text": [
|
| 128 |
-
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/1.2 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m54.2 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m34.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 129 |
-
"\u001b[?25h\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/169.5 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m169.5/169.5 kB\u001b[0m \u001b[31m17.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 130 |
-
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m66.8/66.8 kB\u001b[0m \u001b[31m6.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 131 |
-
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.9/49.9 MB\u001b[0m \u001b[31m20.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 132 |
-
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.5/1.5 MB\u001b[0m \u001b[31m77.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 133 |
-
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.5/5.5 MB\u001b[0m \u001b[31m130.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 134 |
-
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.6/17.6 MB\u001b[0m \u001b[31m92.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 135 |
-
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m17.2/17.2 MB\u001b[0m \u001b[31m20.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
|
| 136 |
-
"\u001b[?25h"
|
| 137 |
-
]
|
| 138 |
-
}
|
| 139 |
]
|
| 140 |
},
|
| 141 |
{
|
| 142 |
"cell_type": "markdown",
|
| 143 |
-
"metadata": {
|
|
|
|
|
|
|
| 144 |
"source": [
|
| 145 |
-
"##
|
| 146 |
"\n",
|
| 147 |
-
"
|
|
|
|
| 148 |
]
|
| 149 |
},
|
| 150 |
{
|
| 151 |
"cell_type": "code",
|
| 152 |
-
"
|
| 153 |
-
"\n",
|
| 154 |
-
"import os\n",
|
| 155 |
-
"from ultralytics import YOLO\n",
|
| 156 |
-
"print(\"✅ Ultralytics ready, CUDA:\", os.popen(\"nvidia-smi --query-gpu=name --format=csv,noheader\").read().strip())"
|
| 157 |
-
],
|
| 158 |
"metadata": {
|
| 159 |
"colab": {
|
| 160 |
"base_uri": "https://localhost:8080/"
|
|
@@ -163,39 +111,29 @@
|
|
| 163 |
"id": "yJoIU507DcKF",
|
| 164 |
"outputId": "e92f642d-1464-45e4-ec35-cd3c7eb402bf"
|
| 165 |
},
|
| 166 |
-
"
|
| 167 |
-
"
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
"Creating new Ultralytics Settings v0.0.6 file ✅ \n",
|
| 173 |
-
"View Ultralytics Settings with 'yolo settings' or at '/root/.config/Ultralytics/settings.json'\n",
|
| 174 |
-
"Update Settings with 'yolo settings key=value', i.e. 'yolo settings runs_dir=path/to/dir'. For help see https://docs.ultralytics.com/quickstart/#ultralytics-settings.\n",
|
| 175 |
-
"✅ Ultralytics ready, CUDA: Tesla T4\n"
|
| 176 |
-
]
|
| 177 |
-
}
|
| 178 |
]
|
| 179 |
},
|
| 180 |
{
|
| 181 |
"cell_type": "markdown",
|
| 182 |
-
"metadata": {
|
|
|
|
|
|
|
| 183 |
"source": [
|
| 184 |
-
"##
|
| 185 |
"\n",
|
| 186 |
-
"
|
| 187 |
-
"
|
| 188 |
-
"chatbot_service/data/pothole_training/road_damage_2025/archive.zip\n",
|
| 189 |
-
"```\n",
|
| 190 |
-
"> 📂 This contains ~2,009 labeled road damage images in YOLO format (potholes, cracks, manholes)."
|
| 191 |
]
|
| 192 |
},
|
| 193 |
{
|
| 194 |
"cell_type": "code",
|
| 195 |
-
"
|
| 196 |
-
"from google.colab import files\n",
|
| 197 |
-
"uploaded = files.upload()"
|
| 198 |
-
],
|
| 199 |
"metadata": {
|
| 200 |
"colab": {
|
| 201 |
"base_uri": "https://localhost:8080/",
|
|
@@ -204,231 +142,27 @@
|
|
| 204 |
"id": "t7uQDAFzDeaJ",
|
| 205 |
"outputId": "e5e7f1b4-8a1d-4d91-b2a9-feddd6783794"
|
| 206 |
},
|
| 207 |
-
"
|
| 208 |
-
"
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
"data": {
|
| 212 |
-
"text/plain": [
|
| 213 |
-
"<IPython.core.display.HTML object>"
|
| 214 |
-
],
|
| 215 |
-
"text/html": [
|
| 216 |
-
"\n",
|
| 217 |
-
" <input type=\"file\" id=\"files-24ea8cd9-a427-4ce7-9646-b6a5625d2fc4\" name=\"files[]\" multiple disabled\n",
|
| 218 |
-
" style=\"border:none\" />\n",
|
| 219 |
-
" <output id=\"result-24ea8cd9-a427-4ce7-9646-b6a5625d2fc4\">\n",
|
| 220 |
-
" Upload widget is only available when the cell has been executed in the\n",
|
| 221 |
-
" current browser session. Please rerun this cell to enable.\n",
|
| 222 |
-
" </output>\n",
|
| 223 |
-
" <script>// Copyright 2017 Google LLC\n",
|
| 224 |
-
"//\n",
|
| 225 |
-
"// Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
| 226 |
-
"// you may not use this file except in compliance with the License.\n",
|
| 227 |
-
"// You may obtain a copy of the License at\n",
|
| 228 |
-
"//\n",
|
| 229 |
-
"// http://www.apache.org/licenses/LICENSE-2.0\n",
|
| 230 |
-
"//\n",
|
| 231 |
-
"// Unless required by applicable law or agreed to in writing, software\n",
|
| 232 |
-
"// distributed under the License is distributed on an \"AS IS\" BASIS,\n",
|
| 233 |
-
"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
|
| 234 |
-
"// See the License for the specific language governing permissions and\n",
|
| 235 |
-
"// limitations under the License.\n",
|
| 236 |
-
"\n",
|
| 237 |
-
"/**\n",
|
| 238 |
-
" * @fileoverview Helpers for google.colab Python module.\n",
|
| 239 |
-
" */\n",
|
| 240 |
-
"(function(scope) {\n",
|
| 241 |
-
"function span(text, styleAttributes = {}) {\n",
|
| 242 |
-
" const element = document.createElement('span');\n",
|
| 243 |
-
" element.textContent = text;\n",
|
| 244 |
-
" for (const key of Object.keys(styleAttributes)) {\n",
|
| 245 |
-
" element.style[key] = styleAttributes[key];\n",
|
| 246 |
-
" }\n",
|
| 247 |
-
" return element;\n",
|
| 248 |
-
"}\n",
|
| 249 |
-
"\n",
|
| 250 |
-
"// Max number of bytes which will be uploaded at a time.\n",
|
| 251 |
-
"const MAX_PAYLOAD_SIZE = 100 * 1024;\n",
|
| 252 |
-
"\n",
|
| 253 |
-
"function _uploadFiles(inputId, outputId) {\n",
|
| 254 |
-
" const steps = uploadFilesStep(inputId, outputId);\n",
|
| 255 |
-
" const outputElement = document.getElementById(outputId);\n",
|
| 256 |
-
" // Cache steps on the outputElement to make it available for the next call\n",
|
| 257 |
-
" // to uploadFilesContinue from Python.\n",
|
| 258 |
-
" outputElement.steps = steps;\n",
|
| 259 |
-
"\n",
|
| 260 |
-
" return _uploadFilesContinue(outputId);\n",
|
| 261 |
-
"}\n",
|
| 262 |
-
"\n",
|
| 263 |
-
"// This is roughly an async generator (not supported in the browser yet),\n",
|
| 264 |
-
"// where there are multiple asynchronous steps and the Python side is going\n",
|
| 265 |
-
"// to poll for completion of each step.\n",
|
| 266 |
-
"// This uses a Promise to block the python side on completion of each step,\n",
|
| 267 |
-
"// then passes the result of the previous step as the input to the next step.\n",
|
| 268 |
-
"function _uploadFilesContinue(outputId) {\n",
|
| 269 |
-
" const outputElement = document.getElementById(outputId);\n",
|
| 270 |
-
" const steps = outputElement.steps;\n",
|
| 271 |
-
"\n",
|
| 272 |
-
" const next = steps.next(outputElement.lastPromiseValue);\n",
|
| 273 |
-
" return Promise.resolve(next.value.promise).then((value) => {\n",
|
| 274 |
-
" // Cache the last promise value to make it available to the next\n",
|
| 275 |
-
" // step of the generator.\n",
|
| 276 |
-
" outputElement.lastPromiseValue = value;\n",
|
| 277 |
-
" return next.value.response;\n",
|
| 278 |
-
" });\n",
|
| 279 |
-
"}\n",
|
| 280 |
-
"\n",
|
| 281 |
-
"/**\n",
|
| 282 |
-
" * Generator function which is called between each async step of the upload\n",
|
| 283 |
-
" * process.\n",
|
| 284 |
-
" * @param {string} inputId Element ID of the input file picker element.\n",
|
| 285 |
-
" * @param {string} outputId Element ID of the output display.\n",
|
| 286 |
-
" * @return {!Iterable<!Object>} Iterable of next steps.\n",
|
| 287 |
-
" */\n",
|
| 288 |
-
"function* uploadFilesStep(inputId, outputId) {\n",
|
| 289 |
-
" const inputElement = document.getElementById(inputId);\n",
|
| 290 |
-
" inputElement.disabled = false;\n",
|
| 291 |
-
"\n",
|
| 292 |
-
" const outputElement = document.getElementById(outputId);\n",
|
| 293 |
-
" outputElement.innerHTML = '';\n",
|
| 294 |
-
"\n",
|
| 295 |
-
" const pickedPromise = new Promise((resolve) => {\n",
|
| 296 |
-
" inputElement.addEventListener('change', (e) => {\n",
|
| 297 |
-
" resolve(e.target.files);\n",
|
| 298 |
-
" });\n",
|
| 299 |
-
" });\n",
|
| 300 |
-
"\n",
|
| 301 |
-
" const cancel = document.createElement('button');\n",
|
| 302 |
-
" inputElement.parentElement.appendChild(cancel);\n",
|
| 303 |
-
" cancel.textContent = 'Cancel upload';\n",
|
| 304 |
-
" const cancelPromise = new Promise((resolve) => {\n",
|
| 305 |
-
" cancel.onclick = () => {\n",
|
| 306 |
-
" resolve(null);\n",
|
| 307 |
-
" };\n",
|
| 308 |
-
" });\n",
|
| 309 |
-
"\n",
|
| 310 |
-
" // Wait for the user to pick the files.\n",
|
| 311 |
-
" const files = yield {\n",
|
| 312 |
-
" promise: Promise.race([pickedPromise, cancelPromise]),\n",
|
| 313 |
-
" response: {\n",
|
| 314 |
-
" action: 'starting',\n",
|
| 315 |
-
" }\n",
|
| 316 |
-
" };\n",
|
| 317 |
-
"\n",
|
| 318 |
-
" cancel.remove();\n",
|
| 319 |
-
"\n",
|
| 320 |
-
" // Disable the input element since further picks are not allowed.\n",
|
| 321 |
-
" inputElement.disabled = true;\n",
|
| 322 |
-
"\n",
|
| 323 |
-
" if (!files) {\n",
|
| 324 |
-
" return {\n",
|
| 325 |
-
" response: {\n",
|
| 326 |
-
" action: 'complete',\n",
|
| 327 |
-
" }\n",
|
| 328 |
-
" };\n",
|
| 329 |
-
" }\n",
|
| 330 |
-
"\n",
|
| 331 |
-
" for (const file of files) {\n",
|
| 332 |
-
" const li = document.createElement('li');\n",
|
| 333 |
-
" li.append(span(file.name, {fontWeight: 'bold'}));\n",
|
| 334 |
-
" li.append(span(\n",
|
| 335 |
-
" `(${file.type || 'n/a'}) - ${file.size} bytes, ` +\n",
|
| 336 |
-
" `last modified: ${\n",
|
| 337 |
-
" file.lastModifiedDate ? file.lastModifiedDate.toLocaleDateString() :\n",
|
| 338 |
-
" 'n/a'} - `));\n",
|
| 339 |
-
" const percent = span('0% done');\n",
|
| 340 |
-
" li.appendChild(percent);\n",
|
| 341 |
-
"\n",
|
| 342 |
-
" outputElement.appendChild(li);\n",
|
| 343 |
-
"\n",
|
| 344 |
-
" const fileDataPromise = new Promise((resolve) => {\n",
|
| 345 |
-
" const reader = new FileReader();\n",
|
| 346 |
-
" reader.onload = (e) => {\n",
|
| 347 |
-
" resolve(e.target.result);\n",
|
| 348 |
-
" };\n",
|
| 349 |
-
" reader.readAsArrayBuffer(file);\n",
|
| 350 |
-
" });\n",
|
| 351 |
-
" // Wait for the data to be ready.\n",
|
| 352 |
-
" let fileData = yield {\n",
|
| 353 |
-
" promise: fileDataPromise,\n",
|
| 354 |
-
" response: {\n",
|
| 355 |
-
" action: 'continue',\n",
|
| 356 |
-
" }\n",
|
| 357 |
-
" };\n",
|
| 358 |
-
"\n",
|
| 359 |
-
" // Use a chunked sending to avoid message size limits. See b/62115660.\n",
|
| 360 |
-
" let position = 0;\n",
|
| 361 |
-
" do {\n",
|
| 362 |
-
" const length = Math.min(fileData.byteLength - position, MAX_PAYLOAD_SIZE);\n",
|
| 363 |
-
" const chunk = new Uint8Array(fileData, position, length);\n",
|
| 364 |
-
" position += length;\n",
|
| 365 |
-
"\n",
|
| 366 |
-
" const base64 = btoa(String.fromCharCode.apply(null, chunk));\n",
|
| 367 |
-
" yield {\n",
|
| 368 |
-
" response: {\n",
|
| 369 |
-
" action: 'append',\n",
|
| 370 |
-
" file: file.name,\n",
|
| 371 |
-
" data: base64,\n",
|
| 372 |
-
" },\n",
|
| 373 |
-
" };\n",
|
| 374 |
-
"\n",
|
| 375 |
-
" let percentDone = fileData.byteLength === 0 ?\n",
|
| 376 |
-
" 100 :\n",
|
| 377 |
-
" Math.round((position / fileData.byteLength) * 100);\n",
|
| 378 |
-
" percent.textContent = `${percentDone}% done`;\n",
|
| 379 |
-
"\n",
|
| 380 |
-
" } while (position < fileData.byteLength);\n",
|
| 381 |
-
" }\n",
|
| 382 |
-
"\n",
|
| 383 |
-
" // All done.\n",
|
| 384 |
-
" yield {\n",
|
| 385 |
-
" response: {\n",
|
| 386 |
-
" action: 'complete',\n",
|
| 387 |
-
" }\n",
|
| 388 |
-
" };\n",
|
| 389 |
-
"}\n",
|
| 390 |
-
"\n",
|
| 391 |
-
"scope.google = scope.google || {};\n",
|
| 392 |
-
"scope.google.colab = scope.google.colab || {};\n",
|
| 393 |
-
"scope.google.colab._files = {\n",
|
| 394 |
-
" _uploadFiles,\n",
|
| 395 |
-
" _uploadFilesContinue,\n",
|
| 396 |
-
"};\n",
|
| 397 |
-
"})(self);\n",
|
| 398 |
-
"</script> "
|
| 399 |
-
]
|
| 400 |
-
},
|
| 401 |
-
"metadata": {}
|
| 402 |
-
},
|
| 403 |
-
{
|
| 404 |
-
"output_type": "stream",
|
| 405 |
-
"name": "stdout",
|
| 406 |
-
"text": [
|
| 407 |
-
"Saving archive.zip to archive.zip\n"
|
| 408 |
-
]
|
| 409 |
-
}
|
| 410 |
]
|
| 411 |
},
|
| 412 |
{
|
| 413 |
"cell_type": "markdown",
|
| 414 |
-
"metadata": {
|
|
|
|
|
|
|
| 415 |
"source": [
|
| 416 |
-
"##
|
| 417 |
"\n",
|
| 418 |
-
"
|
| 419 |
-
"
|
| 420 |
]
|
| 421 |
},
|
| 422 |
{
|
| 423 |
"cell_type": "code",
|
| 424 |
-
"
|
| 425 |
-
"# Cell 3 — Extract the main zipped dataset\n",
|
| 426 |
-
"import zipfile\n",
|
| 427 |
-
"\n",
|
| 428 |
-
"with zipfile.ZipFile('/content/archive.zip', 'r') as z:\n",
|
| 429 |
-
" z.extractall('/content/pothole_data')\n",
|
| 430 |
-
"print(\"✅ archive.zip extracted successfully\")\n"
|
| 431 |
-
],
|
| 432 |
"metadata": {
|
| 433 |
"colab": {
|
| 434 |
"base_uri": "https://localhost:8080/"
|
|
@@ -436,29 +170,43 @@
|
|
| 436 |
"id": "MdUI5xwtK6fp",
|
| 437 |
"outputId": "945affb4-bba0-496f-c1f6-9429cad842eb"
|
| 438 |
},
|
| 439 |
-
"
|
| 440 |
-
"
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
}
|
| 448 |
]
|
| 449 |
},
|
| 450 |
{
|
| 451 |
"cell_type": "markdown",
|
| 452 |
-
"metadata": {
|
|
|
|
|
|
|
| 453 |
"source": [
|
| 454 |
-
"##
|
| 455 |
"\n",
|
| 456 |
-
"
|
| 457 |
-
"This
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
]
|
| 459 |
},
|
| 460 |
{
|
| 461 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
"source": [
|
| 463 |
"# Cell 4 — Setup master directory structure for merged datasets\n",
|
| 464 |
"import os, shutil\n",
|
|
@@ -472,39 +220,34 @@
|
|
| 472 |
"for p in [merged_train_img, merged_train_lbl, merged_val_img, merged_val_lbl]:\n",
|
| 473 |
" os.makedirs(p, exist_ok=True)\n",
|
| 474 |
"print(\"✅ Master directories created\")\n"
|
| 475 |
-
],
|
| 476 |
-
"metadata": {
|
| 477 |
-
"colab": {
|
| 478 |
-
"base_uri": "https://localhost:8080/"
|
| 479 |
-
},
|
| 480 |
-
"id": "RMlyOEcEK-Zz",
|
| 481 |
-
"outputId": "bd472e3d-d1be-4d07-daaa-db42568eb77c"
|
| 482 |
-
},
|
| 483 |
-
"execution_count": null,
|
| 484 |
-
"outputs": [
|
| 485 |
-
{
|
| 486 |
-
"output_type": "stream",
|
| 487 |
-
"name": "stdout",
|
| 488 |
-
"text": [
|
| 489 |
-
"✅ Master directories created\n"
|
| 490 |
-
]
|
| 491 |
-
}
|
| 492 |
]
|
| 493 |
},
|
| 494 |
{
|
| 495 |
"cell_type": "markdown",
|
| 496 |
-
"metadata": {
|
|
|
|
|
|
|
| 497 |
"source": [
|
| 498 |
-
"##
|
| 499 |
"\n",
|
| 500 |
-
"
|
|
|
|
| 501 |
"then copies them all into the master `merged/train/` directory.\n",
|
| 502 |
"\n",
|
| 503 |
-
">
|
| 504 |
]
|
| 505 |
},
|
| 506 |
{
|
| 507 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
"source": [
|
| 509 |
"# Cell 5 — Copy all images and labels into the merged folder (Bulletproof Search)\n",
|
| 510 |
"# List of directories containing datasets (Assuming they are available in /content/)\n",
|
|
@@ -526,30 +269,15 @@
|
|
| 526 |
" shutil.copy(lbl, merged_train_lbl)\n",
|
| 527 |
"\n",
|
| 528 |
"print('✅ Merging complete. Total train images:', len(list(Path(merged_train_img).glob('*.jpg'))))\n"
|
| 529 |
-
],
|
| 530 |
-
"metadata": {
|
| 531 |
-
"colab": {
|
| 532 |
-
"base_uri": "https://localhost:8080/"
|
| 533 |
-
},
|
| 534 |
-
"id": "lJZFF47NLEFJ",
|
| 535 |
-
"outputId": "04ff65e2-a9c7-4ce6-d2dd-11d1139a6a8f"
|
| 536 |
-
},
|
| 537 |
-
"execution_count": null,
|
| 538 |
-
"outputs": [
|
| 539 |
-
{
|
| 540 |
-
"output_type": "stream",
|
| 541 |
-
"name": "stdout",
|
| 542 |
-
"text": [
|
| 543 |
-
"✅ Merging complete. Total train images: 2009\n"
|
| 544 |
-
]
|
| 545 |
-
}
|
| 546 |
]
|
| 547 |
},
|
| 548 |
{
|
| 549 |
"cell_type": "markdown",
|
| 550 |
-
"metadata": {
|
|
|
|
|
|
|
| 551 |
"source": [
|
| 552 |
-
"##
|
| 553 |
"\n",
|
| 554 |
"Creates the YOLO dataset configuration file defining:\n",
|
| 555 |
"- 3 detection classes: `['pothole', 'crack', 'manhole']`\n",
|
|
@@ -560,6 +288,15 @@
|
|
| 560 |
},
|
| 561 |
{
|
| 562 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
"source": [
|
| 564 |
"# Cell 6 — Create data.yaml mapping to our 3 classes\n",
|
| 565 |
"data_yaml = \"\"\"\n",
|
|
@@ -574,48 +311,32 @@
|
|
| 574 |
" f.write(data_yaml)\n",
|
| 575 |
"\n",
|
| 576 |
"print(\"✅ data.yaml written\")\n"
|
| 577 |
-
],
|
| 578 |
-
"metadata": {
|
| 579 |
-
"colab": {
|
| 580 |
-
"base_uri": "https://localhost:8080/"
|
| 581 |
-
},
|
| 582 |
-
"id": "f5Cmy0iuMZSC",
|
| 583 |
-
"outputId": "15593ba5-a0b6-46f9-a751-367262c4f65f"
|
| 584 |
-
},
|
| 585 |
-
"execution_count": null,
|
| 586 |
-
"outputs": [
|
| 587 |
-
{
|
| 588 |
-
"output_type": "stream",
|
| 589 |
-
"name": "stdout",
|
| 590 |
-
"text": [
|
| 591 |
-
"✅ data.yaml written\n"
|
| 592 |
-
]
|
| 593 |
-
}
|
| 594 |
]
|
| 595 |
},
|
| 596 |
{
|
| 597 |
"cell_type": "markdown",
|
| 598 |
-
"metadata": {
|
|
|
|
|
|
|
| 599 |
"source": [
|
| 600 |
-
"##
|
| 601 |
-
"\n",
|
| 602 |
-
"Trains YOLOv8 nano on the merged dataset using these hyperparameters:\n",
|
| 603 |
-
"\n",
|
| 604 |
-
"| Parameter | Value | Reason |\n",
|
| 605 |
-
"|-----------|-------|--------|\n",
|
| 606 |
-
"| `model` | yolov8n.pt | Smallest model — runs well in browser via ONNX |\n",
|
| 607 |
-
"| `epochs` | 50 | Balanced between accuracy and training time |\n",
|
| 608 |
-
"| `imgsz` | 640 | Standard YOLO input resolution |\n",
|
| 609 |
-
"| `batch` | 16 | Fits T4 14GB VRAM |\n",
|
| 610 |
-
"| `device` | 0 (GPU) | CUDA training |\n",
|
| 611 |
"\n",
|
| 612 |
-
"
|
| 613 |
-
"
|
| 614 |
-
"\n**It will then export to ONNX and download the final model.**"
|
| 615 |
]
|
| 616 |
},
|
| 617 |
{
|
| 618 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
"source": [
|
| 620 |
"# Cell 7 — Train (45-60 min on T4 GPU)\n",
|
| 621 |
"model = YOLO('yolov8n.pt')\n",
|
|
@@ -631,415 +352,51 @@
|
|
| 631 |
" save=True,\n",
|
| 632 |
")\n",
|
| 633 |
"print(\"✅ YOLO Training Finished\")\n"
|
| 634 |
-
]
|
|
|
|
|
|
|
|
|
|
| 635 |
"metadata": {
|
| 636 |
-
"
|
| 637 |
-
"base_uri": "https://localhost:8080/"
|
| 638 |
-
},
|
| 639 |
-
"id": "kXWxRFmaMcyE",
|
| 640 |
-
"outputId": "66b2cdd5-193d-4946-cbaf-b39dc5fa24ae",
|
| 641 |
-
"collapsed": true
|
| 642 |
},
|
| 643 |
-
"
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
"output_type": "stream",
|
| 647 |
-
"name": "stdout",
|
| 648 |
-
"text": [
|
| 649 |
-
"Ultralytics 8.4.37 🚀 Python-3.12.13 torch-2.10.0+cu128 CUDA:0 (Tesla T4, 14913MiB)\n",
|
| 650 |
-
"\u001b[34m\u001b[1mengine/trainer: \u001b[0magnostic_nms=False, amp=True, angle=1.0, augment=False, auto_augment=randaugment, batch=16, bgr=0.0, box=7.5, cache=False, cfg=None, classes=None, close_mosaic=10, cls=0.5, cls_pw=0.0, compile=False, conf=None, copy_paste=0.0, copy_paste_mode=flip, cos_lr=False, cutmix=0.0, data=/content/pothole.yaml, degrees=0.0, deterministic=True, device=0, dfl=1.5, dnn=False, dropout=0.0, dynamic=False, embed=None, end2end=None, epochs=50, erasing=0.4, exist_ok=False, fliplr=0.5, flipud=0.0, format=torchscript, fraction=1.0, freeze=None, half=False, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, imgsz=640, int8=False, iou=0.7, keras=False, kobj=1.0, line_width=None, lr0=0.01, lrf=0.01, mask_ratio=4, max_det=300, mixup=0.0, mode=train, model=yolov8n.pt, momentum=0.937, mosaic=1.0, multi_scale=0.0, name=pothole_v12, nbs=64, nms=False, opset=None, optimize=False, optimizer=auto, overlap_mask=True, patience=100, perspective=0.0, plots=True, pose=12.0, pretrained=True, profile=False, project=/content/runs/detect, rect=False, resume=False, retina_masks=False, rle=1.0, save=True, save_conf=False, save_crop=False, save_dir=/content/runs/detect/pothole_v12, save_frames=False, save_json=False, save_period=-1, save_txt=False, scale=0.5, seed=0, shear=0.0, show=False, show_boxes=True, show_conf=True, show_labels=True, simplify=True, single_cls=False, source=None, split=val, stream_buffer=False, task=detect, time=None, tracker=botsort.yaml, translate=0.1, val=True, verbose=True, vid_stride=1, visualize=False, warmup_bias_lr=0.1, warmup_epochs=3.0, warmup_momentum=0.8, weight_decay=0.0005, workers=8, workspace=None\n",
|
| 651 |
-
"Overriding model.yaml nc=80 with nc=3\n",
|
| 652 |
-
"\n",
|
| 653 |
-
" from n params module arguments \n",
|
| 654 |
-
" 0 -1 1 464 ultralytics.nn.modules.conv.Conv [3, 16, 3, 2] \n",
|
| 655 |
-
" 1 -1 1 4672 ultralytics.nn.modules.conv.Conv [16, 32, 3, 2] \n",
|
| 656 |
-
" 2 -1 1 7360 ultralytics.nn.modules.block.C2f [32, 32, 1, True] \n",
|
| 657 |
-
" 3 -1 1 18560 ultralytics.nn.modules.conv.Conv [32, 64, 3, 2] \n",
|
| 658 |
-
" 4 -1 2 49664 ultralytics.nn.modules.block.C2f [64, 64, 2, True] \n",
|
| 659 |
-
" 5 -1 1 73984 ultralytics.nn.modules.conv.Conv [64, 128, 3, 2] \n",
|
| 660 |
-
" 6 -1 2 197632 ultralytics.nn.modules.block.C2f [128, 128, 2, True] \n",
|
| 661 |
-
" 7 -1 1 295424 ultralytics.nn.modules.conv.Conv [128, 256, 3, 2] \n",
|
| 662 |
-
" 8 -1 1 460288 ultralytics.nn.modules.block.C2f [256, 256, 1, True] \n",
|
| 663 |
-
" 9 -1 1 164608 ultralytics.nn.modules.block.SPPF [256, 256, 5] \n",
|
| 664 |
-
" 10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
|
| 665 |
-
" 11 [-1, 6] 1 0 ultralytics.nn.modules.conv.Concat [1] \n",
|
| 666 |
-
" 12 -1 1 148224 ultralytics.nn.modules.block.C2f [384, 128, 1] \n",
|
| 667 |
-
" 13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
|
| 668 |
-
" 14 [-1, 4] 1 0 ultralytics.nn.modules.conv.Concat [1] \n",
|
| 669 |
-
" 15 -1 1 37248 ultralytics.nn.modules.block.C2f [192, 64, 1] \n",
|
| 670 |
-
" 16 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2] \n",
|
| 671 |
-
" 17 [-1, 12] 1 0 ultralytics.nn.modules.conv.Concat [1] \n",
|
| 672 |
-
" 18 -1 1 123648 ultralytics.nn.modules.block.C2f [192, 128, 1] \n",
|
| 673 |
-
" 19 -1 1 147712 ultralytics.nn.modules.conv.Conv [128, 128, 3, 2] \n",
|
| 674 |
-
" 20 [-1, 9] 1 0 ultralytics.nn.modules.conv.Concat [1] \n",
|
| 675 |
-
" 21 -1 1 493056 ultralytics.nn.modules.block.C2f [384, 256, 1] \n",
|
| 676 |
-
" 22 [15, 18, 21] 1 751897 ultralytics.nn.modules.head.Detect [3, 16, None, [64, 128, 256]] \n",
|
| 677 |
-
"Model summary: 130 layers, 3,011,433 parameters, 3,011,417 gradients, 8.2 GFLOPs\n",
|
| 678 |
-
"\n",
|
| 679 |
-
"Transferred 319/355 items from pretrained weights\n",
|
| 680 |
-
"Freezing layer 'model.22.dfl.conv.weight'\n",
|
| 681 |
-
"\u001b[34m\u001b[1mAMP: \u001b[0mrunning Automatic Mixed Precision (AMP) checks...\n",
|
| 682 |
-
"\u001b[34m\u001b[1mAMP: \u001b[0mchecks passed ✅\n",
|
| 683 |
-
"\u001b[34m\u001b[1mtrain: \u001b[0mFast image access ✅ (ping: 0.0±0.0 ms, read: 1748.1±478.9 MB/s, size: 91.3 KB)\n",
|
| 684 |
-
"\u001b[K\u001b[34m\u001b[1mtrain: \u001b[0mScanning /content/merged/train/labels.cache... 2009 images, 0 backgrounds, 0 corrupt: 100% ━━━━━━━━━━━━ 2009/2009 702.2Mit/s 0.0s\n",
|
| 685 |
-
"\u001b[34m\u001b[1malbumentations: \u001b[0mBlur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01, method='weighted_average', num_output_channels=3), CLAHE(p=0.01, clip_limit=(1.0, 4.0), tile_grid_size=(8, 8))\n",
|
| 686 |
-
"\u001b[34m\u001b[1mval: \u001b[0mFast image access ✅ (ping: 0.0±0.0 ms, read: 602.0±531.0 MB/s, size: 96.3 KB)\n",
|
| 687 |
-
"\u001b[K\u001b[34m\u001b[1mval: \u001b[0mScanning /content/merged/train/labels.cache... 2009 images, 0 backgrounds, 0 corrupt: 100% ━━━━━━━━━━━━ 2009/2009 98.0Mit/s 0.0s\n",
|
| 688 |
-
"\u001b[34m\u001b[1moptimizer:\u001b[0m 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically... \n",
|
| 689 |
-
"\u001b[34m\u001b[1moptimizer:\u001b[0m AdamW(lr=0.001429, momentum=0.9) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias(decay=0.0)\n",
|
| 690 |
-
"Plotting labels to /content/runs/detect/pothole_v12/labels.jpg... \n",
|
| 691 |
-
"Image sizes 640 train, 640 val\n",
|
| 692 |
-
"Using 2 dataloader workers\n",
|
| 693 |
-
"Logging results to \u001b[1m/content/runs/detect/pothole_v12\u001b[0m\n",
|
| 694 |
-
"Starting training for 50 epochs...\n",
|
| 695 |
-
"\n",
|
| 696 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 697 |
-
"\u001b[K 1/50 2.07G 2.461 3.585 1.815 42 640: 100% ━━━━━━━━━━━━ 126/126 2.6it/s 48.6s\n",
|
| 698 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.5s\n",
|
| 699 |
-
" all 2009 4737 0.294 0.193 0.145 0.0462\n",
|
| 700 |
-
"\n",
|
| 701 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 702 |
-
"\u001b[K 2/50 2.18G 2.278 2.788 1.713 39 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.4s\n",
|
| 703 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.0it/s 15.7s\n",
|
| 704 |
-
" all 2009 4737 0.314 0.26 0.225 0.0889\n",
|
| 705 |
-
"\n",
|
| 706 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 707 |
-
"\u001b[K 3/50 2.18G 2.302 2.577 1.706 39 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.3s\n",
|
| 708 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.7s\n",
|
| 709 |
-
" all 2009 4737 0.346 0.319 0.254 0.0951\n",
|
| 710 |
-
"\n",
|
| 711 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 712 |
-
"\u001b[K 4/50 2.18G 2.292 2.446 1.713 26 640: 100% ━━━━━━━━━━━━ 126/126 3.2it/s 39.8s\n",
|
| 713 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.0s\n",
|
| 714 |
-
" all 2009 4737 0.345 0.347 0.292 0.114\n",
|
| 715 |
-
"\n",
|
| 716 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 717 |
-
"\u001b[K 5/50 2.18G 2.235 2.342 1.692 37 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 41.5s\n",
|
| 718 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.2s\n",
|
| 719 |
-
" all 2009 4737 0.371 0.323 0.285 0.116\n",
|
| 720 |
-
"\n",
|
| 721 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 722 |
-
"\u001b[K 6/50 2.18G 2.198 2.251 1.665 25 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.3s\n",
|
| 723 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 14.9s\n",
|
| 724 |
-
" all 2009 4737 0.405 0.399 0.345 0.146\n",
|
| 725 |
-
"\n",
|
| 726 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 727 |
-
"\u001b[K 7/50 2.18G 2.178 2.215 1.644 39 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 40.6s\n",
|
| 728 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.5s\n",
|
| 729 |
-
" all 2009 4737 0.383 0.412 0.367 0.15\n",
|
| 730 |
-
"\n",
|
| 731 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 732 |
-
"\u001b[K 8/50 2.18G 2.165 2.176 1.62 39 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 41.3s\n",
|
| 733 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.1s\n",
|
| 734 |
-
" all 2009 4737 0.36 0.426 0.381 0.16\n",
|
| 735 |
-
"\n",
|
| 736 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 737 |
-
"\u001b[K 9/50 2.18G 2.125 2.129 1.607 25 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 41.7s\n",
|
| 738 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.3s\n",
|
| 739 |
-
" all 2009 4737 0.411 0.429 0.392 0.162\n",
|
| 740 |
-
"\n",
|
| 741 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 742 |
-
"\u001b[K 10/50 2.18G 2.13 2.077 1.599 52 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.2s\n",
|
| 743 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.1s\n",
|
| 744 |
-
" all 2009 4737 0.454 0.414 0.408 0.174\n",
|
| 745 |
-
"\n",
|
| 746 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 747 |
-
"\u001b[K 11/50 2.18G 2.074 2.036 1.575 43 640: 100% ━━━━━━━━━━━━ 126/126 3.2it/s 39.8s\n",
|
| 748 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.3s\n",
|
| 749 |
-
" all 2009 4737 0.426 0.441 0.402 0.17\n",
|
| 750 |
-
"\n",
|
| 751 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 752 |
-
"\u001b[K 12/50 2.18G 2.083 2.026 1.576 28 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.1s\n",
|
| 753 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.0s\n",
|
| 754 |
-
" all 2009 4737 0.445 0.442 0.405 0.171\n",
|
| 755 |
-
"\n",
|
| 756 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 757 |
-
"\u001b[K 13/50 2.18G 2.068 2 1.57 41 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 41.6s\n",
|
| 758 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.8s\n",
|
| 759 |
-
" all 2009 4737 0.442 0.45 0.418 0.18\n",
|
| 760 |
-
"\n",
|
| 761 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 762 |
-
"\u001b[K 14/50 2.18G 2.054 1.98 1.556 43 640: 100% ━━━━━━━━━━━━ 126/126 3.2it/s 39.7s\n",
|
| 763 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.0it/s 15.7s\n",
|
| 764 |
-
" all 2009 4737 0.4 0.465 0.423 0.167\n",
|
| 765 |
-
"\n",
|
| 766 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 767 |
-
"\u001b[K 15/50 2.18G 2.062 1.97 1.549 29 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 40.4s\n",
|
| 768 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.3s\n",
|
| 769 |
-
" all 2009 4737 0.486 0.481 0.455 0.2\n",
|
| 770 |
-
"\n",
|
| 771 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 772 |
-
"\u001b[K 16/50 2.18G 2.017 1.908 1.536 36 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 41.6s\n",
|
| 773 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.0s\n",
|
| 774 |
-
" all 2009 4737 0.507 0.494 0.476 0.211\n",
|
| 775 |
-
"\n",
|
| 776 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 777 |
-
"\u001b[K 17/50 2.18G 2.008 1.91 1.533 35 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 40.9s\n",
|
| 778 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.1s\n",
|
| 779 |
-
" all 2009 4737 0.506 0.502 0.484 0.214\n",
|
| 780 |
-
"\n",
|
| 781 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 782 |
-
"\u001b[K 18/50 2.18G 2.014 1.871 1.512 43 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 41.0s\n",
|
| 783 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.7s\n",
|
| 784 |
-
" all 2009 4737 0.511 0.482 0.476 0.219\n",
|
| 785 |
-
"\n",
|
| 786 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 787 |
-
"\u001b[K 19/50 2.18G 2 1.871 1.514 36 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.4s\n",
|
| 788 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.0it/s 15.8s\n",
|
| 789 |
-
" all 2009 4737 0.519 0.512 0.49 0.215\n",
|
| 790 |
-
"\n",
|
| 791 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 792 |
-
"\u001b[K 20/50 2.18G 1.971 1.848 1.496 33 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 41.8s\n",
|
| 793 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.3s\n",
|
| 794 |
-
" all 2009 4737 0.544 0.52 0.522 0.233\n",
|
| 795 |
-
"\n",
|
| 796 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 797 |
-
"\u001b[K 21/50 2.18G 1.973 1.843 1.501 42 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 40.6s\n",
|
| 798 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.3s\n",
|
| 799 |
-
" all 2009 4737 0.528 0.532 0.528 0.244\n",
|
| 800 |
-
"\n",
|
| 801 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 802 |
-
"\u001b[K 22/50 2.18G 1.966 1.798 1.489 25 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 41.3s\n",
|
| 803 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.1s\n",
|
| 804 |
-
" all 2009 4737 0.528 0.524 0.514 0.233\n",
|
| 805 |
-
"\n",
|
| 806 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 807 |
-
"\u001b[K 23/50 2.18G 1.962 1.804 1.492 29 640: 100% ━━━━━━━━━━━━ 126/126 2.9it/s 42.8s\n",
|
| 808 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.2s\n",
|
| 809 |
-
" all 2009 4737 0.504 0.51 0.505 0.239\n",
|
| 810 |
-
"\n",
|
| 811 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 812 |
-
"\u001b[K 24/50 2.18G 1.948 1.791 1.48 52 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.3s\n",
|
| 813 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.2s\n",
|
| 814 |
-
" all 2009 4737 0.534 0.549 0.551 0.258\n",
|
| 815 |
-
"\n",
|
| 816 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 817 |
-
"\u001b[K 25/50 2.18G 1.949 1.755 1.471 53 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 40.5s\n",
|
| 818 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.0it/s 15.6s\n",
|
| 819 |
-
" all 2009 4737 0.581 0.543 0.558 0.263\n",
|
| 820 |
-
"\n",
|
| 821 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 822 |
-
"\u001b[K 26/50 2.18G 1.946 1.761 1.454 36 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 41.2s\n",
|
| 823 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.1s\n",
|
| 824 |
-
" all 2009 4737 0.587 0.547 0.565 0.266\n",
|
| 825 |
-
"\n",
|
| 826 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 827 |
-
"\u001b[K 27/50 2.18G 1.888 1.715 1.438 36 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.1s\n",
|
| 828 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.5s\n",
|
| 829 |
-
" all 2009 4737 0.589 0.551 0.578 0.28\n",
|
| 830 |
-
"\n",
|
| 831 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 832 |
-
"\u001b[K 28/50 2.18G 1.93 1.705 1.444 41 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 41.2s\n",
|
| 833 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.5s\n",
|
| 834 |
-
" all 2009 4737 0.606 0.563 0.592 0.283\n",
|
| 835 |
-
"\n",
|
| 836 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 837 |
-
"\u001b[K 29/50 2.18G 1.879 1.654 1.431 44 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 40.5s\n",
|
| 838 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.4s\n",
|
| 839 |
-
" all 2009 4737 0.58 0.564 0.578 0.274\n",
|
| 840 |
-
"\n",
|
| 841 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 842 |
-
"\u001b[K 30/50 2.18G 1.877 1.658 1.432 36 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.1s\n",
|
| 843 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.3s\n",
|
| 844 |
-
" all 2009 4737 0.621 0.585 0.607 0.3\n",
|
| 845 |
-
"\n",
|
| 846 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 847 |
-
"\u001b[K 31/50 2.18G 1.877 1.637 1.422 45 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.4s\n",
|
| 848 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.0it/s 15.6s\n",
|
| 849 |
-
" all 2009 4737 0.621 0.595 0.626 0.309\n",
|
| 850 |
-
"\n",
|
| 851 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 852 |
-
"\u001b[K 32/50 2.18G 1.856 1.636 1.417 55 640: 100% ━━━━━━━━━━━━ 126/126 2.9it/s 42.8s\n",
|
| 853 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.6s\n",
|
| 854 |
-
" all 2009 4737 0.622 0.607 0.627 0.314\n",
|
| 855 |
-
"\n",
|
| 856 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 857 |
-
"\u001b[K 33/50 2.18G 1.861 1.607 1.408 31 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 40.9s\n",
|
| 858 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 14.9s\n",
|
| 859 |
-
" all 2009 4737 0.643 0.601 0.635 0.311\n",
|
| 860 |
-
"\n",
|
| 861 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 862 |
-
"\u001b[K 34/50 2.18G 1.847 1.612 1.4 48 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.5s\n",
|
| 863 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.4s\n",
|
| 864 |
-
" all 2009 4737 0.648 0.625 0.659 0.328\n",
|
| 865 |
-
"\n",
|
| 866 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 867 |
-
"\u001b[K 35/50 2.18G 1.81 1.578 1.393 48 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.0s\n",
|
| 868 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.0it/s 15.6s\n",
|
| 869 |
-
" all 2009 4737 0.637 0.64 0.659 0.334\n",
|
| 870 |
-
"\n",
|
| 871 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 872 |
-
"\u001b[K 36/50 2.18G 1.837 1.554 1.398 42 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 41.0s\n",
|
| 873 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.4s\n",
|
| 874 |
-
" all 2009 4737 0.659 0.639 0.674 0.342\n",
|
| 875 |
-
"\n",
|
| 876 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 877 |
-
"\u001b[K 37/50 2.18G 1.828 1.573 1.39 34 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 40.6s\n",
|
| 878 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.4s\n",
|
| 879 |
-
" all 2009 4737 0.662 0.613 0.66 0.334\n",
|
| 880 |
-
"\n",
|
| 881 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 882 |
-
"\u001b[K 38/50 2.18G 1.798 1.516 1.373 45 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.3s\n",
|
| 883 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.3s\n",
|
| 884 |
-
" all 2009 4737 0.661 0.641 0.678 0.35\n",
|
| 885 |
-
"\n",
|
| 886 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 887 |
-
"\u001b[K 39/50 2.18G 1.801 1.518 1.373 50 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 42.2s\n",
|
| 888 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.0it/s 15.9s\n",
|
| 889 |
-
" all 2009 4737 0.68 0.64 0.692 0.36\n",
|
| 890 |
-
"\n",
|
| 891 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 892 |
-
"\u001b[K 40/50 2.18G 1.773 1.485 1.36 44 640: 100% ━━━━━━━━━━━━ 126/126 3.1it/s 40.2s\n",
|
| 893 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.0s\n",
|
| 894 |
-
" all 2009 4737 0.675 0.655 0.7 0.359\n",
|
| 895 |
-
"Closing dataloader mosaic\n",
|
| 896 |
-
"\u001b[34m\u001b[1malbumentations: \u001b[0mBlur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01, method='weighted_average', num_output_channels=3), CLAHE(p=0.01, clip_limit=(1.0, 4.0), tile_grid_size=(8, 8))\n",
|
| 897 |
-
"\n",
|
| 898 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 899 |
-
"\u001b[K 41/50 2.18G 1.765 1.475 1.409 13 640: 100% ━━━━━━━━━━━━ 126/126 3.0it/s 41.6s\n",
|
| 900 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.7s\n",
|
| 901 |
-
" all 2009 4737 0.677 0.635 0.684 0.352\n",
|
| 902 |
-
"\n",
|
| 903 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 904 |
-
"\u001b[K 42/50 2.18G 1.732 1.417 1.393 14 640: 100% ━━━━━━━━━━━━ 126/126 3.4it/s 36.7s\n",
|
| 905 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.4it/s 14.4s\n",
|
| 906 |
-
" all 2009 4737 0.705 0.658 0.716 0.375\n",
|
| 907 |
-
"\n",
|
| 908 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 909 |
-
"\u001b[K 43/50 2.18G 1.709 1.389 1.379 27 640: 100% ━━━━━━━━━━━━ 126/126 3.3it/s 38.5s\n",
|
| 910 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.8s\n",
|
| 911 |
-
" all 2009 4737 0.704 0.664 0.718 0.376\n",
|
| 912 |
-
"\n",
|
| 913 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 914 |
-
"\u001b[K 44/50 2.18G 1.698 1.365 1.381 18 640: 100% ━━━━━━━━━━━━ 126/126 3.5it/s 36.4s\n",
|
| 915 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.7s\n",
|
| 916 |
-
" all 2009 4737 0.732 0.66 0.729 0.38\n",
|
| 917 |
-
"\n",
|
| 918 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 919 |
-
"\u001b[K 45/50 2.18G 1.679 1.353 1.373 23 640: 100% ━━━━━━━━━━━━ 126/126 3.4it/s 37.4s\n",
|
| 920 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.1it/s 15.2s\n",
|
| 921 |
-
" all 2009 4737 0.733 0.675 0.74 0.401\n",
|
| 922 |
-
"\n",
|
| 923 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 924 |
-
"\u001b[K 46/50 2.18G 1.678 1.335 1.358 20 640: 100% ━━━━━━━━━━━━ 126/126 3.4it/s 36.6s\n",
|
| 925 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.6s\n",
|
| 926 |
-
" all 2009 4737 0.739 0.676 0.747 0.402\n",
|
| 927 |
-
"\n",
|
| 928 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 929 |
-
"\u001b[K 47/50 2.18G 1.66 1.34 1.36 18 640: 100% ━━━━━━━━━━━━ 126/126 3.4it/s 37.0s\n",
|
| 930 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.6s\n",
|
| 931 |
-
" all 2009 4737 0.743 0.687 0.761 0.412\n",
|
| 932 |
-
"\n",
|
| 933 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 934 |
-
"\u001b[K 48/50 2.18G 1.661 1.296 1.346 22 640: 100% ━━━━━━━━━━━━ 126/126 3.3it/s 37.8s\n",
|
| 935 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.0s\n",
|
| 936 |
-
" all 2009 4737 0.747 0.688 0.762 0.415\n",
|
| 937 |
-
"\n",
|
| 938 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 939 |
-
"\u001b[K 49/50 2.18G 1.616 1.276 1.33 17 640: 100% ━━━━━━━━━━━━ 126/126 3.5it/s 36.3s\n",
|
| 940 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.3it/s 14.5s\n",
|
| 941 |
-
" all 2009 4737 0.75 0.696 0.767 0.422\n",
|
| 942 |
-
"\n",
|
| 943 |
-
" Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size\n",
|
| 944 |
-
"\u001b[K 50/50 2.18G 1.613 1.265 1.325 15 640: 100% ━━━━━━━━━━━━ 126/126 3.3it/s 38.5s\n",
|
| 945 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 4.2it/s 15.0s\n",
|
| 946 |
-
" all 2009 4737 0.75 0.712 0.775 0.427\n",
|
| 947 |
-
"\n",
|
| 948 |
-
"50 epochs completed in 0.787 hours.\n",
|
| 949 |
-
"Optimizer stripped from /content/runs/detect/pothole_v12/weights/last.pt, 6.2MB\n",
|
| 950 |
-
"Optimizer stripped from /content/runs/detect/pothole_v12/weights/best.pt, 6.2MB\n",
|
| 951 |
-
"\n",
|
| 952 |
-
"Validating /content/runs/detect/pothole_v12/weights/best.pt...\n",
|
| 953 |
-
"Ultralytics 8.4.37 🚀 Python-3.12.13 torch-2.10.0+cu128 CUDA:0 (Tesla T4, 14913MiB)\n",
|
| 954 |
-
"Model summary (fused): 73 layers, 3,006,233 parameters, 0 gradients, 8.1 GFLOPs\n",
|
| 955 |
-
"\u001b[K Class Images Instances Box(P R mAP50 mAP50-95): 100% ━━━━━━━━━━━━ 63/63 3.7it/s 17.1s\n",
|
| 956 |
-
" all 2009 4737 0.75 0.712 0.774 0.426\n",
|
| 957 |
-
" pothole 795 1261 0.692 0.638 0.71 0.363\n",
|
| 958 |
-
" crack 1375 2519 0.693 0.623 0.697 0.382\n",
|
| 959 |
-
" manhole 759 957 0.865 0.874 0.917 0.535\n",
|
| 960 |
-
"Speed: 0.1ms preprocess, 1.6ms inference, 0.0ms loss, 1.7ms postprocess per image\n",
|
| 961 |
-
"Results saved to \u001b[1m/content/runs/detect/pothole_v12\u001b[0m\n",
|
| 962 |
-
"✅ YOLO Training Finished\n"
|
| 963 |
-
]
|
| 964 |
-
}
|
| 965 |
]
|
| 966 |
},
|
| 967 |
{
|
| 968 |
"cell_type": "code",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 969 |
"source": [
|
| 970 |
"# Cell 8 — Export ONNX\n",
|
| 971 |
"best_model = YOLO('/content/runs/detect/pothole_v1/weights/best.pt')\n",
|
| 972 |
"best_model.export(format='onnx', imgsz=640, opset=12, simplify=True)\n",
|
| 973 |
"best_model.export(format='torchscript')\n",
|
| 974 |
"print(\"✅ ONNX models generated\")\n"
|
| 975 |
-
]
|
|
|
|
|
|
|
|
|
|
| 976 |
"metadata": {
|
| 977 |
-
"
|
| 978 |
-
"base_uri": "https://localhost:8080/"
|
| 979 |
-
},
|
| 980 |
-
"id": "53VaY29vfU3S",
|
| 981 |
-
"outputId": "43484095-f9d9-43bd-efbf-cef0b272448a"
|
| 982 |
},
|
| 983 |
-
"
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
"output_type": "stream",
|
| 987 |
-
"name": "stdout",
|
| 988 |
-
"text": [
|
| 989 |
-
"Ultralytics 8.4.37 🚀 Python-3.12.13 torch-2.10.0+cu128 CPU (Intel Xeon CPU @ 2.00GHz)\n",
|
| 990 |
-
"💡 ProTip: Export to OpenVINO format for best performance on Intel hardware. Learn more at https://docs.ultralytics.com/integrations/openvino/\n",
|
| 991 |
-
"Model summary (fused): 73 layers, 3,006,233 parameters, 0 gradients, 8.1 GFLOPs\n",
|
| 992 |
-
"\n",
|
| 993 |
-
"\u001b[34m\u001b[1mPyTorch:\u001b[0m starting from '/content/runs/detect/pothole_v1/weights/best.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 7, 8400) (5.9 MB)\n",
|
| 994 |
-
"\u001b[31m\u001b[1mrequirements:\u001b[0m Ultralytics requirements ['onnxslim>=0.1.71', 'onnxruntime-gpu'] not found, attempting AutoUpdate...\n",
|
| 995 |
-
"Using Python 3.12.13 environment at: /usr\n",
|
| 996 |
-
"Resolved 12 packages in 446ms\n",
|
| 997 |
-
"Prepared 3 packages in 4.89s\n",
|
| 998 |
-
"Installed 3 packages in 39ms\n",
|
| 999 |
-
" + colorama==0.4.6\n",
|
| 1000 |
-
" + onnxruntime-gpu==1.24.4\n",
|
| 1001 |
-
" + onnxslim==0.1.91\n",
|
| 1002 |
-
"\n",
|
| 1003 |
-
"\u001b[31m\u001b[1mrequirements:\u001b[0m AutoUpdate success ✅ 6.3s\n",
|
| 1004 |
-
"WARNING ⚠️ \u001b[31m\u001b[1mrequirements:\u001b[0m \u001b[1mRestart runtime or rerun command for updates to take effect\u001b[0m\n",
|
| 1005 |
-
"\n",
|
| 1006 |
-
"\n",
|
| 1007 |
-
"\u001b[34m\u001b[1mONNX:\u001b[0m starting export with onnx 1.21.0 opset 12...\n",
|
| 1008 |
-
"\u001b[34m\u001b[1mONNX:\u001b[0m slimming with onnxslim 0.1.91...\n",
|
| 1009 |
-
"\u001b[34m\u001b[1mONNX:\u001b[0m export success ✅ 7.9s, saved as '/content/runs/detect/pothole_v1/weights/best.onnx' (11.7 MB)\n",
|
| 1010 |
-
"\n",
|
| 1011 |
-
"Export complete (9.3s)\n",
|
| 1012 |
-
"Results saved to \u001b[1m/content/runs/detect/pothole_v1/weights\u001b[0m\n",
|
| 1013 |
-
"Predict: yolo predict task=detect model=/content/runs/detect/pothole_v1/weights/best.onnx imgsz=640 \n",
|
| 1014 |
-
"Validate: yolo val task=detect model=/content/runs/detect/pothole_v1/weights/best.onnx imgsz=640 data=/content/pothole.yaml \n",
|
| 1015 |
-
"Visualize: https://netron.app\n",
|
| 1016 |
-
"Ultralytics 8.4.37 🚀 Python-3.12.13 torch-2.10.0+cu128 CPU (Intel Xeon CPU @ 2.00GHz)\n",
|
| 1017 |
-
"Model summary (fused): 73 layers, 3,006,233 parameters, 0 gradients, 8.1 GFLOPs\n",
|
| 1018 |
-
"\n",
|
| 1019 |
-
"\u001b[34m\u001b[1mPyTorch:\u001b[0m starting from '/content/runs/detect/pothole_v1/weights/best.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 7, 8400) (5.9 MB)\n",
|
| 1020 |
-
"\n",
|
| 1021 |
-
"\u001b[34m\u001b[1mTorchScript:\u001b[0m starting export with torch 2.10.0+cu128...\n",
|
| 1022 |
-
"\u001b[34m\u001b[1mTorchScript:\u001b[0m export success ✅ 1.9s, saved as '/content/runs/detect/pothole_v1/weights/best.torchscript' (11.9 MB)\n",
|
| 1023 |
-
"\n",
|
| 1024 |
-
"Export complete (2.3s)\n",
|
| 1025 |
-
"Results saved to \u001b[1m/content/runs/detect/pothole_v1/weights\u001b[0m\n",
|
| 1026 |
-
"Predict: yolo predict task=detect model=/content/runs/detect/pothole_v1/weights/best.torchscript imgsz=640 \n",
|
| 1027 |
-
"Validate: yolo val task=detect model=/content/runs/detect/pothole_v1/weights/best.torchscript imgsz=640 data=/content/pothole.yaml \n",
|
| 1028 |
-
"Visualize: https://netron.app\n",
|
| 1029 |
-
"✅ ONNX models generated\n"
|
| 1030 |
-
]
|
| 1031 |
-
}
|
| 1032 |
]
|
| 1033 |
},
|
| 1034 |
{
|
| 1035 |
"cell_type": "code",
|
| 1036 |
-
"
|
| 1037 |
-
"# Cell 9 — Download the weights\n",
|
| 1038 |
-
"import shutil\n",
|
| 1039 |
-
"from google.colab import files\n",
|
| 1040 |
-
"shutil.make_archive('/content/pothole_weights', 'zip', '/content/runs/detect/pothole_v1/weights')\n",
|
| 1041 |
-
"files.download('/content/pothole_weights.zip')\n"
|
| 1042 |
-
],
|
| 1043 |
"metadata": {
|
| 1044 |
"colab": {
|
| 1045 |
"base_uri": "https://localhost:8080/",
|
|
@@ -1048,73 +405,30 @@
|
|
| 1048 |
"id": "SEZ7OyABfs_3",
|
| 1049 |
"outputId": "e237add9-7506-4af3-cae3-8827fb64c9fc"
|
| 1050 |
},
|
| 1051 |
-
"
|
| 1052 |
-
"
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
],
|
| 1059 |
-
"application/javascript": [
|
| 1060 |
-
"\n",
|
| 1061 |
-
" async function download(id, filename, size) {\n",
|
| 1062 |
-
" if (!google.colab.kernel.accessAllowed) {\n",
|
| 1063 |
-
" return;\n",
|
| 1064 |
-
" }\n",
|
| 1065 |
-
" const div = document.createElement('div');\n",
|
| 1066 |
-
" const label = document.createElement('label');\n",
|
| 1067 |
-
" label.textContent = `Downloading \"${filename}\": `;\n",
|
| 1068 |
-
" div.appendChild(label);\n",
|
| 1069 |
-
" const progress = document.createElement('progress');\n",
|
| 1070 |
-
" progress.max = size;\n",
|
| 1071 |
-
" div.appendChild(progress);\n",
|
| 1072 |
-
" document.body.appendChild(div);\n",
|
| 1073 |
-
"\n",
|
| 1074 |
-
" const buffers = [];\n",
|
| 1075 |
-
" let downloaded = 0;\n",
|
| 1076 |
-
"\n",
|
| 1077 |
-
" const channel = await google.colab.kernel.comms.open(id);\n",
|
| 1078 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 1079 |
-
" channel.send({})\n",
|
| 1080 |
-
"\n",
|
| 1081 |
-
" for await (const message of channel.messages) {\n",
|
| 1082 |
-
" // Send a message to notify the kernel that we're ready.\n",
|
| 1083 |
-
" channel.send({})\n",
|
| 1084 |
-
" if (message.buffers) {\n",
|
| 1085 |
-
" for (const buffer of message.buffers) {\n",
|
| 1086 |
-
" buffers.push(buffer);\n",
|
| 1087 |
-
" downloaded += buffer.byteLength;\n",
|
| 1088 |
-
" progress.value = downloaded;\n",
|
| 1089 |
-
" }\n",
|
| 1090 |
-
" }\n",
|
| 1091 |
-
" }\n",
|
| 1092 |
-
" const blob = new Blob(buffers, {type: 'application/binary'});\n",
|
| 1093 |
-
" const a = document.createElement('a');\n",
|
| 1094 |
-
" a.href = window.URL.createObjectURL(blob);\n",
|
| 1095 |
-
" a.download = filename;\n",
|
| 1096 |
-
" div.appendChild(a);\n",
|
| 1097 |
-
" a.click();\n",
|
| 1098 |
-
" div.remove();\n",
|
| 1099 |
-
" }\n",
|
| 1100 |
-
" "
|
| 1101 |
-
]
|
| 1102 |
-
},
|
| 1103 |
-
"metadata": {}
|
| 1104 |
-
},
|
| 1105 |
-
{
|
| 1106 |
-
"output_type": "display_data",
|
| 1107 |
-
"data": {
|
| 1108 |
-
"text/plain": [
|
| 1109 |
-
"<IPython.core.display.Javascript object>"
|
| 1110 |
-
],
|
| 1111 |
-
"application/javascript": [
|
| 1112 |
-
"download(\"download_2729bae4-56fd-42a8-8baf-585fe75b983c\", \"pothole_weights.zip\", 32567058)"
|
| 1113 |
-
]
|
| 1114 |
-
},
|
| 1115 |
-
"metadata": {}
|
| 1116 |
-
}
|
| 1117 |
]
|
| 1118 |
}
|
| 1119 |
-
]
|
| 1120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "markdown",
|
| 5 |
+
"metadata": {
|
| 6 |
+
"id": "v_iQK6_S0_pc"
|
| 7 |
+
},
|
| 8 |
"source": [
|
| 9 |
+
"# YOLOv8 Pothole & Road Damage Detector Training\n",
|
| 10 |
"\n",
|
| 11 |
+
"**Output:** `best.onnx` -> deployed to `frontend/public/models/best.onnx`\n",
|
|
|
|
| 12 |
"\n",
|
| 13 |
+
"This notebook trains a YOLOv8 nano model to detect road damage (potholes, cracks, manholes)\n",
|
| 14 |
+
"using a custom Roboflow dataset merged with the Kaggle RDD2022 dataset.\n",
|
| 15 |
"\n",
|
| 16 |
"---\n",
|
| 17 |
+
"### Dataset\n",
|
| 18 |
+
"- **Source 1:** Custom Roboflow Pothole Dataset (v3)\n",
|
| 19 |
+
"- **Source 2:** Kaggle RDD2022 (Road Damage Detection 2022)\n",
|
| 20 |
+
"- **Total Images:** ~2,000+\n",
|
| 21 |
+
"- **Classes:** `0: pothole`, `1: crack`, `2: manhole`\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
"\n",
|
| 23 |
+
"### Pipeline\n",
|
| 24 |
+
"`Roboflow + Kaggle Data -> Merge -> YOLOv8n Train (50 epochs) -> ONNX Export`"
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"cell_type": "markdown",
|
| 29 |
+
"metadata": {
|
| 30 |
+
"id": "SAAYhbS5pEM1"
|
| 31 |
+
},
|
| 32 |
+
"source": [
|
| 33 |
+
"## Pre-requisite - Anti-Disconnect Script\n",
|
| 34 |
+
"Keeps the Colab session alive during long vector embedding processes."
|
| 35 |
]
|
| 36 |
},
|
| 37 |
{
|
|
|
|
| 46 |
"id": "uwTMRE_8C740",
|
| 47 |
"outputId": "ecfb62d6-9b10-4bc0-caa0-971da9a80c3e"
|
| 48 |
},
|
| 49 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
"source": [
|
| 51 |
"import time\n",
|
| 52 |
"from IPython.display import Javascript\n",
|
|
|
|
| 61 |
},
|
| 62 |
{
|
| 63 |
"cell_type": "markdown",
|
| 64 |
+
"metadata": {
|
| 65 |
+
"id": "Pg1-Sr4T0_pk"
|
| 66 |
+
},
|
| 67 |
"source": [
|
| 68 |
+
"## Step 1 - Install Dependencies\n",
|
| 69 |
"\n",
|
| 70 |
+
"Installs `ultralytics` for YOLOv8 training, `roboflow` for dataset download,\n",
|
| 71 |
+
"and `onnx` tools for the final model export."
|
|
|
|
|
|
|
| 72 |
]
|
| 73 |
},
|
| 74 |
{
|
| 75 |
"cell_type": "code",
|
| 76 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
| 77 |
"metadata": {
|
| 78 |
"colab": {
|
| 79 |
"base_uri": "https://localhost:8080/"
|
|
|
|
| 82 |
"id": "I0GBSI74DVJI",
|
| 83 |
"outputId": "a71f5e00-bbe6-458c-c79d-5e9d75c8931f"
|
| 84 |
},
|
| 85 |
+
"outputs": [],
|
| 86 |
+
"source": [
|
| 87 |
+
"!pip install ultralytics roboflow -q\n",
|
| 88 |
+
"!pip install onnx onnxruntime -q"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
]
|
| 90 |
},
|
| 91 |
{
|
| 92 |
"cell_type": "markdown",
|
| 93 |
+
"metadata": {
|
| 94 |
+
"id": "Gyy-NB5t0_qK"
|
| 95 |
+
},
|
| 96 |
"source": [
|
| 97 |
+
"## Step 2 - Check GPU\n",
|
| 98 |
"\n",
|
| 99 |
+
"Verifies that CUDA is available and the GPU is correctly mapped.\n",
|
| 100 |
+
"Essential for accelerating YOLO training."
|
| 101 |
]
|
| 102 |
},
|
| 103 |
{
|
| 104 |
"cell_type": "code",
|
| 105 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
"metadata": {
|
| 107 |
"colab": {
|
| 108 |
"base_uri": "https://localhost:8080/"
|
|
|
|
| 111 |
"id": "yJoIU507DcKF",
|
| 112 |
"outputId": "e92f642d-1464-45e4-ec35-cd3c7eb402bf"
|
| 113 |
},
|
| 114 |
+
"outputs": [],
|
| 115 |
+
"source": [
|
| 116 |
+
"\n",
|
| 117 |
+
"import os\n",
|
| 118 |
+
"from ultralytics import YOLO\n",
|
| 119 |
+
"print(\"✅ Ultralytics ready, CUDA:\", os.popen(\"nvidia-smi --query-gpu=name --format=csv,noheader\").read().strip())"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
]
|
| 121 |
},
|
| 122 |
{
|
| 123 |
"cell_type": "markdown",
|
| 124 |
+
"metadata": {
|
| 125 |
+
"id": "Tfz0yuQJ0_qL"
|
| 126 |
+
},
|
| 127 |
"source": [
|
| 128 |
+
"## Step 3 - Download Base Dataset (Roboflow)\n",
|
| 129 |
"\n",
|
| 130 |
+
"Downloads the initial custom dataset containing labeled potholes,\n",
|
| 131 |
+
"cracks, and manholes."
|
|
|
|
|
|
|
|
|
|
| 132 |
]
|
| 133 |
},
|
| 134 |
{
|
| 135 |
"cell_type": "code",
|
| 136 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
| 137 |
"metadata": {
|
| 138 |
"colab": {
|
| 139 |
"base_uri": "https://localhost:8080/",
|
|
|
|
| 142 |
"id": "t7uQDAFzDeaJ",
|
| 143 |
"outputId": "e5e7f1b4-8a1d-4d91-b2a9-feddd6783794"
|
| 144 |
},
|
| 145 |
+
"outputs": [],
|
| 146 |
+
"source": [
|
| 147 |
+
"from google.colab import files\n",
|
| 148 |
+
"uploaded = files.upload()"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
]
|
| 150 |
},
|
| 151 |
{
|
| 152 |
"cell_type": "markdown",
|
| 153 |
+
"metadata": {
|
| 154 |
+
"id": "9-YN4Yie0_qM"
|
| 155 |
+
},
|
| 156 |
"source": [
|
| 157 |
+
"## Step 4 - Download Kaggle RDD2022 Dataset\n",
|
| 158 |
"\n",
|
| 159 |
+
"Fetches the massive Road Damage Detection dataset from Kaggle to supplement\n",
|
| 160 |
+
"the Roboflow dataset and improve model generalization."
|
| 161 |
]
|
| 162 |
},
|
| 163 |
{
|
| 164 |
"cell_type": "code",
|
| 165 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
"metadata": {
|
| 167 |
"colab": {
|
| 168 |
"base_uri": "https://localhost:8080/"
|
|
|
|
| 170 |
"id": "MdUI5xwtK6fp",
|
| 171 |
"outputId": "945affb4-bba0-496f-c1f6-9429cad842eb"
|
| 172 |
},
|
| 173 |
+
"outputs": [],
|
| 174 |
+
"source": [
|
| 175 |
+
"# Cell 3 — Extract the main zipped dataset\n",
|
| 176 |
+
"import zipfile\n",
|
| 177 |
+
"\n",
|
| 178 |
+
"with zipfile.ZipFile('/content/archive.zip', 'r') as z:\n",
|
| 179 |
+
" z.extractall('/content/pothole_data')\n",
|
| 180 |
+
"print(\"✅ archive.zip extracted successfully\")\n"
|
|
|
|
| 181 |
]
|
| 182 |
},
|
| 183 |
{
|
| 184 |
"cell_type": "markdown",
|
| 185 |
+
"metadata": {
|
| 186 |
+
"id": "2cwRMkKa0_qN"
|
| 187 |
+
},
|
| 188 |
"source": [
|
| 189 |
+
"## Step 5 - Standardize Kaggle Labels\n",
|
| 190 |
"\n",
|
| 191 |
+
"The Kaggle dataset uses 4 classes (`D00, D10, D20, D40`).\n",
|
| 192 |
+
"This step maps them to our custom 3 classes:\n",
|
| 193 |
+
"- `D00` (Longitudinal Crack) -> `1` (crack)\n",
|
| 194 |
+
"- `D10` (Transverse Crack) -> `1` (crack)\n",
|
| 195 |
+
"- `D20` (Alligator Crack) -> `1` (crack)\n",
|
| 196 |
+
"- `D40` (Pothole) -> `0` (pothole)"
|
| 197 |
]
|
| 198 |
},
|
| 199 |
{
|
| 200 |
"cell_type": "code",
|
| 201 |
+
"execution_count": null,
|
| 202 |
+
"metadata": {
|
| 203 |
+
"colab": {
|
| 204 |
+
"base_uri": "https://localhost:8080/"
|
| 205 |
+
},
|
| 206 |
+
"id": "RMlyOEcEK-Zz",
|
| 207 |
+
"outputId": "bd472e3d-d1be-4d07-daaa-db42568eb77c"
|
| 208 |
+
},
|
| 209 |
+
"outputs": [],
|
| 210 |
"source": [
|
| 211 |
"# Cell 4 — Setup master directory structure for merged datasets\n",
|
| 212 |
"import os, shutil\n",
|
|
|
|
| 220 |
"for p in [merged_train_img, merged_train_lbl, merged_val_img, merged_val_lbl]:\n",
|
| 221 |
" os.makedirs(p, exist_ok=True)\n",
|
| 222 |
"print(\"✅ Master directories created\")\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
]
|
| 224 |
},
|
| 225 |
{
|
| 226 |
"cell_type": "markdown",
|
| 227 |
+
"metadata": {
|
| 228 |
+
"id": "371UYSus0_qO"
|
| 229 |
+
},
|
| 230 |
"source": [
|
| 231 |
+
"## Step 6 - Merge Datasets\n",
|
| 232 |
"\n",
|
| 233 |
+
"Iterates through both the Roboflow and Kaggle dataset directories,\n",
|
| 234 |
+
"checks for corresponding images and standardized label files, and\n",
|
| 235 |
"then copies them all into the master `merged/train/` directory.\n",
|
| 236 |
"\n",
|
| 237 |
+
"> Result: **2,009 training images** merged."
|
| 238 |
]
|
| 239 |
},
|
| 240 |
{
|
| 241 |
"cell_type": "code",
|
| 242 |
+
"execution_count": null,
|
| 243 |
+
"metadata": {
|
| 244 |
+
"colab": {
|
| 245 |
+
"base_uri": "https://localhost:8080/"
|
| 246 |
+
},
|
| 247 |
+
"id": "lJZFF47NLEFJ",
|
| 248 |
+
"outputId": "04ff65e2-a9c7-4ce6-d2dd-11d1139a6a8f"
|
| 249 |
+
},
|
| 250 |
+
"outputs": [],
|
| 251 |
"source": [
|
| 252 |
"# Cell 5 — Copy all images and labels into the merged folder (Bulletproof Search)\n",
|
| 253 |
"# List of directories containing datasets (Assuming they are available in /content/)\n",
|
|
|
|
| 269 |
" shutil.copy(lbl, merged_train_lbl)\n",
|
| 270 |
"\n",
|
| 271 |
"print('✅ Merging complete. Total train images:', len(list(Path(merged_train_img).glob('*.jpg'))))\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
]
|
| 273 |
},
|
| 274 |
{
|
| 275 |
"cell_type": "markdown",
|
| 276 |
+
"metadata": {
|
| 277 |
+
"id": "IPleZZ6U0_qP"
|
| 278 |
+
},
|
| 279 |
"source": [
|
| 280 |
+
"## Step 7 - Write `data.yaml`\n",
|
| 281 |
"\n",
|
| 282 |
"Creates the YOLO dataset configuration file defining:\n",
|
| 283 |
"- 3 detection classes: `['pothole', 'crack', 'manhole']`\n",
|
|
|
|
| 288 |
},
|
| 289 |
{
|
| 290 |
"cell_type": "code",
|
| 291 |
+
"execution_count": null,
|
| 292 |
+
"metadata": {
|
| 293 |
+
"colab": {
|
| 294 |
+
"base_uri": "https://localhost:8080/"
|
| 295 |
+
},
|
| 296 |
+
"id": "f5Cmy0iuMZSC",
|
| 297 |
+
"outputId": "15593ba5-a0b6-46f9-a751-367262c4f65f"
|
| 298 |
+
},
|
| 299 |
+
"outputs": [],
|
| 300 |
"source": [
|
| 301 |
"# Cell 6 — Create data.yaml mapping to our 3 classes\n",
|
| 302 |
"data_yaml = \"\"\"\n",
|
|
|
|
| 311 |
" f.write(data_yaml)\n",
|
| 312 |
"\n",
|
| 313 |
"print(\"✅ data.yaml written\")\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
]
|
| 315 |
},
|
| 316 |
{
|
| 317 |
"cell_type": "markdown",
|
| 318 |
+
"metadata": {
|
| 319 |
+
"id": "DfzFlcQy0_qP"
|
| 320 |
+
},
|
| 321 |
"source": [
|
| 322 |
+
"## Step 8 - Train YOLOv8n (50 Epochs) & Export ONNX\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
"\n",
|
| 324 |
+
"Trains YOLOv8 nano on the merged dataset.\n",
|
| 325 |
+
"**It will then export to ONNX and download the final model.**"
|
|
|
|
| 326 |
]
|
| 327 |
},
|
| 328 |
{
|
| 329 |
"cell_type": "code",
|
| 330 |
+
"execution_count": null,
|
| 331 |
+
"metadata": {
|
| 332 |
+
"colab": {
|
| 333 |
+
"base_uri": "https://localhost:8080/"
|
| 334 |
+
},
|
| 335 |
+
"collapsed": true,
|
| 336 |
+
"id": "kXWxRFmaMcyE",
|
| 337 |
+
"outputId": "66b2cdd5-193d-4946-cbaf-b39dc5fa24ae"
|
| 338 |
+
},
|
| 339 |
+
"outputs": [],
|
| 340 |
"source": [
|
| 341 |
"# Cell 7 — Train (45-60 min on T4 GPU)\n",
|
| 342 |
"model = YOLO('yolov8n.pt')\n",
|
|
|
|
| 352 |
" save=True,\n",
|
| 353 |
")\n",
|
| 354 |
"print(\"✅ YOLO Training Finished\")\n"
|
| 355 |
+
]
|
| 356 |
+
},
|
| 357 |
+
{
|
| 358 |
+
"cell_type": "markdown",
|
| 359 |
"metadata": {
|
| 360 |
+
"id": "vHVZjW4w4Zd6"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
},
|
| 362 |
+
"source": [
|
| 363 |
+
"### Step 8.1 - Export to ONNX & TorchScript\n",
|
| 364 |
+
"Exports the trained YOLOv8 model to ONNX and TorchScript formats for deployment."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
]
|
| 366 |
},
|
| 367 |
{
|
| 368 |
"cell_type": "code",
|
| 369 |
+
"execution_count": null,
|
| 370 |
+
"metadata": {
|
| 371 |
+
"colab": {
|
| 372 |
+
"base_uri": "https://localhost:8080/"
|
| 373 |
+
},
|
| 374 |
+
"collapsed": true,
|
| 375 |
+
"id": "53VaY29vfU3S",
|
| 376 |
+
"outputId": "43484095-f9d9-43bd-efbf-cef0b272448a"
|
| 377 |
+
},
|
| 378 |
+
"outputs": [],
|
| 379 |
"source": [
|
| 380 |
"# Cell 8 — Export ONNX\n",
|
| 381 |
"best_model = YOLO('/content/runs/detect/pothole_v1/weights/best.pt')\n",
|
| 382 |
"best_model.export(format='onnx', imgsz=640, opset=12, simplify=True)\n",
|
| 383 |
"best_model.export(format='torchscript')\n",
|
| 384 |
"print(\"✅ ONNX models generated\")\n"
|
| 385 |
+
]
|
| 386 |
+
},
|
| 387 |
+
{
|
| 388 |
+
"cell_type": "markdown",
|
| 389 |
"metadata": {
|
| 390 |
+
"id": "G8eMKCO24oWA"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
},
|
| 392 |
+
"source": [
|
| 393 |
+
"### Step 8.2 - Download the Final Model\n",
|
| 394 |
+
"Zips the training results and downloads the final weights and ONNX models to your local machine."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
]
|
| 396 |
},
|
| 397 |
{
|
| 398 |
"cell_type": "code",
|
| 399 |
+
"execution_count": null,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
"metadata": {
|
| 401 |
"colab": {
|
| 402 |
"base_uri": "https://localhost:8080/",
|
|
|
|
| 405 |
"id": "SEZ7OyABfs_3",
|
| 406 |
"outputId": "e237add9-7506-4af3-cae3-8827fb64c9fc"
|
| 407 |
},
|
| 408 |
+
"outputs": [],
|
| 409 |
+
"source": [
|
| 410 |
+
"# Cell 9 — Download the weights\n",
|
| 411 |
+
"import shutil\n",
|
| 412 |
+
"from google.colab import files\n",
|
| 413 |
+
"shutil.make_archive('/content/pothole_weights', 'zip', '/content/runs/detect/pothole_v1/weights')\n",
|
| 414 |
+
"files.download('/content/pothole_weights.zip')\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
]
|
| 416 |
}
|
| 417 |
+
],
|
| 418 |
+
"metadata": {
|
| 419 |
+
"accelerator": "GPU",
|
| 420 |
+
"colab": {
|
| 421 |
+
"gpuType": "T4",
|
| 422 |
+
"provenance": []
|
| 423 |
+
},
|
| 424 |
+
"kernelspec": {
|
| 425 |
+
"display_name": "Python 3",
|
| 426 |
+
"name": "python3"
|
| 427 |
+
},
|
| 428 |
+
"language_info": {
|
| 429 |
+
"name": "python"
|
| 430 |
+
}
|
| 431 |
+
},
|
| 432 |
+
"nbformat": 4,
|
| 433 |
+
"nbformat_minor": 0
|
| 434 |
+
}
|
scripts/backend/data/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# backend/data scripts — pure Python data transforms (no DB required)
|
scripts/scripts/data/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# scripts/data — pure Python data scripts (no DB required)
|
scripts/scripts/data/_overpass_utils.py
CHANGED
|
@@ -9,7 +9,6 @@ from pathlib import Path
|
|
| 9 |
from typing import Iterable
|
| 10 |
|
| 11 |
|
| 12 |
-
ROOT_DIR = Path(__file__).resolve().parents[1]
|
| 13 |
DEFAULT_ENDPOINTS = (
|
| 14 |
'https://overpass-api.de/api/interpreter',
|
| 15 |
'https://overpass.kumi.systems/api/interpreter',
|
|
@@ -69,7 +68,7 @@ def build_india_query(selectors: Iterable[str], *, timeout: int) -> str:
|
|
| 69 |
)
|
| 70 |
|
| 71 |
|
| 72 |
-
def fetch_elements(query: str, *, endpoint: str | None, timeout: int) -> list[dict]:
|
| 73 |
payload = urllib.parse.urlencode({'data': query}).encode('utf-8')
|
| 74 |
endpoints = [endpoint] if endpoint else list(DEFAULT_ENDPOINTS)
|
| 75 |
last_error: Exception | None = None
|
|
@@ -109,7 +108,7 @@ def compose_address(tags: dict[str, str]) -> str:
|
|
| 109 |
return ', '.join(part for part in parts if part)
|
| 110 |
|
| 111 |
|
| 112 |
-
def normalize_row(element: dict, *, default_type: str, fallback_name: str) -> dict | None:
|
| 113 |
lat, lon = extract_point(element)
|
| 114 |
if lat is None or lon is None:
|
| 115 |
return None
|
|
|
|
| 9 |
from typing import Iterable
|
| 10 |
|
| 11 |
|
|
|
|
| 12 |
DEFAULT_ENDPOINTS = (
|
| 13 |
'https://overpass-api.de/api/interpreter',
|
| 14 |
'https://overpass.kumi.systems/api/interpreter',
|
|
|
|
| 68 |
)
|
| 69 |
|
| 70 |
|
| 71 |
+
def fetch_elements(query: str, *, endpoint: str | None, timeout: int, **kwargs) -> list[dict]:
|
| 72 |
payload = urllib.parse.urlencode({'data': query}).encode('utf-8')
|
| 73 |
endpoints = [endpoint] if endpoint else list(DEFAULT_ENDPOINTS)
|
| 74 |
last_error: Exception | None = None
|
|
|
|
| 108 |
return ', '.join(part for part in parts if part)
|
| 109 |
|
| 110 |
|
| 111 |
+
def normalize_row(element: dict, *, default_type: str, fallback_name: str, **kwargs) -> dict | None:
|
| 112 |
lat, lon = extract_point(element)
|
| 113 |
if lat is None or lon is None:
|
| 114 |
return None
|
scripts/scripts/data/bootstrap_local_data.py
CHANGED
|
@@ -8,7 +8,6 @@ import math
|
|
| 8 |
import shutil
|
| 9 |
import struct
|
| 10 |
import sys
|
| 11 |
-
import tempfile
|
| 12 |
import zipfile
|
| 13 |
from pathlib import Path
|
| 14 |
|
|
|
|
| 8 |
import shutil
|
| 9 |
import struct
|
| 10 |
import sys
|
|
|
|
| 11 |
import zipfile
|
| 12 |
from pathlib import Path
|
| 13 |
|
scripts/scripts/data/fetch_ambulance.py
CHANGED
|
@@ -4,7 +4,10 @@ import logging
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
-
from
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'emergency' / 'ambulance_stations.csv'
|
|
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
ROOT_DIR = Path(__file__).resolve().parents[2]
|
| 9 |
+
|
| 10 |
+
from _overpass_utils import build_arg_parser, build_india_query, fetch_elements, normalize_row, write_rows
|
| 11 |
|
| 12 |
|
| 13 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'emergency' / 'ambulance_stations.csv'
|
scripts/scripts/data/fetch_blood_banks.py
CHANGED
|
@@ -4,7 +4,10 @@ import logging
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
-
from
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'hospitals' / 'blood_bank_directory.csv'
|
|
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
ROOT_DIR = Path(__file__).resolve().parents[2]
|
| 9 |
+
|
| 10 |
+
from _overpass_utils import build_arg_parser, build_india_query, fetch_elements, normalize_row, write_rows
|
| 11 |
|
| 12 |
|
| 13 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'hospitals' / 'blood_bank_directory.csv'
|
scripts/scripts/data/fetch_fire.py
CHANGED
|
@@ -4,7 +4,10 @@ import logging
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
-
from
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'emergency' / 'fire_stations.csv'
|
|
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
ROOT_DIR = Path(__file__).resolve().parents[2]
|
| 9 |
+
|
| 10 |
+
from _overpass_utils import build_arg_parser, build_india_query, fetch_elements, normalize_row, write_rows
|
| 11 |
|
| 12 |
|
| 13 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'emergency' / 'fire_stations.csv'
|
scripts/scripts/data/fetch_hospitals.py
CHANGED
|
@@ -4,7 +4,10 @@ import logging
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
-
from
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'hospitals' / 'hospital_directory.csv'
|
|
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
ROOT_DIR = Path(__file__).resolve().parents[2]
|
| 9 |
+
|
| 10 |
+
from _overpass_utils import build_arg_parser, build_india_query, fetch_elements, normalize_row, write_rows
|
| 11 |
|
| 12 |
|
| 13 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'hospitals' / 'hospital_directory.csv'
|
scripts/scripts/data/fetch_police.py
CHANGED
|
@@ -4,7 +4,10 @@ import logging
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
-
from
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'emergency' / 'police_stations.csv'
|
|
|
|
| 4 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 5 |
LOGGER = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
ROOT_DIR = Path(__file__).resolve().parents[2]
|
| 9 |
+
|
| 10 |
+
from _overpass_utils import build_arg_parser, build_india_query, fetch_elements, normalize_row, write_rows
|
| 11 |
|
| 12 |
|
| 13 |
DEFAULT_OUTPUT = ROOT_DIR / 'chatbot_service' / 'data' / 'emergency' / 'police_stations.csv'
|