You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tutorial.ipynb 46KB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
Merge `develop` branch into `master` (#3518) * update ci-testing.yml (#3322) * update ci-testing.yml * update greetings.yml * bring back os matrix * update ci-testing.yml (#3322) * update ci-testing.yml * update greetings.yml * bring back os matrix * Enable direct `--weights URL` definition (#3373) * Enable direct `--weights URL` definition @KalenMike this PR will enable direct --weights URL definition. Example use case: ``` python train.py --weights https://storage.googleapis.com/bucket/dir/model.pt ``` * cleanup * bug fixes * weights = attempt_download(weights) * Update experimental.py * Update hubconf.py * return bug fix * comment mirror * min_bytes * Update tutorial.ipynb (#3368) add Open in Kaggle badge * `cv2.imread(img, -1)` for IMREAD_UNCHANGED (#3379) * Update datasets.py * comment Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> * COCO evolution fix (#3388) * COCO evolution fix * cleanup * update print * print fix * Create `is_pip()` function (#3391) Returns `True` if file is part of pip package. Useful for contextual behavior modification. ```python def is_pip(): # Is file in a pip package? return 'site-packages' in Path(__file__).absolute().parts ``` * Revert "`cv2.imread(img, -1)` for IMREAD_UNCHANGED (#3379)" (#3395) This reverts commit 21a9607e00f1365b21d8c4bd81bdbf5fc0efea24. * Update FLOPs description (#3422) * Update README.md * Changing FLOPS to FLOPs. Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> * Parse URL authentication (#3424) * Parse URL authentication * urllib.parse.unquote() * improved error handling * improved error handling * remove %3F * update check_file() * Add FLOPs title to table (#3453) * Suppress jit trace warning + graph once (#3454) * Suppress jit trace warning + graph once Suppress harmless jit trace warning on TensorBoard add_graph call. Also fix multiple add_graph() calls bug, now only on batch 0. * Update train.py * Update MixUp augmentation `alpha=beta=32.0` (#3455) Per VOC empirical results https://github.com/ultralytics/yolov5/issues/3380#issuecomment-853001307 by @developer0hye * Add `timeout()` class (#3460) * Add `timeout()` class * rearrange order * Faster HSV augmentation (#3462) remove datatype conversion process that can be skipped * Add `check_git_status()` 5 second timeout (#3464) * Add check_git_status() 5 second timeout This should prevent the SSH Git bug that we were discussing @KalenMike * cleanup * replace timeout with check_output built-in timeout * Improved `check_requirements()` offline-handling (#3466) Improve robustness of `check_requirements()` function to offline environments (do not attempt pip installs when offline). * Add `output_names` argument for ONNX export with dynamic axes (#3456) * Add output names & dynamic axes for onnx export Add output_names and dynamic_axes names for all outputs in torch.onnx.export. The first four outputs of the model will have names output0, output1, output2, output3 * use first output only + cleanup Co-authored-by: Samridha Shrestha <samridha.shrestha@g42.ai> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> * Revert FP16 `test.py` and `detect.py` inference to FP32 default (#3423) * fixed inference bug ,while use half precision * replace --use-half with --half * replace space and PEP8 in detect.py * PEP8 detect.py * update --half help comment * Update test.py * revert space Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> * Add additional links/resources to stale.yml message (#3467) * Update stale.yml * cleanup * Update stale.yml * reformat * Update stale.yml HUB URL (#3468) * Stale `github.actor` bug fix (#3483) * Explicit `model.eval()` call `if opt.train=False` (#3475) * call model.eval() when opt.train is False call model.eval() when opt.train is False * single-line if statement * cleanup Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> * check_requirements() exclude `opencv-python` (#3495) Fix for 3rd party or contrib versions of installed OpenCV as in https://github.com/ultralytics/yolov5/issues/3494. * Earlier `assert` for cpu and half option (#3508) * early assert for cpu and half option early assert for cpu and half option * Modified comment Modified comment * Update tutorial.ipynb (#3510) * Reduce test.py results spacing (#3511) * Update README.md (#3512) * Update README.md Minor modifications * 850 width * Update greetings.yml revert greeting change as PRs will now merge to master. Co-authored-by: Piotr Skalski <SkalskiP@users.noreply.github.com> Co-authored-by: SkalskiP <piotr.skalski92@gmail.com> Co-authored-by: Peretz Cohen <pizzaz93@users.noreply.github.com> Co-authored-by: tudoulei <34886368+tudoulei@users.noreply.github.com> Co-authored-by: chocosaj <chocosaj@users.noreply.github.com> Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> Co-authored-by: Yonghye Kwon <developer.0hye@gmail.com> Co-authored-by: Sam_S <SamSamhuns@users.noreply.github.com> Co-authored-by: Samridha Shrestha <samridha.shrestha@g42.ai> Co-authored-by: edificewang <609552430@qq.com>
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
Merge `develop` branch into `master` (#3518) * update ci-testing.yml (#3322) * update ci-testing.yml * update greetings.yml * bring back os matrix * update ci-testing.yml (#3322) * update ci-testing.yml * update greetings.yml * bring back os matrix * Enable direct `--weights URL` definition (#3373) * Enable direct `--weights URL` definition @KalenMike this PR will enable direct --weights URL definition. Example use case: ``` python train.py --weights https://storage.googleapis.com/bucket/dir/model.pt ``` * cleanup * bug fixes * weights = attempt_download(weights) * Update experimental.py * Update hubconf.py * return bug fix * comment mirror * min_bytes * Update tutorial.ipynb (#3368) add Open in Kaggle badge * `cv2.imread(img, -1)` for IMREAD_UNCHANGED (#3379) * Update datasets.py * comment Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> * COCO evolution fix (#3388) * COCO evolution fix * cleanup * update print * print fix * Create `is_pip()` function (#3391) Returns `True` if file is part of pip package. Useful for contextual behavior modification. ```python def is_pip(): # Is file in a pip package? return 'site-packages' in Path(__file__).absolute().parts ``` * Revert "`cv2.imread(img, -1)` for IMREAD_UNCHANGED (#3379)" (#3395) This reverts commit 21a9607e00f1365b21d8c4bd81bdbf5fc0efea24. * Update FLOPs description (#3422) * Update README.md * Changing FLOPS to FLOPs. Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> * Parse URL authentication (#3424) * Parse URL authentication * urllib.parse.unquote() * improved error handling * improved error handling * remove %3F * update check_file() * Add FLOPs title to table (#3453) * Suppress jit trace warning + graph once (#3454) * Suppress jit trace warning + graph once Suppress harmless jit trace warning on TensorBoard add_graph call. Also fix multiple add_graph() calls bug, now only on batch 0. * Update train.py * Update MixUp augmentation `alpha=beta=32.0` (#3455) Per VOC empirical results https://github.com/ultralytics/yolov5/issues/3380#issuecomment-853001307 by @developer0hye * Add `timeout()` class (#3460) * Add `timeout()` class * rearrange order * Faster HSV augmentation (#3462) remove datatype conversion process that can be skipped * Add `check_git_status()` 5 second timeout (#3464) * Add check_git_status() 5 second timeout This should prevent the SSH Git bug that we were discussing @KalenMike * cleanup * replace timeout with check_output built-in timeout * Improved `check_requirements()` offline-handling (#3466) Improve robustness of `check_requirements()` function to offline environments (do not attempt pip installs when offline). * Add `output_names` argument for ONNX export with dynamic axes (#3456) * Add output names & dynamic axes for onnx export Add output_names and dynamic_axes names for all outputs in torch.onnx.export. The first four outputs of the model will have names output0, output1, output2, output3 * use first output only + cleanup Co-authored-by: Samridha Shrestha <samridha.shrestha@g42.ai> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> * Revert FP16 `test.py` and `detect.py` inference to FP32 default (#3423) * fixed inference bug ,while use half precision * replace --use-half with --half * replace space and PEP8 in detect.py * PEP8 detect.py * update --half help comment * Update test.py * revert space Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> * Add additional links/resources to stale.yml message (#3467) * Update stale.yml * cleanup * Update stale.yml * reformat * Update stale.yml HUB URL (#3468) * Stale `github.actor` bug fix (#3483) * Explicit `model.eval()` call `if opt.train=False` (#3475) * call model.eval() when opt.train is False call model.eval() when opt.train is False * single-line if statement * cleanup Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com> * check_requirements() exclude `opencv-python` (#3495) Fix for 3rd party or contrib versions of installed OpenCV as in https://github.com/ultralytics/yolov5/issues/3494. * Earlier `assert` for cpu and half option (#3508) * early assert for cpu and half option early assert for cpu and half option * Modified comment Modified comment * Update tutorial.ipynb (#3510) * Reduce test.py results spacing (#3511) * Update README.md (#3512) * Update README.md Minor modifications * 850 width * Update greetings.yml revert greeting change as PRs will now merge to master. Co-authored-by: Piotr Skalski <SkalskiP@users.noreply.github.com> Co-authored-by: SkalskiP <piotr.skalski92@gmail.com> Co-authored-by: Peretz Cohen <pizzaz93@users.noreply.github.com> Co-authored-by: tudoulei <34886368+tudoulei@users.noreply.github.com> Co-authored-by: chocosaj <chocosaj@users.noreply.github.com> Co-authored-by: BuildTools <unconfigured@null.spigotmc.org> Co-authored-by: Yonghye Kwon <developer.0hye@gmail.com> Co-authored-by: Sam_S <SamSamhuns@users.noreply.github.com> Co-authored-by: Samridha Shrestha <samridha.shrestha@g42.ai> Co-authored-by: edificewang <609552430@qq.com>
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. {
  2. "nbformat": 4,
  3. "nbformat_minor": 0,
  4. "metadata": {
  5. "colab": {
  6. "name": "YOLOv5 Tutorial",
  7. "provenance": [],
  8. "collapsed_sections": [],
  9. "include_colab_link": true
  10. },
  11. "kernelspec": {
  12. "name": "python3",
  13. "display_name": "Python 3"
  14. },
  15. "accelerator": "GPU",
  16. "widgets": {
  17. "application/vnd.jupyter.widget-state+json": {
  18. "484511f272e64eab8b42e68dac5f7a66": {
  19. "model_module": "@jupyter-widgets/controls",
  20. "model_name": "HBoxModel",
  21. "model_module_version": "1.5.0",
  22. "state": {
  23. "_view_name": "HBoxView",
  24. "_dom_classes": [],
  25. "_model_name": "HBoxModel",
  26. "_view_module": "@jupyter-widgets/controls",
  27. "_model_module_version": "1.5.0",
  28. "_view_count": null,
  29. "_view_module_version": "1.5.0",
  30. "box_style": "",
  31. "layout": "IPY_MODEL_78cceec059784f2bb36988d3336e4d56",
  32. "_model_module": "@jupyter-widgets/controls",
  33. "children": [
  34. "IPY_MODEL_ab93d8b65c134605934ff9ec5efb1bb6",
  35. "IPY_MODEL_30df865ded4c434191bce772c9a82f3a",
  36. "IPY_MODEL_20cdc61eb3404f42a12b37901b0d85fb"
  37. ]
  38. }
  39. },
  40. "78cceec059784f2bb36988d3336e4d56": {
  41. "model_module": "@jupyter-widgets/base",
  42. "model_name": "LayoutModel",
  43. "model_module_version": "1.2.0",
  44. "state": {
  45. "_view_name": "LayoutView",
  46. "grid_template_rows": null,
  47. "right": null,
  48. "justify_content": null,
  49. "_view_module": "@jupyter-widgets/base",
  50. "overflow": null,
  51. "_model_module_version": "1.2.0",
  52. "_view_count": null,
  53. "flex_flow": null,
  54. "width": null,
  55. "min_width": null,
  56. "border": null,
  57. "align_items": null,
  58. "bottom": null,
  59. "_model_module": "@jupyter-widgets/base",
  60. "top": null,
  61. "grid_column": null,
  62. "overflow_y": null,
  63. "overflow_x": null,
  64. "grid_auto_flow": null,
  65. "grid_area": null,
  66. "grid_template_columns": null,
  67. "flex": null,
  68. "_model_name": "LayoutModel",
  69. "justify_items": null,
  70. "grid_row": null,
  71. "max_height": null,
  72. "align_content": null,
  73. "visibility": null,
  74. "align_self": null,
  75. "height": null,
  76. "min_height": null,
  77. "padding": null,
  78. "grid_auto_rows": null,
  79. "grid_gap": null,
  80. "max_width": null,
  81. "order": null,
  82. "_view_module_version": "1.2.0",
  83. "grid_template_areas": null,
  84. "object_position": null,
  85. "object_fit": null,
  86. "grid_auto_columns": null,
  87. "margin": null,
  88. "display": null,
  89. "left": null
  90. }
  91. },
  92. "ab93d8b65c134605934ff9ec5efb1bb6": {
  93. "model_module": "@jupyter-widgets/controls",
  94. "model_name": "HTMLModel",
  95. "model_module_version": "1.5.0",
  96. "state": {
  97. "_view_name": "HTMLView",
  98. "style": "IPY_MODEL_2d7239993a9645b09b221405ac682743",
  99. "_dom_classes": [],
  100. "description": "",
  101. "_model_name": "HTMLModel",
  102. "placeholder": "​",
  103. "_view_module": "@jupyter-widgets/controls",
  104. "_model_module_version": "1.5.0",
  105. "value": "100%",
  106. "_view_count": null,
  107. "_view_module_version": "1.5.0",
  108. "description_tooltip": null,
  109. "_model_module": "@jupyter-widgets/controls",
  110. "layout": "IPY_MODEL_17b5a87f92104ec7ab96bf507637d0d2"
  111. }
  112. },
  113. "30df865ded4c434191bce772c9a82f3a": {
  114. "model_module": "@jupyter-widgets/controls",
  115. "model_name": "FloatProgressModel",
  116. "model_module_version": "1.5.0",
  117. "state": {
  118. "_view_name": "ProgressView",
  119. "style": "IPY_MODEL_2358bfb2270247359e94b066b3cc3d1f",
  120. "_dom_classes": [],
  121. "description": "",
  122. "_model_name": "FloatProgressModel",
  123. "bar_style": "success",
  124. "max": 818322941,
  125. "_view_module": "@jupyter-widgets/controls",
  126. "_model_module_version": "1.5.0",
  127. "value": 818322941,
  128. "_view_count": null,
  129. "_view_module_version": "1.5.0",
  130. "orientation": "horizontal",
  131. "min": 0,
  132. "description_tooltip": null,
  133. "_model_module": "@jupyter-widgets/controls",
  134. "layout": "IPY_MODEL_3e984405db654b0b83b88b2db08baffd"
  135. }
  136. },
  137. "20cdc61eb3404f42a12b37901b0d85fb": {
  138. "model_module": "@jupyter-widgets/controls",
  139. "model_name": "HTMLModel",
  140. "model_module_version": "1.5.0",
  141. "state": {
  142. "_view_name": "HTMLView",
  143. "style": "IPY_MODEL_654d8a19b9f949c6bbdaf8b0875c931e",
  144. "_dom_classes": [],
  145. "description": "",
  146. "_model_name": "HTMLModel",
  147. "placeholder": "​",
  148. "_view_module": "@jupyter-widgets/controls",
  149. "_model_module_version": "1.5.0",
  150. "value": " 780M/780M [00:33&lt;00:00, 24.4MB/s]",
  151. "_view_count": null,
  152. "_view_module_version": "1.5.0",
  153. "description_tooltip": null,
  154. "_model_module": "@jupyter-widgets/controls",
  155. "layout": "IPY_MODEL_896030c5d13b415aaa05032818d81a6e"
  156. }
  157. },
  158. "2d7239993a9645b09b221405ac682743": {
  159. "model_module": "@jupyter-widgets/controls",
  160. "model_name": "DescriptionStyleModel",
  161. "model_module_version": "1.5.0",
  162. "state": {
  163. "_view_name": "StyleView",
  164. "_model_name": "DescriptionStyleModel",
  165. "description_width": "",
  166. "_view_module": "@jupyter-widgets/base",
  167. "_model_module_version": "1.5.0",
  168. "_view_count": null,
  169. "_view_module_version": "1.2.0",
  170. "_model_module": "@jupyter-widgets/controls"
  171. }
  172. },
  173. "17b5a87f92104ec7ab96bf507637d0d2": {
  174. "model_module": "@jupyter-widgets/base",
  175. "model_name": "LayoutModel",
  176. "model_module_version": "1.2.0",
  177. "state": {
  178. "_view_name": "LayoutView",
  179. "grid_template_rows": null,
  180. "right": null,
  181. "justify_content": null,
  182. "_view_module": "@jupyter-widgets/base",
  183. "overflow": null,
  184. "_model_module_version": "1.2.0",
  185. "_view_count": null,
  186. "flex_flow": null,
  187. "width": null,
  188. "min_width": null,
  189. "border": null,
  190. "align_items": null,
  191. "bottom": null,
  192. "_model_module": "@jupyter-widgets/base",
  193. "top": null,
  194. "grid_column": null,
  195. "overflow_y": null,
  196. "overflow_x": null,
  197. "grid_auto_flow": null,
  198. "grid_area": null,
  199. "grid_template_columns": null,
  200. "flex": null,
  201. "_model_name": "LayoutModel",
  202. "justify_items": null,
  203. "grid_row": null,
  204. "max_height": null,
  205. "align_content": null,
  206. "visibility": null,
  207. "align_self": null,
  208. "height": null,
  209. "min_height": null,
  210. "padding": null,
  211. "grid_auto_rows": null,
  212. "grid_gap": null,
  213. "max_width": null,
  214. "order": null,
  215. "_view_module_version": "1.2.0",
  216. "grid_template_areas": null,
  217. "object_position": null,
  218. "object_fit": null,
  219. "grid_auto_columns": null,
  220. "margin": null,
  221. "display": null,
  222. "left": null
  223. }
  224. },
  225. "2358bfb2270247359e94b066b3cc3d1f": {
  226. "model_module": "@jupyter-widgets/controls",
  227. "model_name": "ProgressStyleModel",
  228. "model_module_version": "1.5.0",
  229. "state": {
  230. "_view_name": "StyleView",
  231. "_model_name": "ProgressStyleModel",
  232. "description_width": "",
  233. "_view_module": "@jupyter-widgets/base",
  234. "_model_module_version": "1.5.0",
  235. "_view_count": null,
  236. "_view_module_version": "1.2.0",
  237. "bar_color": null,
  238. "_model_module": "@jupyter-widgets/controls"
  239. }
  240. },
  241. "3e984405db654b0b83b88b2db08baffd": {
  242. "model_module": "@jupyter-widgets/base",
  243. "model_name": "LayoutModel",
  244. "model_module_version": "1.2.0",
  245. "state": {
  246. "_view_name": "LayoutView",
  247. "grid_template_rows": null,
  248. "right": null,
  249. "justify_content": null,
  250. "_view_module": "@jupyter-widgets/base",
  251. "overflow": null,
  252. "_model_module_version": "1.2.0",
  253. "_view_count": null,
  254. "flex_flow": null,
  255. "width": null,
  256. "min_width": null,
  257. "border": null,
  258. "align_items": null,
  259. "bottom": null,
  260. "_model_module": "@jupyter-widgets/base",
  261. "top": null,
  262. "grid_column": null,
  263. "overflow_y": null,
  264. "overflow_x": null,
  265. "grid_auto_flow": null,
  266. "grid_area": null,
  267. "grid_template_columns": null,
  268. "flex": null,
  269. "_model_name": "LayoutModel",
  270. "justify_items": null,
  271. "grid_row": null,
  272. "max_height": null,
  273. "align_content": null,
  274. "visibility": null,
  275. "align_self": null,
  276. "height": null,
  277. "min_height": null,
  278. "padding": null,
  279. "grid_auto_rows": null,
  280. "grid_gap": null,
  281. "max_width": null,
  282. "order": null,
  283. "_view_module_version": "1.2.0",
  284. "grid_template_areas": null,
  285. "object_position": null,
  286. "object_fit": null,
  287. "grid_auto_columns": null,
  288. "margin": null,
  289. "display": null,
  290. "left": null
  291. }
  292. },
  293. "654d8a19b9f949c6bbdaf8b0875c931e": {
  294. "model_module": "@jupyter-widgets/controls",
  295. "model_name": "DescriptionStyleModel",
  296. "model_module_version": "1.5.0",
  297. "state": {
  298. "_view_name": "StyleView",
  299. "_model_name": "DescriptionStyleModel",
  300. "description_width": "",
  301. "_view_module": "@jupyter-widgets/base",
  302. "_model_module_version": "1.5.0",
  303. "_view_count": null,
  304. "_view_module_version": "1.2.0",
  305. "_model_module": "@jupyter-widgets/controls"
  306. }
  307. },
  308. "896030c5d13b415aaa05032818d81a6e": {
  309. "model_module": "@jupyter-widgets/base",
  310. "model_name": "LayoutModel",
  311. "model_module_version": "1.2.0",
  312. "state": {
  313. "_view_name": "LayoutView",
  314. "grid_template_rows": null,
  315. "right": null,
  316. "justify_content": null,
  317. "_view_module": "@jupyter-widgets/base",
  318. "overflow": null,
  319. "_model_module_version": "1.2.0",
  320. "_view_count": null,
  321. "flex_flow": null,
  322. "width": null,
  323. "min_width": null,
  324. "border": null,
  325. "align_items": null,
  326. "bottom": null,
  327. "_model_module": "@jupyter-widgets/base",
  328. "top": null,
  329. "grid_column": null,
  330. "overflow_y": null,
  331. "overflow_x": null,
  332. "grid_auto_flow": null,
  333. "grid_area": null,
  334. "grid_template_columns": null,
  335. "flex": null,
  336. "_model_name": "LayoutModel",
  337. "justify_items": null,
  338. "grid_row": null,
  339. "max_height": null,
  340. "align_content": null,
  341. "visibility": null,
  342. "align_self": null,
  343. "height": null,
  344. "min_height": null,
  345. "padding": null,
  346. "grid_auto_rows": null,
  347. "grid_gap": null,
  348. "max_width": null,
  349. "order": null,
  350. "_view_module_version": "1.2.0",
  351. "grid_template_areas": null,
  352. "object_position": null,
  353. "object_fit": null,
  354. "grid_auto_columns": null,
  355. "margin": null,
  356. "display": null,
  357. "left": null
  358. }
  359. }
  360. }
  361. }
  362. },
  363. "cells": [
  364. {
  365. "cell_type": "markdown",
  366. "metadata": {
  367. "id": "view-in-github",
  368. "colab_type": "text"
  369. },
  370. "source": [
  371. "<a href=\"https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
  372. ]
  373. },
  374. {
  375. "cell_type": "markdown",
  376. "metadata": {
  377. "id": "t6MPjfT5NrKQ"
  378. },
  379. "source": [
  380. "<a align=\"left\" href=\"https://ultralytics.com/yolov5\" target=\"_blank\">\n",
  381. "<img src=\"https://user-images.githubusercontent.com/26833433/125273437-35b3fc00-e30d-11eb-9079-46f313325424.png\"></a>\n",
  382. "\n",
  383. "This is the **official YOLOv5 🚀 notebook** by **Ultralytics**, and is freely available for redistribution under the [GPL-3.0 license](https://choosealicense.com/licenses/gpl-3.0/). \n",
  384. "For more information please visit https://github.com/ultralytics/yolov5 and https://ultralytics.com. Thank you!"
  385. ]
  386. },
  387. {
  388. "cell_type": "markdown",
  389. "metadata": {
  390. "id": "7mGmQbAO5pQb"
  391. },
  392. "source": [
  393. "# Setup\n",
  394. "\n",
  395. "Clone repo, install dependencies and check PyTorch and GPU."
  396. ]
  397. },
  398. {
  399. "cell_type": "code",
  400. "metadata": {
  401. "id": "wbvMlHd_QwMG",
  402. "colab": {
  403. "base_uri": "https://localhost:8080/"
  404. },
  405. "outputId": "4d67116a-43e9-4d84-d19e-1edd83f23a04"
  406. },
  407. "source": [
  408. "!git clone https://github.com/ultralytics/yolov5 # clone repo\n",
  409. "%cd yolov5\n",
  410. "%pip install -qr requirements.txt # install dependencies\n",
  411. "\n",
  412. "import torch\n",
  413. "from IPython.display import Image, clear_output # to display images\n",
  414. "\n",
  415. "clear_output()\n",
  416. "print(f\"Setup complete. Using torch {torch.__version__} ({torch.cuda.get_device_properties(0).name if torch.cuda.is_available() else 'CPU'})\")"
  417. ],
  418. "execution_count": null,
  419. "outputs": [
  420. {
  421. "output_type": "stream",
  422. "text": [
  423. "Setup complete. Using torch 1.9.0+cu102 (Tesla V100-SXM2-16GB)\n"
  424. ],
  425. "name": "stdout"
  426. }
  427. ]
  428. },
  429. {
  430. "cell_type": "markdown",
  431. "metadata": {
  432. "id": "4JnkELT0cIJg"
  433. },
  434. "source": [
  435. "# 1. Inference\n",
  436. "\n",
  437. "`detect.py` runs YOLOv5 inference on a variety of sources, downloading models automatically from the [latest YOLOv5 release](https://github.com/ultralytics/yolov5/releases), and saving results to `runs/detect`. Example inference sources are:\n",
  438. "\n",
  439. "```shell\n",
  440. "python detect.py --source 0 # webcam\n",
  441. " file.jpg # image \n",
  442. " file.mp4 # video\n",
  443. " path/ # directory\n",
  444. " path/*.jpg # glob\n",
  445. " 'https://youtu.be/NUsoVlDFqZg' # YouTube\n",
  446. " 'rtsp://example.com/media.mp4' # RTSP, RTMP, HTTP stream\n",
  447. "```"
  448. ]
  449. },
  450. {
  451. "cell_type": "code",
  452. "metadata": {
  453. "id": "zR9ZbuQCH7FX",
  454. "colab": {
  455. "base_uri": "https://localhost:8080/"
  456. },
  457. "outputId": "8b728908-81ab-4861-edb0-4d0c46c439fb"
  458. },
  459. "source": [
  460. "%rm -rf runs\n",
  461. "!python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images/\n",
  462. "#Image(filename='runs/detect/exp/zidane.jpg', width=600)"
  463. ],
  464. "execution_count": null,
  465. "outputs": [
  466. {
  467. "output_type": "stream",
  468. "text": [
  469. "\u001b[34m\u001b[1mdetect: \u001b[0mweights=['yolov5s.pt'], source=data/images/, imgsz=640, conf_thres=0.25, iou_thres=0.45, max_det=1000, device=, view_img=False, save_txt=False, save_conf=False, save_crop=False, nosave=False, classes=None, agnostic_nms=False, augment=False, visualize=False, update=False, project=runs/detect, name=exp, exist_ok=False, line_thickness=3, hide_labels=False, hide_conf=False, half=False\n",
  470. "YOLOv5 🚀 v5.0-367-g01cdb76 torch 1.9.0+cu102 CUDA:0 (Tesla V100-SXM2-16GB, 16160.5MB)\n",
  471. "\n",
  472. "Fusing layers... \n",
  473. "Model Summary: 224 layers, 7266973 parameters, 0 gradients\n",
  474. "image 1/2 /content/yolov5/data/images/bus.jpg: 640x480 4 persons, 1 bus, 1 fire hydrant, Done. (0.007s)\n",
  475. "image 2/2 /content/yolov5/data/images/zidane.jpg: 384x640 2 persons, 2 ties, Done. (0.007s)\n",
  476. "Results saved to \u001b[1mruns/detect/exp\u001b[0m\n",
  477. "Done. (0.091s)\n"
  478. ],
  479. "name": "stdout"
  480. }
  481. ]
  482. },
  483. {
  484. "cell_type": "markdown",
  485. "metadata": {
  486. "id": "hkAzDWJ7cWTr"
  487. },
  488. "source": [
  489. "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n",
  490. "<img align=\"left\" src=\"https://user-images.githubusercontent.com/26833433/127574988-6a558aa1-d268-44b9-bf6b-62d4c605cc72.jpg\" width=\"600\">"
  491. ]
  492. },
  493. {
  494. "cell_type": "markdown",
  495. "metadata": {
  496. "id": "0eq1SMWl6Sfn"
  497. },
  498. "source": [
  499. "# 2. Validate\n",
  500. "Validate a model's accuracy on [COCO](https://cocodataset.org/#home) val or test-dev datasets. Models are downloaded automatically from the [latest YOLOv5 release](https://github.com/ultralytics/yolov5/releases). To show results by class use the `--verbose` flag. Note that `pycocotools` metrics may be ~1% better than the equivalent repo metrics, as is visible below, due to slight differences in mAP computation."
  501. ]
  502. },
  503. {
  504. "cell_type": "markdown",
  505. "metadata": {
  506. "id": "eyTZYGgRjnMc"
  507. },
  508. "source": [
  509. "## COCO val2017\n",
  510. "Download [COCO val 2017](https://github.com/ultralytics/yolov5/blob/74b34872fdf41941cddcf243951cdb090fbac17b/data/coco.yaml#L14) dataset (1GB - 5000 images), and test model accuracy."
  511. ]
  512. },
  513. {
  514. "cell_type": "code",
  515. "metadata": {
  516. "id": "WQPtK1QYVaD_",
  517. "colab": {
  518. "base_uri": "https://localhost:8080/",
  519. "height": 48,
  520. "referenced_widgets": [
  521. "484511f272e64eab8b42e68dac5f7a66",
  522. "78cceec059784f2bb36988d3336e4d56",
  523. "ab93d8b65c134605934ff9ec5efb1bb6",
  524. "30df865ded4c434191bce772c9a82f3a",
  525. "20cdc61eb3404f42a12b37901b0d85fb",
  526. "2d7239993a9645b09b221405ac682743",
  527. "17b5a87f92104ec7ab96bf507637d0d2",
  528. "2358bfb2270247359e94b066b3cc3d1f",
  529. "3e984405db654b0b83b88b2db08baffd",
  530. "654d8a19b9f949c6bbdaf8b0875c931e",
  531. "896030c5d13b415aaa05032818d81a6e"
  532. ]
  533. },
  534. "outputId": "7e6f5c96-c819-43e1-cd03-d3b9878cf8de"
  535. },
  536. "source": [
  537. "# Download COCO val2017\n",
  538. "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017val.zip', 'tmp.zip')\n",
  539. "!unzip -q tmp.zip -d ../datasets && rm tmp.zip"
  540. ],
  541. "execution_count": null,
  542. "outputs": [
  543. {
  544. "output_type": "display_data",
  545. "data": {
  546. "application/vnd.jupyter.widget-view+json": {
  547. "model_id": "484511f272e64eab8b42e68dac5f7a66",
  548. "version_minor": 0,
  549. "version_major": 2
  550. },
  551. "text/plain": [
  552. " 0%| | 0.00/780M [00:00<?, ?B/s]"
  553. ]
  554. },
  555. "metadata": {
  556. "tags": []
  557. }
  558. }
  559. ]
  560. },
  561. {
  562. "cell_type": "code",
  563. "metadata": {
  564. "id": "X58w8JLpMnjH",
  565. "colab": {
  566. "base_uri": "https://localhost:8080/"
  567. },
  568. "outputId": "3dd0e2fc-aecf-4108-91b1-6392da1863cb"
  569. },
  570. "source": [
  571. "# Run YOLOv5x on COCO val2017\n",
  572. "!python val.py --weights yolov5x.pt --data coco.yaml --img 640 --iou 0.65 --half"
  573. ],
  574. "execution_count": null,
  575. "outputs": [
  576. {
  577. "output_type": "stream",
  578. "text": [
  579. "\u001b[34m\u001b[1mval: \u001b[0mdata=./data/coco.yaml, weights=['yolov5x.pt'], batch_size=32, imgsz=640, conf_thres=0.001, iou_thres=0.65, task=val, device=, single_cls=False, augment=False, verbose=False, save_txt=False, save_hybrid=False, save_conf=False, save_json=True, project=runs/val, name=exp, exist_ok=False, half=True\n",
  580. "YOLOv5 🚀 v5.0-367-g01cdb76 torch 1.9.0+cu102 CUDA:0 (Tesla V100-SXM2-16GB, 16160.5MB)\n",
  581. "\n",
  582. "Downloading https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5x.pt to yolov5x.pt...\n",
  583. "100% 168M/168M [00:08<00:00, 20.6MB/s]\n",
  584. "\n",
  585. "Fusing layers... \n",
  586. "Model Summary: 476 layers, 87730285 parameters, 0 gradients\n",
  587. "\u001b[34m\u001b[1mval: \u001b[0mScanning '../datasets/coco/val2017' images and labels...4952 found, 48 missing, 0 empty, 0 corrupted: 100% 5000/5000 [00:01<00:00, 2749.96it/s]\n",
  588. "\u001b[34m\u001b[1mval: \u001b[0mNew cache created: ../datasets/coco/val2017.cache\n",
  589. " Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 157/157 [01:08<00:00, 2.28it/s]\n",
  590. " all 5000 36335 0.746 0.626 0.68 0.49\n",
  591. "Speed: 0.1ms pre-process, 5.1ms inference, 1.6ms NMS per image at shape (32, 3, 640, 640)\n",
  592. "\n",
  593. "Evaluating pycocotools mAP... saving runs/val/exp/yolov5x_predictions.json...\n",
  594. "loading annotations into memory...\n",
  595. "Done (t=0.46s)\n",
  596. "creating index...\n",
  597. "index created!\n",
  598. "Loading and preparing results...\n",
  599. "DONE (t=4.94s)\n",
  600. "creating index...\n",
  601. "index created!\n",
  602. "Running per image evaluation...\n",
  603. "Evaluate annotation type *bbox*\n",
  604. "DONE (t=83.60s).\n",
  605. "Accumulating evaluation results...\n",
  606. "DONE (t=13.22s).\n",
  607. " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.504\n",
  608. " Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.688\n",
  609. " Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.546\n",
  610. " Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.351\n",
  611. " Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.551\n",
  612. " Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.644\n",
  613. " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.382\n",
  614. " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.629\n",
  615. " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.681\n",
  616. " Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.524\n",
  617. " Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.735\n",
  618. " Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.827\n",
  619. "Results saved to \u001b[1mruns/val/exp\u001b[0m\n"
  620. ],
  621. "name": "stdout"
  622. }
  623. ]
  624. },
  625. {
  626. "cell_type": "markdown",
  627. "metadata": {
  628. "id": "rc_KbFk0juX2"
  629. },
  630. "source": [
  631. "## COCO test-dev2017\n",
  632. "Download [COCO test2017](https://github.com/ultralytics/yolov5/blob/74b34872fdf41941cddcf243951cdb090fbac17b/data/coco.yaml#L15) dataset (7GB - 40,000 images), to test model accuracy on test-dev set (**20,000 images, no labels**). Results are saved to a `*.json` file which should be **zipped** and submitted to the evaluation server at https://competitions.codalab.org/competitions/20794."
  633. ]
  634. },
  635. {
  636. "cell_type": "code",
  637. "metadata": {
  638. "id": "V0AJnSeCIHyJ"
  639. },
  640. "source": [
  641. "# Download COCO test-dev2017\n",
  642. "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017labels.zip', 'tmp.zip')\n",
  643. "!unzip -q tmp.zip -d ../ && rm tmp.zip # unzip labels\n",
  644. "!f=\"test2017.zip\" && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f && rm $f # 7GB, 41k images\n",
  645. "%mv ./test2017 ../coco/images # move to /coco"
  646. ],
  647. "execution_count": null,
  648. "outputs": []
  649. },
  650. {
  651. "cell_type": "code",
  652. "metadata": {
  653. "id": "29GJXAP_lPrt"
  654. },
  655. "source": [
  656. "# Run YOLOv5s on COCO test-dev2017 using --task test\n",
  657. "!python val.py --weights yolov5s.pt --data coco.yaml --task test"
  658. ],
  659. "execution_count": null,
  660. "outputs": []
  661. },
  662. {
  663. "cell_type": "markdown",
  664. "metadata": {
  665. "id": "VUOiNLtMP5aG"
  666. },
  667. "source": [
  668. "# 3. Train\n",
  669. "\n",
  670. "Download [COCO128](https://www.kaggle.com/ultralytics/coco128), a small 128-image tutorial dataset, start tensorboard and train YOLOv5s from a pretrained checkpoint for 3 epochs (note actual training is typically much longer, around **300-1000 epochs**, depending on your dataset)."
  671. ]
  672. },
  673. {
  674. "cell_type": "code",
  675. "metadata": {
  676. "id": "Knxi2ncxWffW"
  677. },
  678. "source": [
  679. "# Download COCO128\n",
  680. "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip', 'tmp.zip')\n",
  681. "!unzip -q tmp.zip -d ../datasets && rm tmp.zip"
  682. ],
  683. "execution_count": null,
  684. "outputs": []
  685. },
  686. {
  687. "cell_type": "markdown",
  688. "metadata": {
  689. "id": "_pOkGLv1dMqh"
  690. },
  691. "source": [
  692. "Train a YOLOv5s model on [COCO128](https://www.kaggle.com/ultralytics/coco128) with `--data coco128.yaml`, starting from pretrained `--weights yolov5s.pt`, or from randomly initialized `--weights '' --cfg yolov5s.yaml`. Models are downloaded automatically from the [latest YOLOv5 release](https://github.com/ultralytics/yolov5/releases), and **COCO, COCO128, and VOC datasets are downloaded automatically** on first use.\n",
  693. "\n",
  694. "All training results are saved to `runs/train/` with incrementing run directories, i.e. `runs/train/exp2`, `runs/train/exp3` etc.\n"
  695. ]
  696. },
  697. {
  698. "cell_type": "code",
  699. "metadata": {
  700. "id": "bOy5KI2ncnWd"
  701. },
  702. "source": [
  703. "# Tensorboard (optional)\n",
  704. "%load_ext tensorboard\n",
  705. "%tensorboard --logdir runs/train"
  706. ],
  707. "execution_count": null,
  708. "outputs": []
  709. },
  710. {
  711. "cell_type": "code",
  712. "metadata": {
  713. "id": "2fLAV42oNb7M"
  714. },
  715. "source": [
  716. "# Weights & Biases (optional)\n",
  717. "%pip install -q wandb\n",
  718. "import wandb\n",
  719. "wandb.login()"
  720. ],
  721. "execution_count": null,
  722. "outputs": []
  723. },
  724. {
  725. "cell_type": "code",
  726. "metadata": {
  727. "id": "1NcFxRcFdJ_O",
  728. "colab": {
  729. "base_uri": "https://localhost:8080/"
  730. },
  731. "outputId": "00ea4b14-a75c-44a2-a913-03b431b69de5"
  732. },
  733. "source": [
  734. "# Train YOLOv5s on COCO128 for 3 epochs\n",
  735. "!python train.py --img 640 --batch 16 --epochs 3 --data coco128.yaml --weights yolov5s.pt --cache"
  736. ],
  737. "execution_count": null,
  738. "outputs": [
  739. {
  740. "output_type": "stream",
  741. "text": [
  742. "\u001b[34m\u001b[1mtrain: \u001b[0mweights=yolov5s.pt, cfg=, data=coco128.yaml, hyp=data/hyps/hyp.scratch.yaml, epochs=3, batch_size=16, imgsz=640, rect=False, resume=False, nosave=False, noval=False, noautoanchor=False, evolve=None, bucket=, cache=ram, image_weights=False, device=, multi_scale=False, single_cls=False, adam=False, sync_bn=False, workers=8, project=runs/train, entity=None, name=exp, exist_ok=False, quad=False, linear_lr=False, label_smoothing=0.0, upload_dataset=False, bbox_interval=-1, save_period=-1, artifact_alias=latest, local_rank=-1, freeze=0\n",
  743. "\u001b[34m\u001b[1mgithub: \u001b[0mup to date with https://github.com/ultralytics/yolov5 ✅\n",
  744. "YOLOv5 🚀 v5.0-367-g01cdb76 torch 1.9.0+cu102 CUDA:0 (Tesla V100-SXM2-16GB, 16160.5MB)\n",
  745. "\n",
  746. "\u001b[34m\u001b[1mhyperparameters: \u001b[0mlr0=0.01, lrf=0.2, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=0.05, cls=0.5, cls_pw=1.0, obj=1.0, obj_pw=1.0, iou_t=0.2, anchor_t=4.0, fl_gamma=0.0, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0\n",
  747. "\u001b[34m\u001b[1mWeights & Biases: \u001b[0mrun 'pip install wandb' to automatically track and visualize YOLOv5 🚀 runs (RECOMMENDED)\n",
  748. "\u001b[34m\u001b[1mTensorBoard: \u001b[0mStart with 'tensorboard --logdir runs/train', view at http://localhost:6006/\n",
  749. "2021-08-15 14:40:43.449642: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0\n",
  750. "\n",
  751. " from n params module arguments \n",
  752. " 0 -1 1 3520 models.common.Focus [3, 32, 3] \n",
  753. " 1 -1 1 18560 models.common.Conv [32, 64, 3, 2] \n",
  754. " 2 -1 1 18816 models.common.C3 [64, 64, 1] \n",
  755. " 3 -1 1 73984 models.common.Conv [64, 128, 3, 2] \n",
  756. " 4 -1 3 156928 models.common.C3 [128, 128, 3] \n",
  757. " 5 -1 1 295424 models.common.Conv [128, 256, 3, 2] \n",
  758. " 6 -1 3 625152 models.common.C3 [256, 256, 3] \n",
  759. " 7 -1 1 1180672 models.common.Conv [256, 512, 3, 2] \n",
  760. " 8 -1 1 656896 models.common.SPP [512, 512, [5, 9, 13]] \n",
  761. " 9 -1 1 1182720 models.common.C3 [512, 512, 1, False] \n",
  762. " 10 -1 1 131584 models.common.Conv [512, 256, 1, 1] \n",
  763. " 11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
  764. " 12 [-1, 6] 1 0 models.common.Concat [1] \n",
  765. " 13 -1 1 361984 models.common.C3 [512, 256, 1, False] \n",
  766. " 14 -1 1 33024 models.common.Conv [256, 128, 1, 1] \n",
  767. " 15 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
  768. " 16 [-1, 4] 1 0 models.common.Concat [1] \n",
  769. " 17 -1 1 90880 models.common.C3 [256, 128, 1, False] \n",
  770. " 18 -1 1 147712 models.common.Conv [128, 128, 3, 2] \n",
  771. " 19 [-1, 14] 1 0 models.common.Concat [1] \n",
  772. " 20 -1 1 296448 models.common.C3 [256, 256, 1, False] \n",
  773. " 21 -1 1 590336 models.common.Conv [256, 256, 3, 2] \n",
  774. " 22 [-1, 10] 1 0 models.common.Concat [1] \n",
  775. " 23 -1 1 1182720 models.common.C3 [512, 512, 1, False] \n",
  776. " 24 [17, 20, 23] 1 229245 models.yolo.Detect [80, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]]\n",
  777. "Model Summary: 283 layers, 7276605 parameters, 7276605 gradients, 17.1 GFLOPs\n",
  778. "\n",
  779. "Transferred 362/362 items from yolov5s.pt\n",
  780. "Scaled weight_decay = 0.0005\n",
  781. "\u001b[34m\u001b[1moptimizer:\u001b[0m SGD with parameter groups 59 weight, 62 weight (no decay), 62 bias\n",
  782. "\u001b[34m\u001b[1malbumentations: \u001b[0mversion 1.0.3 required by YOLOv5, but version 0.1.12 is currently installed\n",
  783. "\u001b[34m\u001b[1mtrain: \u001b[0mScanning '../datasets/coco128/labels/train2017' images and labels...128 found, 0 missing, 2 empty, 0 corrupted: 100% 128/128 [00:00<00:00, 2440.28it/s]\n",
  784. "\u001b[34m\u001b[1mtrain: \u001b[0mNew cache created: ../datasets/coco128/labels/train2017.cache\n",
  785. "\u001b[34m\u001b[1mtrain: \u001b[0mCaching images (0.1GB ram): 100% 128/128 [00:00<00:00, 302.61it/s]\n",
  786. "\u001b[34m\u001b[1mval: \u001b[0mScanning '../datasets/coco128/labels/train2017.cache' images and labels... 128 found, 0 missing, 2 empty, 0 corrupted: 100% 128/128 [00:00<?, ?it/s]\n",
  787. "\u001b[34m\u001b[1mval: \u001b[0mCaching images (0.1GB ram): 100% 128/128 [00:00<00:00, 142.55it/s]\n",
  788. "[W pthreadpool-cpp.cc:90] Warning: Leaking Caffe2 thread-pool after fork. (function pthreadpool)\n",
  789. "[W pthreadpool-cpp.cc:90] Warning: Leaking Caffe2 thread-pool after fork. (function pthreadpool)\n",
  790. "Plotting labels... \n",
  791. "\n",
  792. "\u001b[34m\u001b[1mautoanchor: \u001b[0mAnalyzing anchors... anchors/target = 4.27, Best Possible Recall (BPR) = 0.9935\n",
  793. "Image sizes 640 train, 640 val\n",
  794. "Using 2 dataloader workers\n",
  795. "Logging results to runs/train/exp\n",
  796. "Starting training for 3 epochs...\n",
  797. "\n",
  798. " Epoch gpu_mem box obj cls labels img_size\n",
  799. " 0/2 3.64G 0.04492 0.0674 0.02213 298 640: 100% 8/8 [00:03<00:00, 2.05it/s]\n",
  800. " Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 4/4 [00:00<00:00, 4.70it/s]\n",
  801. " all 128 929 0.686 0.565 0.642 0.421\n",
  802. "\n",
  803. " Epoch gpu_mem box obj cls labels img_size\n",
  804. " 1/2 5.04G 0.04403 0.0611 0.01986 232 640: 100% 8/8 [00:01<00:00, 5.59it/s]\n",
  805. " Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 4/4 [00:00<00:00, 4.46it/s]\n",
  806. " all 128 929 0.694 0.563 0.654 0.425\n",
  807. "\n",
  808. " Epoch gpu_mem box obj cls labels img_size\n",
  809. " 2/2 5.04G 0.04616 0.07056 0.02071 214 640: 100% 8/8 [00:01<00:00, 5.94it/s]\n",
  810. " Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 4/4 [00:02<00:00, 1.52it/s]\n",
  811. " all 128 929 0.711 0.562 0.66 0.431\n",
  812. "\n",
  813. "3 epochs completed in 0.005 hours.\n",
  814. "Optimizer stripped from runs/train/exp/weights/last.pt, 14.8MB\n",
  815. "Optimizer stripped from runs/train/exp/weights/best.pt, 14.8MB\n",
  816. "Results saved to \u001b[1mruns/train/exp\u001b[0m\n"
  817. ],
  818. "name": "stdout"
  819. }
  820. ]
  821. },
  822. {
  823. "cell_type": "markdown",
  824. "metadata": {
  825. "id": "15glLzbQx5u0"
  826. },
  827. "source": [
  828. "# 4. Visualize"
  829. ]
  830. },
  831. {
  832. "cell_type": "markdown",
  833. "metadata": {
  834. "id": "DLI1JmHU7B0l"
  835. },
  836. "source": [
  837. "## Weights & Biases Logging 🌟 NEW\n",
  838. "\n",
  839. "[Weights & Biases](https://wandb.ai/site?utm_campaign=repo_yolo_notebook) (W&B) is now integrated with YOLOv5 for real-time visualization and cloud logging of training runs. This allows for better run comparison and introspection, as well improved visibility and collaboration for teams. To enable W&B `pip install wandb`, and then train normally (you will be guided through setup on first use). \n",
  840. "\n",
  841. "During training you will see live updates at [https://wandb.ai/home](https://wandb.ai/home?utm_campaign=repo_yolo_notebook), and you can create and share detailed [Reports](https://wandb.ai/glenn-jocher/yolov5_tutorial/reports/YOLOv5-COCO128-Tutorial-Results--VmlldzozMDI5OTY) of your results. For more information see the [YOLOv5 Weights & Biases Tutorial](https://github.com/ultralytics/yolov5/issues/1289). \n",
  842. "\n",
  843. "<img align=\"left\" src=\"https://user-images.githubusercontent.com/26833433/125274843-a27bc600-e30e-11eb-9a44-62af0b7a50a2.png\" width=\"800\">"
  844. ]
  845. },
  846. {
  847. "cell_type": "markdown",
  848. "metadata": {
  849. "id": "-WPvRbS5Swl6"
  850. },
  851. "source": [
  852. "## Local Logging\n",
  853. "\n",
  854. "All results are logged by default to `runs/train`, with a new experiment directory created for each new training as `runs/train/exp2`, `runs/train/exp3`, etc. View train and val jpgs to see mosaics, labels, predictions and augmentation effects. Note an Ultralytics **Mosaic Dataloader** is used for training (shown below), which combines 4 images into 1 mosaic during training.\n",
  855. "\n",
  856. "> <img src=\"https://user-images.githubusercontent.com/26833433/131255960-b536647f-7c61-4f60-bbc5-cb2544d71b2a.jpg\" width=\"700\"> \n",
  857. "`train_batch0.jpg` shows train batch 0 mosaics and labels\n",
  858. "\n",
  859. "> <img src=\"https://user-images.githubusercontent.com/26833433/131256748-603cafc7-55d1-4e58-ab26-83657761aed9.jpg\" width=\"700\"> \n",
  860. "`test_batch0_labels.jpg` shows val batch 0 labels\n",
  861. "\n",
  862. "> <img src=\"https://user-images.githubusercontent.com/26833433/131256752-3f25d7a5-7b0f-4bb3-ab78-46343c3800fe.jpg\" width=\"700\"> \n",
  863. "`test_batch0_pred.jpg` shows val batch 0 _predictions_\n",
  864. "\n",
  865. "Training results are automatically logged to [Tensorboard](https://www.tensorflow.org/tensorboard) and [CSV](https://github.com/ultralytics/yolov5/pull/4148) as `results.csv`, which is plotted as `results.png` (below) after training completes. You can also plot any `results.csv` file manually:\n",
  866. "\n",
  867. "```python\n",
  868. "from utils.plots import plot_results \n",
  869. "plot_results('path/to/results.csv') # plot 'results.csv' as 'results.png'\n",
  870. "```\n",
  871. "\n",
  872. "<img align=\"left\" width=\"800\" alt=\"COCO128 Training Results\" src=\"https://user-images.githubusercontent.com/26833433/126906780-8c5e2990-6116-4de6-b78a-367244a33ccf.png\">"
  873. ]
  874. },
  875. {
  876. "cell_type": "markdown",
  877. "metadata": {
  878. "id": "Zelyeqbyt3GD"
  879. },
  880. "source": [
  881. "# Environments\n",
  882. "\n",
  883. "YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including [CUDA](https://developer.nvidia.com/cuda)/[CUDNN](https://developer.nvidia.com/cudnn), [Python](https://www.python.org/) and [PyTorch](https://pytorch.org/) preinstalled):\n",
  884. "\n",
  885. "- **Google Colab and Kaggle** notebooks with free GPU: <a href=\"https://colab.research.google.com/github/ultralytics/yolov5/blob/master/tutorial.ipynb\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"></a> <a href=\"https://www.kaggle.com/ultralytics/yolov5\"><img src=\"https://kaggle.com/static/images/open-in-kaggle.svg\" alt=\"Open In Kaggle\"></a>\n",
  886. "- **Google Cloud** Deep Learning VM. See [GCP Quickstart Guide](https://github.com/ultralytics/yolov5/wiki/GCP-Quickstart)\n",
  887. "- **Amazon** Deep Learning AMI. See [AWS Quickstart Guide](https://github.com/ultralytics/yolov5/wiki/AWS-Quickstart)\n",
  888. "- **Docker Image**. See [Docker Quickstart Guide](https://github.com/ultralytics/yolov5/wiki/Docker-Quickstart) <a href=\"https://hub.docker.com/r/ultralytics/yolov5\"><img src=\"https://img.shields.io/docker/pulls/ultralytics/yolov5?logo=docker\" alt=\"Docker Pulls\"></a>\n"
  889. ]
  890. },
  891. {
  892. "cell_type": "markdown",
  893. "metadata": {
  894. "id": "6Qu7Iesl0p54"
  895. },
  896. "source": [
  897. "# Status\n",
  898. "\n",
  899. "![CI CPU testing](https://github.com/ultralytics/yolov5/workflows/CI%20CPU%20testing/badge.svg)\n",
  900. "\n",
  901. "If this badge is green, all [YOLOv5 GitHub Actions](https://github.com/ultralytics/yolov5/actions) Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training ([train.py](https://github.com/ultralytics/yolov5/blob/master/train.py)), testing ([val.py](https://github.com/ultralytics/yolov5/blob/master/val.py)), inference ([detect.py](https://github.com/ultralytics/yolov5/blob/master/detect.py)) and export ([export.py](https://github.com/ultralytics/yolov5/blob/master/export.py)) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.\n"
  902. ]
  903. },
  904. {
  905. "cell_type": "markdown",
  906. "metadata": {
  907. "id": "IEijrePND_2I"
  908. },
  909. "source": [
  910. "# Appendix\n",
  911. "\n",
  912. "Optional extras below. Unit tests validate repo functionality and should be run on any PRs submitted.\n"
  913. ]
  914. },
  915. {
  916. "cell_type": "code",
  917. "metadata": {
  918. "id": "mcKoSIK2WSzj"
  919. },
  920. "source": [
  921. "# Reproduce\n",
  922. "for x in 'yolov5s', 'yolov5m', 'yolov5l', 'yolov5x':\n",
  923. " !python val.py --weights {x}.pt --data coco.yaml --img 640 --conf 0.25 --iou 0.45 # speed\n",
  924. " !python val.py --weights {x}.pt --data coco.yaml --img 640 --conf 0.001 --iou 0.65 # mAP"
  925. ],
  926. "execution_count": null,
  927. "outputs": []
  928. },
  929. {
  930. "cell_type": "code",
  931. "metadata": {
  932. "id": "GMusP4OAxFu6"
  933. },
  934. "source": [
  935. "# PyTorch Hub\n",
  936. "import torch\n",
  937. "\n",
  938. "# Model\n",
  939. "model = torch.hub.load('ultralytics/yolov5', 'yolov5s')\n",
  940. "\n",
  941. "# Images\n",
  942. "dir = 'https://ultralytics.com/images/'\n",
  943. "imgs = [dir + f for f in ('zidane.jpg', 'bus.jpg')] # batch of images\n",
  944. "\n",
  945. "# Inference\n",
  946. "results = model(imgs)\n",
  947. "results.print() # or .show(), .save()"
  948. ],
  949. "execution_count": null,
  950. "outputs": []
  951. },
  952. {
  953. "cell_type": "code",
  954. "metadata": {
  955. "id": "FGH0ZjkGjejy"
  956. },
  957. "source": [
  958. "# Unit tests\n",
  959. "%%shell\n",
  960. "export PYTHONPATH=\"$PWD\" # to run *.py. files in subdirectories\n",
  961. "\n",
  962. "rm -rf runs # remove runs/\n",
  963. "for m in yolov5s; do # models\n",
  964. " python train.py --weights $m.pt --epochs 3 --img 320 --device 0 # train pretrained\n",
  965. " python train.py --weights '' --cfg $m.yaml --epochs 3 --img 320 --device 0 # train scratch\n",
  966. " for d in 0 cpu; do # devices\n",
  967. " python detect.py --weights $m.pt --device $d # detect official\n",
  968. " python detect.py --weights runs/train/exp/weights/best.pt --device $d # detect custom\n",
  969. " python val.py --weights $m.pt --device $d # val official\n",
  970. " python val.py --weights runs/train/exp/weights/best.pt --device $d # val custom\n",
  971. " done\n",
  972. " python hubconf.py # hub\n",
  973. " python models/yolo.py --cfg $m.yaml # inspect\n",
  974. " python export.py --weights $m.pt --img 640 --batch 1 # export\n",
  975. "done"
  976. ],
  977. "execution_count": null,
  978. "outputs": []
  979. },
  980. {
  981. "cell_type": "code",
  982. "metadata": {
  983. "id": "gogI-kwi3Tye"
  984. },
  985. "source": [
  986. "# Profile\n",
  987. "from utils.torch_utils import profile\n",
  988. "\n",
  989. "m1 = lambda x: x * torch.sigmoid(x)\n",
  990. "m2 = torch.nn.SiLU()\n",
  991. "results = profile(input=torch.randn(16, 3, 640, 640), ops=[m1, m2], n=100)"
  992. ],
  993. "execution_count": null,
  994. "outputs": []
  995. },
  996. {
  997. "cell_type": "code",
  998. "metadata": {
  999. "id": "RVRSOhEvUdb5"
  1000. },
  1001. "source": [
  1002. "# Evolve\n",
  1003. "!python train.py --img 640 --batch 64 --epochs 100 --data coco128.yaml --weights yolov5s.pt --cache --noautoanchor --evolve\n",
  1004. "!d=runs/train/evolve && cp evolve.* $d && zip -r evolve.zip $d && gsutil mv evolve.zip gs://bucket # upload results (optional)"
  1005. ],
  1006. "execution_count": null,
  1007. "outputs": []
  1008. },
  1009. {
  1010. "cell_type": "code",
  1011. "metadata": {
  1012. "id": "BSgFCAcMbk1R"
  1013. },
  1014. "source": [
  1015. "# VOC\n",
  1016. "for b, m in zip([64, 48, 32, 16], ['yolov5s', 'yolov5m', 'yolov5l', 'yolov5x']): # zip(batch_size, model)\n",
  1017. " !python train.py --batch {b} --weights {m}.pt --data VOC.yaml --epochs 50 --cache --img 512 --nosave --hyp hyp.finetune.yaml --project VOC --name {m}"
  1018. ],
  1019. "execution_count": null,
  1020. "outputs": []
  1021. }
  1022. ]
  1023. }