|
6 | 6 | "name": "inference-yolov5.ipynb", |
7 | 7 | "provenance": [], |
8 | 8 | "collapsed_sections": [], |
9 | | - "authorship_tag": "ABX9TyObNAqoCBWpY38Bbtv0OicP", |
| 9 | + "authorship_tag": "ABX9TyMwTRY4jES52AAhaWMtIQW3", |
10 | 10 | "include_colab_link": true |
11 | 11 | }, |
12 | 12 | "kernelspec": { |
|
45 | 45 | "base_uri": "https://localhost:8080/" |
46 | 46 | }, |
47 | 47 | "id": "OA0ulv5qAAK-", |
48 | | - "outputId": "287344eb-f0ee-4687-e220-b5704ccbc2ea" |
| 48 | + "outputId": "d2ac4618-e803-42bc-bade-491bf3d72054" |
49 | 49 | }, |
50 | 50 | "source": [ |
51 | 51 | "# Make sure you use the Colab GPU to run the testing phase\n", |
|
54 | 54 | "torch.cuda.is_available()\n", |
55 | 55 | "!nvidia-smi" |
56 | 56 | ], |
57 | | - "execution_count": null, |
| 57 | + "execution_count": 2, |
58 | 58 | "outputs": [ |
59 | 59 | { |
60 | 60 | "output_type": "stream", |
61 | 61 | "name": "stdout", |
62 | 62 | "text": [ |
63 | | - "Tue Nov 16 12:07:52 2021 \n", |
| 63 | + "Wed Nov 17 07:31:46 2021 \n", |
64 | 64 | "+-----------------------------------------------------------------------------+\n", |
65 | 65 | "| NVIDIA-SMI 495.44 Driver Version: 460.32.03 CUDA Version: 11.2 |\n", |
66 | 66 | "|-------------------------------+----------------------+----------------------+\n", |
|
69 | 69 | "| | | MIG M. |\n", |
70 | 70 | "|===============================+======================+======================|\n", |
71 | 71 | "| 0 Tesla K80 Off | 00000000:00:04.0 Off | 0 |\n", |
72 | | - "| N/A 35C P8 28W / 149W | 3MiB / 11441MiB | 0% Default |\n", |
| 72 | + "| N/A 34C P8 27W / 149W | 3MiB / 11441MiB | 0% Default |\n", |
73 | 73 | "| | | N/A |\n", |
74 | 74 | "+-------------------------------+----------------------+----------------------+\n", |
75 | 75 | " \n", |
|
100 | 100 | "base_uri": "https://localhost:8080/" |
101 | 101 | }, |
102 | 102 | "id": "qJXVHsenA2QU", |
103 | | - "outputId": "dea5f124-50ac-4733-ca3f-6e03ee01c4f8" |
| 103 | + "outputId": "06d1fed8-cdec-4f5b-efa1-a8b90ad11b73" |
104 | 104 | }, |
105 | 105 | "source": [ |
106 | 106 | "!git clone https://github.com/joycenerd/yolov5-svhn-detection.git" |
107 | 107 | ], |
108 | | - "execution_count": null, |
| 108 | + "execution_count": 3, |
109 | 109 | "outputs": [ |
110 | 110 | { |
111 | 111 | "output_type": "stream", |
112 | 112 | "name": "stdout", |
113 | 113 | "text": [ |
114 | 114 | "Cloning into 'yolov5-svhn-detection'...\n", |
115 | | - "remote: Enumerating objects: 106, done.\u001b[K\n", |
116 | | - "remote: Counting objects: 100% (106/106), done.\u001b[K\n", |
117 | | - "remote: Compressing objects: 100% (83/83), done.\u001b[K\n", |
118 | | - "remote: Total 106 (delta 24), reused 101 (delta 22), pack-reused 0\u001b[K\n", |
119 | | - "Receiving objects: 100% (106/106), 177.05 KiB | 2.53 MiB/s, done.\n", |
120 | | - "Resolving deltas: 100% (24/24), done.\n" |
| 115 | + "remote: Enumerating objects: 109, done.\u001b[K\n", |
| 116 | + "remote: Counting objects: 100% (109/109), done.\u001b[K\n", |
| 117 | + "remote: Compressing objects: 100% (86/86), done.\u001b[K\n", |
| 118 | + "remote: Total 109 (delta 25), reused 100 (delta 22), pack-reused 0\u001b[K\n", |
| 119 | + "Receiving objects: 100% (109/109), 181.64 KiB | 2.36 MiB/s, done.\n", |
| 120 | + "Resolving deltas: 100% (25/25), done.\n" |
121 | 121 | ] |
122 | 122 | } |
123 | 123 | ] |
|
138 | 138 | "base_uri": "https://localhost:8080/" |
139 | 139 | }, |
140 | 140 | "id": "yEi4yJ3QCouL", |
141 | | - "outputId": "f0dbde1c-d19a-48f3-cf0a-2ae811ec2791" |
| 141 | + "outputId": "962762b3-3d7b-4198-964a-e6e4721c9011" |
142 | 142 | }, |
143 | 143 | "source": [ |
144 | 144 | "%cd yolov5-svhn-detection/yolov5/\n", |
145 | 145 | "!pip install -r requirements.txt\n", |
146 | 146 | "!pip install googledrivedownloader" |
147 | 147 | ], |
148 | | - "execution_count": null, |
| 148 | + "execution_count": 4, |
149 | 149 | "outputs": [ |
150 | 150 | { |
151 | 151 | "output_type": "stream", |
|
169 | 169 | "Requirement already satisfied: seaborn>=0.11.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 21)) (0.11.2)\n", |
170 | 170 | "Collecting thop\n", |
171 | 171 | " Downloading thop-0.0.31.post2005241907-py3-none-any.whl (8.7 kB)\n", |
172 | | - "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 4)) (2.8.2)\n", |
173 | | - "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 4)) (1.3.2)\n", |
174 | 172 | "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 4)) (0.11.0)\n", |
175 | 173 | "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 4)) (2.4.7)\n", |
| 174 | + "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 4)) (1.3.2)\n", |
| 175 | + "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=3.2.2->-r requirements.txt (line 4)) (2.8.2)\n", |
176 | 176 | "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23.0->-r requirements.txt (line 9)) (3.0.4)\n", |
177 | | - "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23.0->-r requirements.txt (line 9)) (2.10)\n", |
178 | | - "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23.0->-r requirements.txt (line 9)) (1.24.3)\n", |
179 | 177 | "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23.0->-r requirements.txt (line 9)) (2021.10.8)\n", |
| 178 | + "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23.0->-r requirements.txt (line 9)) (1.24.3)\n", |
| 179 | + "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.23.0->-r requirements.txt (line 9)) (2.10)\n", |
180 | 180 | "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch>=1.7.0->-r requirements.txt (line 11)) (3.10.0.2)\n", |
181 | | - "Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (3.3.4)\n", |
182 | | - "Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (1.0.1)\n", |
183 | | - "Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (1.35.0)\n", |
184 | | - "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (0.4.6)\n", |
185 | | - "Requirement already satisfied: grpcio>=1.24.3 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (1.41.1)\n", |
| 181 | + "Requirement already satisfied: absl-py>=0.4 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (0.12.0)\n", |
186 | 182 | "Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (0.6.1)\n", |
187 | 183 | "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (1.8.0)\n", |
188 | | - "Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (57.4.0)\n", |
189 | | - "Requirement already satisfied: absl-py>=0.4 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (0.12.0)\n", |
| 184 | + "Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (1.0.1)\n", |
190 | 185 | "Requirement already satisfied: protobuf>=3.6.0 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (3.17.3)\n", |
191 | 186 | "Requirement already satisfied: wheel>=0.26 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (0.37.0)\n", |
| 187 | + "Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (3.3.4)\n", |
| 188 | + "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (0.4.6)\n", |
| 189 | + "Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (57.4.0)\n", |
| 190 | + "Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (1.35.0)\n", |
| 191 | + "Requirement already satisfied: grpcio>=1.24.3 in /usr/local/lib/python3.7/dist-packages (from tensorboard>=2.4.1->-r requirements.txt (line 16)) (1.41.1)\n", |
192 | 192 | "Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas>=1.1.4->-r requirements.txt (line 20)) (2018.9)\n", |
193 | 193 | "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from absl-py>=0.4->tensorboard>=2.4.1->-r requirements.txt (line 16)) (1.15.0)\n", |
194 | | - "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.7/dist-packages (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r requirements.txt (line 16)) (0.2.8)\n", |
195 | 194 | "Requirement already satisfied: cachetools<5.0,>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r requirements.txt (line 16)) (4.2.4)\n", |
196 | 195 | "Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.7/dist-packages (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r requirements.txt (line 16)) (4.7.2)\n", |
| 196 | + "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.7/dist-packages (from google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r requirements.txt (line 16)) (0.2.8)\n", |
197 | 197 | "Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.7/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard>=2.4.1->-r requirements.txt (line 16)) (1.3.0)\n", |
198 | 198 | "Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from markdown>=2.6.8->tensorboard>=2.4.1->-r requirements.txt (line 16)) (4.8.2)\n", |
199 | 199 | "Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in /usr/local/lib/python3.7/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard>=2.4.1->-r requirements.txt (line 16)) (0.4.8)\n", |
|
217 | 217 | "base_uri": "https://localhost:8080/" |
218 | 218 | }, |
219 | 219 | "id": "1_CN3AyvD451", |
220 | | - "outputId": "19dfcc53-acd1-4e98-f541-e40162620d05" |
| 220 | + "outputId": "5bc91a50-229c-4f9d-9ce8-8c197dec9595" |
221 | 221 | }, |
222 | 222 | "source": [ |
223 | 223 | "import argparse\n", |
|
246 | 246 | "from tqdm import tqdm\n", |
247 | 247 | "from google_drive_downloader import GoogleDriveDownloader as gdd" |
248 | 248 | ], |
249 | | - "execution_count": null, |
| 249 | + "execution_count": 5, |
250 | 250 | "outputs": [ |
251 | 251 | { |
252 | 252 | "output_type": "stream", |
253 | 253 | "name": "stdout", |
254 | 254 | "text": [ |
255 | | - "/content/yolov5-svhn-detection/yolov5\n" |
| 255 | + "/content/yolov5-svhn-detection/yolov5\n", |
| 256 | + "Downloading https://ultralytics.com/assets/Arial.ttf to /root/.config/Ultralytics/Arial.ttf...\n" |
256 | 257 | ] |
257 | 258 | } |
258 | 259 | ] |
|
263 | 264 | "id": "uAb_xc0oGKhS" |
264 | 265 | }, |
265 | 266 | "source": [ |
266 | | - "# Step 3: Load model\n" |
| 267 | + "# Step 3: Load model\n", |
| 268 | + "\n", |
| 269 | + "If you want to reproduce our results, please download the checkpoint from https://github.com/joycenerd/yolov5-svhn-detection. Download from this repo's lastest release that has the name 'yolov5_best.pt'. And upload the downloaded checkpoint into this Google Colab workspace. (downloaded checkpoint path: /content/best_ckpt.pt)\n", |
| 270 | + "\n", |
| 271 | + "If you want to play around with your own model just upload your own checkpoint file here and modified the `weights` path below.\n", |
| 272 | + "\n", |
| 273 | + "<font color=#FF0000>Note: We use YOLOv5 in this repo https://github.com/ultralytics/yolov5 as our model. Your checkpoint `model_state_dict` should be compatible with our model.</font>\n" |
267 | 274 | ] |
268 | 275 | }, |
269 | 276 | { |
|
273 | 280 | "base_uri": "https://localhost:8080/" |
274 | 281 | }, |
275 | 282 | "id": "qYg_j6JrHHuG", |
276 | | - "outputId": "37783750-be66-42bd-ad48-3ae76f2cbb00" |
| 283 | + "outputId": "9bbf594f-32bb-4ab8-dc48-941ad1192895" |
277 | 284 | }, |
278 | 285 | "source": [ |
279 | | - "weights=['/content/ep54_mAP495.pt']\n", |
| 286 | + "weights=['/content/yolov5_best.pt']\n", |
280 | 287 | "device=select_device('0')\n", |
281 | 288 | "model=DetectMultiBackend(weights,device=device,dnn=False)\n", |
282 | 289 | "stride, names, pt, jit, onnx = model.stride, model.names, model.pt, model.jit, model.onnx\n", |
283 | 290 | "imgsz = check_img_size(imgsz=640, s=stride) # check image size" |
284 | 291 | ], |
285 | | - "execution_count": null, |
| 292 | + "execution_count": 6, |
286 | 293 | "outputs": [ |
287 | 294 | { |
288 | 295 | "output_type": "stream", |
289 | 296 | "name": "stderr", |
290 | 297 | "text": [ |
291 | | - "YOLOv5 🚀 0aad3e6 torch 1.10.0+cu111 CUDA:0 (Tesla K80, 11441MiB)\n", |
| 298 | + "YOLOv5 🚀 5e43ba7 torch 1.10.0+cu111 CUDA:0 (Tesla K80, 11441MiB)\n", |
292 | 299 | "\n", |
293 | | - "Fusing layers... \n", |
| 300 | + "Fusing layers... \n" |
| 301 | + ] |
| 302 | + }, |
| 303 | + { |
| 304 | + "output_type": "stream", |
| 305 | + "name": "stdout", |
| 306 | + "text": [ |
| 307 | + "Epoch: 93\n", |
| 308 | + "Val mAP: [ 0.54181]\n" |
| 309 | + ] |
| 310 | + }, |
| 311 | + { |
| 312 | + "output_type": "stream", |
| 313 | + "name": "stderr", |
| 314 | + "text": [ |
294 | 315 | "Model Summary: 213 layers, 7037095 parameters, 0 gradients, 15.9 GFLOPs\n" |
295 | 316 | ] |
296 | 317 | } |
|
312 | 333 | "base_uri": "https://localhost:8080/" |
313 | 334 | }, |
314 | 335 | "id": "4NBSSYW_qlqt", |
315 | | - "outputId": "ea98267b-972e-4ee8-8391-839af2cb7634" |
| 336 | + "outputId": "19666be4-7d29-4f1b-8089-a7e7efd196f0" |
316 | 337 | }, |
317 | 338 | "source": [ |
318 | 339 | "# 1. Download the testing data\n", |
|
326 | 347 | "bs = 1 # batch_size\n", |
327 | 348 | "print(f\"Test data size: {len(dataset)}\")" |
328 | 349 | ], |
329 | | - "execution_count": null, |
| 350 | + "execution_count": 7, |
330 | 351 | "outputs": [ |
331 | 352 | { |
332 | 353 | "output_type": "stream", |
|
355 | 376 | "base_uri": "https://localhost:8080/" |
356 | 377 | }, |
357 | 378 | "id": "rm_swqoBr6OJ", |
358 | | - "outputId": "ba3079f1-7567-4e12-bd56-6870f1223ad6" |
| 379 | + "outputId": "9154b8e6-9469-422d-9896-cfabfce86599" |
359 | 380 | }, |
360 | 381 | "source": [ |
361 | 382 | "# Test your inference time\n", |
|
397 | 418 | "end_time = time.time()\n", |
398 | 419 | "print(\"\\nInference time per image: \", (end_time - start_time) / TEST_IMAGE_NUMBER)" |
399 | 420 | ], |
400 | | - "execution_count": null, |
| 421 | + "execution_count": 8, |
401 | 422 | "outputs": [ |
402 | 423 | { |
403 | 424 | "output_type": "stream", |
404 | 425 | "name": "stdout", |
405 | 426 | "text": [ |
406 | 427 | "\n", |
407 | | - "Inference time per image: 0.02215820550918579\n" |
| 428 | + "Inference time per image: 0.022769753932952882\n" |
408 | 429 | ] |
409 | 430 | } |
410 | 431 | ] |
|
0 commit comments