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 52KB

4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
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 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
3 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
3 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
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 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
4 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  1. {
  2. "nbformat": 4,
  3. "nbformat_minor": 0,
  4. "metadata": {
  5. "colab": {
  6. "name": "YOLOv5 Tutorial",
  7. "provenance": [],
  8. "collapsed_sections": [],
  9. "toc_visible": true,
  10. "include_colab_link": true
  11. },
  12. "kernelspec": {
  13. "name": "python3",
  14. "display_name": "Python 3"
  15. },
  16. "accelerator": "GPU",
  17. "widgets": {
  18. "application/vnd.jupyter.widget-state+json": {
  19. "2e915d9016c846e095e382b6a02ee773": {
  20. "model_module": "@jupyter-widgets/controls",
  21. "model_name": "HBoxModel",
  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_cb7fc3a5c6cc4fde8d2c83e594a7c86e",
  32. "_model_module": "@jupyter-widgets/controls",
  33. "children": [
  34. "IPY_MODEL_ac3edef4e3434f4587e6cbf8aa048770",
  35. "IPY_MODEL_853ac234cc2a4236946fc516871e10eb"
  36. ]
  37. }
  38. },
  39. "cb7fc3a5c6cc4fde8d2c83e594a7c86e": {
  40. "model_module": "@jupyter-widgets/base",
  41. "model_name": "LayoutModel",
  42. "state": {
  43. "_view_name": "LayoutView",
  44. "grid_template_rows": null,
  45. "right": null,
  46. "justify_content": null,
  47. "_view_module": "@jupyter-widgets/base",
  48. "overflow": null,
  49. "_model_module_version": "1.2.0",
  50. "_view_count": null,
  51. "flex_flow": null,
  52. "width": null,
  53. "min_width": null,
  54. "border": null,
  55. "align_items": null,
  56. "bottom": null,
  57. "_model_module": "@jupyter-widgets/base",
  58. "top": null,
  59. "grid_column": null,
  60. "overflow_y": null,
  61. "overflow_x": null,
  62. "grid_auto_flow": null,
  63. "grid_area": null,
  64. "grid_template_columns": null,
  65. "flex": null,
  66. "_model_name": "LayoutModel",
  67. "justify_items": null,
  68. "grid_row": null,
  69. "max_height": null,
  70. "align_content": null,
  71. "visibility": null,
  72. "align_self": null,
  73. "height": null,
  74. "min_height": null,
  75. "padding": null,
  76. "grid_auto_rows": null,
  77. "grid_gap": null,
  78. "max_width": null,
  79. "order": null,
  80. "_view_module_version": "1.2.0",
  81. "grid_template_areas": null,
  82. "object_position": null,
  83. "object_fit": null,
  84. "grid_auto_columns": null,
  85. "margin": null,
  86. "display": null,
  87. "left": null
  88. }
  89. },
  90. "ac3edef4e3434f4587e6cbf8aa048770": {
  91. "model_module": "@jupyter-widgets/controls",
  92. "model_name": "FloatProgressModel",
  93. "state": {
  94. "_view_name": "ProgressView",
  95. "style": "IPY_MODEL_13842ca90c0047e584b8d68d99dad2b1",
  96. "_dom_classes": [],
  97. "description": "100%",
  98. "_model_name": "FloatProgressModel",
  99. "bar_style": "success",
  100. "max": 818322941,
  101. "_view_module": "@jupyter-widgets/controls",
  102. "_model_module_version": "1.5.0",
  103. "value": 818322941,
  104. "_view_count": null,
  105. "_view_module_version": "1.5.0",
  106. "orientation": "horizontal",
  107. "min": 0,
  108. "description_tooltip": null,
  109. "_model_module": "@jupyter-widgets/controls",
  110. "layout": "IPY_MODEL_f454999c3a924c7bad0746fb453dec36"
  111. }
  112. },
  113. "853ac234cc2a4236946fc516871e10eb": {
  114. "model_module": "@jupyter-widgets/controls",
  115. "model_name": "HTMLModel",
  116. "state": {
  117. "_view_name": "HTMLView",
  118. "style": "IPY_MODEL_f94a7ca8c1f04761bf38fdc5f99664b8",
  119. "_dom_classes": [],
  120. "description": "",
  121. "_model_name": "HTMLModel",
  122. "placeholder": "​",
  123. "_view_module": "@jupyter-widgets/controls",
  124. "_model_module_version": "1.5.0",
  125. "value": " 780M/780M [03:59&lt;00:00, 3.42MB/s]",
  126. "_view_count": null,
  127. "_view_module_version": "1.5.0",
  128. "description_tooltip": null,
  129. "_model_module": "@jupyter-widgets/controls",
  130. "layout": "IPY_MODEL_9da1a23b042c41618dd14b0e30aa7cbe"
  131. }
  132. },
  133. "13842ca90c0047e584b8d68d99dad2b1": {
  134. "model_module": "@jupyter-widgets/controls",
  135. "model_name": "ProgressStyleModel",
  136. "state": {
  137. "_view_name": "StyleView",
  138. "_model_name": "ProgressStyleModel",
  139. "description_width": "initial",
  140. "_view_module": "@jupyter-widgets/base",
  141. "_model_module_version": "1.5.0",
  142. "_view_count": null,
  143. "_view_module_version": "1.2.0",
  144. "bar_color": null,
  145. "_model_module": "@jupyter-widgets/controls"
  146. }
  147. },
  148. "f454999c3a924c7bad0746fb453dec36": {
  149. "model_module": "@jupyter-widgets/base",
  150. "model_name": "LayoutModel",
  151. "state": {
  152. "_view_name": "LayoutView",
  153. "grid_template_rows": null,
  154. "right": null,
  155. "justify_content": null,
  156. "_view_module": "@jupyter-widgets/base",
  157. "overflow": null,
  158. "_model_module_version": "1.2.0",
  159. "_view_count": null,
  160. "flex_flow": null,
  161. "width": null,
  162. "min_width": null,
  163. "border": null,
  164. "align_items": null,
  165. "bottom": null,
  166. "_model_module": "@jupyter-widgets/base",
  167. "top": null,
  168. "grid_column": null,
  169. "overflow_y": null,
  170. "overflow_x": null,
  171. "grid_auto_flow": null,
  172. "grid_area": null,
  173. "grid_template_columns": null,
  174. "flex": null,
  175. "_model_name": "LayoutModel",
  176. "justify_items": null,
  177. "grid_row": null,
  178. "max_height": null,
  179. "align_content": null,
  180. "visibility": null,
  181. "align_self": null,
  182. "height": null,
  183. "min_height": null,
  184. "padding": null,
  185. "grid_auto_rows": null,
  186. "grid_gap": null,
  187. "max_width": null,
  188. "order": null,
  189. "_view_module_version": "1.2.0",
  190. "grid_template_areas": null,
  191. "object_position": null,
  192. "object_fit": null,
  193. "grid_auto_columns": null,
  194. "margin": null,
  195. "display": null,
  196. "left": null
  197. }
  198. },
  199. "f94a7ca8c1f04761bf38fdc5f99664b8": {
  200. "model_module": "@jupyter-widgets/controls",
  201. "model_name": "DescriptionStyleModel",
  202. "state": {
  203. "_view_name": "StyleView",
  204. "_model_name": "DescriptionStyleModel",
  205. "description_width": "",
  206. "_view_module": "@jupyter-widgets/base",
  207. "_model_module_version": "1.5.0",
  208. "_view_count": null,
  209. "_view_module_version": "1.2.0",
  210. "_model_module": "@jupyter-widgets/controls"
  211. }
  212. },
  213. "9da1a23b042c41618dd14b0e30aa7cbe": {
  214. "model_module": "@jupyter-widgets/base",
  215. "model_name": "LayoutModel",
  216. "state": {
  217. "_view_name": "LayoutView",
  218. "grid_template_rows": null,
  219. "right": null,
  220. "justify_content": null,
  221. "_view_module": "@jupyter-widgets/base",
  222. "overflow": null,
  223. "_model_module_version": "1.2.0",
  224. "_view_count": null,
  225. "flex_flow": null,
  226. "width": null,
  227. "min_width": null,
  228. "border": null,
  229. "align_items": null,
  230. "bottom": null,
  231. "_model_module": "@jupyter-widgets/base",
  232. "top": null,
  233. "grid_column": null,
  234. "overflow_y": null,
  235. "overflow_x": null,
  236. "grid_auto_flow": null,
  237. "grid_area": null,
  238. "grid_template_columns": null,
  239. "flex": null,
  240. "_model_name": "LayoutModel",
  241. "justify_items": null,
  242. "grid_row": null,
  243. "max_height": null,
  244. "align_content": null,
  245. "visibility": null,
  246. "align_self": null,
  247. "height": null,
  248. "min_height": null,
  249. "padding": null,
  250. "grid_auto_rows": null,
  251. "grid_gap": null,
  252. "max_width": null,
  253. "order": null,
  254. "_view_module_version": "1.2.0",
  255. "grid_template_areas": null,
  256. "object_position": null,
  257. "object_fit": null,
  258. "grid_auto_columns": null,
  259. "margin": null,
  260. "display": null,
  261. "left": null
  262. }
  263. },
  264. "6ff8a710ded44391a624dec5c460b771": {
  265. "model_module": "@jupyter-widgets/controls",
  266. "model_name": "HBoxModel",
  267. "state": {
  268. "_view_name": "HBoxView",
  269. "_dom_classes": [],
  270. "_model_name": "HBoxModel",
  271. "_view_module": "@jupyter-widgets/controls",
  272. "_model_module_version": "1.5.0",
  273. "_view_count": null,
  274. "_view_module_version": "1.5.0",
  275. "box_style": "",
  276. "layout": "IPY_MODEL_3c19729b51cd45d4848035da06e96ff8",
  277. "_model_module": "@jupyter-widgets/controls",
  278. "children": [
  279. "IPY_MODEL_23b2f0ae3d46438c8de375987c77f580",
  280. "IPY_MODEL_dd9498c321a9422da6faf17a0be026d4"
  281. ]
  282. }
  283. },
  284. "3c19729b51cd45d4848035da06e96ff8": {
  285. "model_module": "@jupyter-widgets/base",
  286. "model_name": "LayoutModel",
  287. "state": {
  288. "_view_name": "LayoutView",
  289. "grid_template_rows": null,
  290. "right": null,
  291. "justify_content": null,
  292. "_view_module": "@jupyter-widgets/base",
  293. "overflow": null,
  294. "_model_module_version": "1.2.0",
  295. "_view_count": null,
  296. "flex_flow": null,
  297. "width": null,
  298. "min_width": null,
  299. "border": null,
  300. "align_items": null,
  301. "bottom": null,
  302. "_model_module": "@jupyter-widgets/base",
  303. "top": null,
  304. "grid_column": null,
  305. "overflow_y": null,
  306. "overflow_x": null,
  307. "grid_auto_flow": null,
  308. "grid_area": null,
  309. "grid_template_columns": null,
  310. "flex": null,
  311. "_model_name": "LayoutModel",
  312. "justify_items": null,
  313. "grid_row": null,
  314. "max_height": null,
  315. "align_content": null,
  316. "visibility": null,
  317. "align_self": null,
  318. "height": null,
  319. "min_height": null,
  320. "padding": null,
  321. "grid_auto_rows": null,
  322. "grid_gap": null,
  323. "max_width": null,
  324. "order": null,
  325. "_view_module_version": "1.2.0",
  326. "grid_template_areas": null,
  327. "object_position": null,
  328. "object_fit": null,
  329. "grid_auto_columns": null,
  330. "margin": null,
  331. "display": null,
  332. "left": null
  333. }
  334. },
  335. "23b2f0ae3d46438c8de375987c77f580": {
  336. "model_module": "@jupyter-widgets/controls",
  337. "model_name": "FloatProgressModel",
  338. "state": {
  339. "_view_name": "ProgressView",
  340. "style": "IPY_MODEL_d8dda4b2ce864fd682e558b9a48f602e",
  341. "_dom_classes": [],
  342. "description": "100%",
  343. "_model_name": "FloatProgressModel",
  344. "bar_style": "success",
  345. "max": 6984509,
  346. "_view_module": "@jupyter-widgets/controls",
  347. "_model_module_version": "1.5.0",
  348. "value": 6984509,
  349. "_view_count": null,
  350. "_view_module_version": "1.5.0",
  351. "orientation": "horizontal",
  352. "min": 0,
  353. "description_tooltip": null,
  354. "_model_module": "@jupyter-widgets/controls",
  355. "layout": "IPY_MODEL_ff8151449e444a14869684212b9ab14e"
  356. }
  357. },
  358. "dd9498c321a9422da6faf17a0be026d4": {
  359. "model_module": "@jupyter-widgets/controls",
  360. "model_name": "HTMLModel",
  361. "state": {
  362. "_view_name": "HTMLView",
  363. "style": "IPY_MODEL_0f84fe609bcf4aa9afdc32a8cf076909",
  364. "_dom_classes": [],
  365. "description": "",
  366. "_model_name": "HTMLModel",
  367. "placeholder": "​",
  368. "_view_module": "@jupyter-widgets/controls",
  369. "_model_module_version": "1.5.0",
  370. "value": " 6.66M/6.66M [00:01&lt;00:00, 6.08MB/s]",
  371. "_view_count": null,
  372. "_view_module_version": "1.5.0",
  373. "description_tooltip": null,
  374. "_model_module": "@jupyter-widgets/controls",
  375. "layout": "IPY_MODEL_8fda673769984e2b928ef820d34c85c3"
  376. }
  377. },
  378. "d8dda4b2ce864fd682e558b9a48f602e": {
  379. "model_module": "@jupyter-widgets/controls",
  380. "model_name": "ProgressStyleModel",
  381. "state": {
  382. "_view_name": "StyleView",
  383. "_model_name": "ProgressStyleModel",
  384. "description_width": "initial",
  385. "_view_module": "@jupyter-widgets/base",
  386. "_model_module_version": "1.5.0",
  387. "_view_count": null,
  388. "_view_module_version": "1.2.0",
  389. "bar_color": null,
  390. "_model_module": "@jupyter-widgets/controls"
  391. }
  392. },
  393. "ff8151449e444a14869684212b9ab14e": {
  394. "model_module": "@jupyter-widgets/base",
  395. "model_name": "LayoutModel",
  396. "state": {
  397. "_view_name": "LayoutView",
  398. "grid_template_rows": null,
  399. "right": null,
  400. "justify_content": null,
  401. "_view_module": "@jupyter-widgets/base",
  402. "overflow": null,
  403. "_model_module_version": "1.2.0",
  404. "_view_count": null,
  405. "flex_flow": null,
  406. "width": null,
  407. "min_width": null,
  408. "border": null,
  409. "align_items": null,
  410. "bottom": null,
  411. "_model_module": "@jupyter-widgets/base",
  412. "top": null,
  413. "grid_column": null,
  414. "overflow_y": null,
  415. "overflow_x": null,
  416. "grid_auto_flow": null,
  417. "grid_area": null,
  418. "grid_template_columns": null,
  419. "flex": null,
  420. "_model_name": "LayoutModel",
  421. "justify_items": null,
  422. "grid_row": null,
  423. "max_height": null,
  424. "align_content": null,
  425. "visibility": null,
  426. "align_self": null,
  427. "height": null,
  428. "min_height": null,
  429. "padding": null,
  430. "grid_auto_rows": null,
  431. "grid_gap": null,
  432. "max_width": null,
  433. "order": null,
  434. "_view_module_version": "1.2.0",
  435. "grid_template_areas": null,
  436. "object_position": null,
  437. "object_fit": null,
  438. "grid_auto_columns": null,
  439. "margin": null,
  440. "display": null,
  441. "left": null
  442. }
  443. },
  444. "0f84fe609bcf4aa9afdc32a8cf076909": {
  445. "model_module": "@jupyter-widgets/controls",
  446. "model_name": "DescriptionStyleModel",
  447. "state": {
  448. "_view_name": "StyleView",
  449. "_model_name": "DescriptionStyleModel",
  450. "description_width": "",
  451. "_view_module": "@jupyter-widgets/base",
  452. "_model_module_version": "1.5.0",
  453. "_view_count": null,
  454. "_view_module_version": "1.2.0",
  455. "_model_module": "@jupyter-widgets/controls"
  456. }
  457. },
  458. "8fda673769984e2b928ef820d34c85c3": {
  459. "model_module": "@jupyter-widgets/base",
  460. "model_name": "LayoutModel",
  461. "state": {
  462. "_view_name": "LayoutView",
  463. "grid_template_rows": null,
  464. "right": null,
  465. "justify_content": null,
  466. "_view_module": "@jupyter-widgets/base",
  467. "overflow": null,
  468. "_model_module_version": "1.2.0",
  469. "_view_count": null,
  470. "flex_flow": null,
  471. "width": null,
  472. "min_width": null,
  473. "border": null,
  474. "align_items": null,
  475. "bottom": null,
  476. "_model_module": "@jupyter-widgets/base",
  477. "top": null,
  478. "grid_column": null,
  479. "overflow_y": null,
  480. "overflow_x": null,
  481. "grid_auto_flow": null,
  482. "grid_area": null,
  483. "grid_template_columns": null,
  484. "flex": null,
  485. "_model_name": "LayoutModel",
  486. "justify_items": null,
  487. "grid_row": null,
  488. "max_height": null,
  489. "align_content": null,
  490. "visibility": null,
  491. "align_self": null,
  492. "height": null,
  493. "min_height": null,
  494. "padding": null,
  495. "grid_auto_rows": null,
  496. "grid_gap": null,
  497. "max_width": null,
  498. "order": null,
  499. "_view_module_version": "1.2.0",
  500. "grid_template_areas": null,
  501. "object_position": null,
  502. "object_fit": null,
  503. "grid_auto_columns": null,
  504. "margin": null,
  505. "display": null,
  506. "left": null
  507. }
  508. }
  509. }
  510. }
  511. },
  512. "cells": [
  513. {
  514. "cell_type": "markdown",
  515. "metadata": {
  516. "id": "view-in-github",
  517. "colab_type": "text"
  518. },
  519. "source": [
  520. "<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>"
  521. ]
  522. },
  523. {
  524. "cell_type": "markdown",
  525. "metadata": {
  526. "id": "t6MPjfT5NrKQ"
  527. },
  528. "source": [
  529. "<a align=\"left\" href=\"https://ultralytics.com/yolov5\" target=\"_blank\">\n",
  530. "<img src=\"https://user-images.githubusercontent.com/26833433/125273437-35b3fc00-e30d-11eb-9079-46f313325424.png\"></a>\n",
  531. "\n",
  532. "This is the **official YOLOv5 🚀 notebook** authored by **Ultralytics**, and is freely available for redistribution under the [GPL-3.0 license](https://choosealicense.com/licenses/gpl-3.0/). \n",
  533. "For more information please visit https://github.com/ultralytics/yolov5 and https://ultralytics.com. Thank you!"
  534. ]
  535. },
  536. {
  537. "cell_type": "markdown",
  538. "metadata": {
  539. "id": "7mGmQbAO5pQb"
  540. },
  541. "source": [
  542. "# Setup\n",
  543. "\n",
  544. "Clone repo, install dependencies and check PyTorch and GPU."
  545. ]
  546. },
  547. {
  548. "cell_type": "code",
  549. "metadata": {
  550. "id": "wbvMlHd_QwMG",
  551. "colab": {
  552. "base_uri": "https://localhost:8080/"
  553. },
  554. "outputId": "ada1dd8d-e0aa-4858-e893-dc320319ca30"
  555. },
  556. "source": [
  557. "!git clone https://github.com/ultralytics/yolov5 # clone repo\n",
  558. "%cd yolov5\n",
  559. "%pip install -qr requirements.txt # install dependencies\n",
  560. "\n",
  561. "import torch\n",
  562. "from IPython.display import Image, clear_output # to display images\n",
  563. "\n",
  564. "clear_output()\n",
  565. "print(f\"Setup complete. Using torch {torch.__version__} ({torch.cuda.get_device_properties(0).name if torch.cuda.is_available() else 'CPU'})\")"
  566. ],
  567. "execution_count": 1,
  568. "outputs": [
  569. {
  570. "output_type": "stream",
  571. "text": [
  572. "Setup complete. Using torch 1.9.0+cu102 (Tesla V100-SXM2-16GB)\n"
  573. ],
  574. "name": "stdout"
  575. }
  576. ]
  577. },
  578. {
  579. "cell_type": "markdown",
  580. "metadata": {
  581. "id": "4JnkELT0cIJg"
  582. },
  583. "source": [
  584. "# 1. Inference\n",
  585. "\n",
  586. "`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",
  587. "\n",
  588. "<img align=\"left\" src=\"https://user-images.githubusercontent.com/26833433/114307955-5c7e4e80-9ae2-11eb-9f50-a90e39bee53f.png\" width=\"900\"> "
  589. ]
  590. },
  591. {
  592. "cell_type": "code",
  593. "metadata": {
  594. "id": "zR9ZbuQCH7FX",
  595. "colab": {
  596. "base_uri": "https://localhost:8080/"
  597. },
  598. "outputId": "a7a37616-a82b-4bdb-a463-6ead850b5615"
  599. },
  600. "source": [
  601. "!python detect.py --weights yolov5s.pt --img 640 --conf 0.25 --source data/images/\n",
  602. "Image(filename='runs/detect/exp/zidane.jpg', width=600)"
  603. ],
  604. "execution_count": 9,
  605. "outputs": [
  606. {
  607. "output_type": "stream",
  608. "text": [
  609. "\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",
  610. "YOLOv5 🚀 v5.0-330-g18f6ba7 torch 1.9.0+cu102 CUDA:0 (Tesla V100-SXM2-16GB, 16160.5MB)\n",
  611. "\n",
  612. "Fusing layers... \n",
  613. "Model Summary: 224 layers, 7266973 parameters, 0 gradients\n",
  614. "image 1/2 /content/yolov5/data/images/bus.jpg: 640x480 4 persons, 1 bus, 1 fire hydrant, Done. (0.008s)\n",
  615. "image 2/2 /content/yolov5/data/images/zidane.jpg: 384x640 2 persons, 2 ties, Done. (0.008s)\n",
  616. "Results saved to runs/detect/exp\n",
  617. "Done. (0.091s)\n"
  618. ],
  619. "name": "stdout"
  620. }
  621. ]
  622. },
  623. {
  624. "cell_type": "markdown",
  625. "metadata": {
  626. "id": "hkAzDWJ7cWTr"
  627. },
  628. "source": [
  629. "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n",
  630. "<img align=\"left\" src=\"https://user-images.githubusercontent.com/26833433/127574988-6a558aa1-d268-44b9-bf6b-62d4c605cc72.jpg\" width=\"600\">"
  631. ]
  632. },
  633. {
  634. "cell_type": "markdown",
  635. "metadata": {
  636. "id": "0eq1SMWl6Sfn"
  637. },
  638. "source": [
  639. "# 2. Validate\n",
  640. "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."
  641. ]
  642. },
  643. {
  644. "cell_type": "markdown",
  645. "metadata": {
  646. "id": "eyTZYGgRjnMc"
  647. },
  648. "source": [
  649. "## COCO val2017\n",
  650. "Download [COCO val 2017](https://github.com/ultralytics/yolov5/blob/74b34872fdf41941cddcf243951cdb090fbac17b/data/coco.yaml#L14) dataset (1GB - 5000 images), and test model accuracy."
  651. ]
  652. },
  653. {
  654. "cell_type": "code",
  655. "metadata": {
  656. "id": "WQPtK1QYVaD_",
  657. "colab": {
  658. "base_uri": "https://localhost:8080/",
  659. "height": 66,
  660. "referenced_widgets": [
  661. "2e915d9016c846e095e382b6a02ee773",
  662. "cb7fc3a5c6cc4fde8d2c83e594a7c86e",
  663. "ac3edef4e3434f4587e6cbf8aa048770",
  664. "853ac234cc2a4236946fc516871e10eb",
  665. "13842ca90c0047e584b8d68d99dad2b1",
  666. "f454999c3a924c7bad0746fb453dec36",
  667. "f94a7ca8c1f04761bf38fdc5f99664b8",
  668. "9da1a23b042c41618dd14b0e30aa7cbe"
  669. ]
  670. },
  671. "outputId": "3606f305-aa67-43fd-d5d6-93d1f311768c"
  672. },
  673. "source": [
  674. "# Download COCO val2017\n",
  675. "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017val.zip', 'tmp.zip')\n",
  676. "!unzip -q tmp.zip -d ../datasets && rm tmp.zip"
  677. ],
  678. "execution_count": 10,
  679. "outputs": [
  680. {
  681. "output_type": "display_data",
  682. "data": {
  683. "application/vnd.jupyter.widget-view+json": {
  684. "model_id": "2e915d9016c846e095e382b6a02ee773",
  685. "version_minor": 0,
  686. "version_major": 2
  687. },
  688. "text/plain": [
  689. "HBox(children=(FloatProgress(value=0.0, max=818322941.0), HTML(value='')))"
  690. ]
  691. },
  692. "metadata": {
  693. "tags": []
  694. }
  695. },
  696. {
  697. "output_type": "stream",
  698. "text": [
  699. "\n"
  700. ],
  701. "name": "stdout"
  702. }
  703. ]
  704. },
  705. {
  706. "cell_type": "code",
  707. "metadata": {
  708. "id": "X58w8JLpMnjH",
  709. "colab": {
  710. "base_uri": "https://localhost:8080/"
  711. },
  712. "outputId": "20fbc423-f536-43ff-e70b-3acf6aeade99"
  713. },
  714. "source": [
  715. "# Run YOLOv5x on COCO val2017\n",
  716. "!python val.py --weights yolov5x.pt --data coco.yaml --img 640 --iou 0.65 --half"
  717. ],
  718. "execution_count": 11,
  719. "outputs": [
  720. {
  721. "output_type": "stream",
  722. "text": [
  723. "\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",
  724. "YOLOv5 🚀 v5.0-330-g18f6ba7 torch 1.9.0+cu102 CUDA:0 (Tesla V100-SXM2-16GB, 16160.5MB)\n",
  725. "\n",
  726. "Downloading https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5x.pt to yolov5x.pt...\n",
  727. "100% 168M/168M [00:05<00:00, 31.9MB/s]\n",
  728. "\n",
  729. "Fusing layers... \n",
  730. "Model Summary: 476 layers, 87730285 parameters, 0 gradients\n",
  731. "\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, 2653.03it/s]\n",
  732. "\u001b[34m\u001b[1mval: \u001b[0mNew cache created: ../datasets/coco/val2017.cache\n",
  733. " Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 157/157 [01:18<00:00, 2.00it/s]\n",
  734. " all 5000 36335 0.746 0.626 0.68 0.49\n",
  735. "Speed: 0.1ms pre-process, 5.1ms inference, 1.5ms NMS per image at shape (32, 3, 640, 640)\n",
  736. "\n",
  737. "Evaluating pycocotools mAP... saving runs/val/exp/yolov5x_predictions.json...\n",
  738. "loading annotations into memory...\n",
  739. "Done (t=0.44s)\n",
  740. "creating index...\n",
  741. "index created!\n",
  742. "Loading and preparing results...\n",
  743. "DONE (t=4.82s)\n",
  744. "creating index...\n",
  745. "index created!\n",
  746. "Running per image evaluation...\n",
  747. "Evaluate annotation type *bbox*\n",
  748. "DONE (t=84.52s).\n",
  749. "Accumulating evaluation results...\n",
  750. "DONE (t=13.82s).\n",
  751. " Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.504\n",
  752. " Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.688\n",
  753. " Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.546\n",
  754. " Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.351\n",
  755. " Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.551\n",
  756. " Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.644\n",
  757. " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.382\n",
  758. " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.629\n",
  759. " Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.681\n",
  760. " Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.524\n",
  761. " Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.735\n",
  762. " Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.827\n",
  763. "Results saved to runs/val/exp\n"
  764. ],
  765. "name": "stdout"
  766. }
  767. ]
  768. },
  769. {
  770. "cell_type": "markdown",
  771. "metadata": {
  772. "id": "rc_KbFk0juX2"
  773. },
  774. "source": [
  775. "## COCO test-dev2017\n",
  776. "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."
  777. ]
  778. },
  779. {
  780. "cell_type": "code",
  781. "metadata": {
  782. "id": "V0AJnSeCIHyJ"
  783. },
  784. "source": [
  785. "# Download COCO test-dev2017\n",
  786. "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco2017labels.zip', 'tmp.zip')\n",
  787. "!unzip -q tmp.zip -d ../ && rm tmp.zip # unzip labels\n",
  788. "!f=\"test2017.zip\" && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f && rm $f # 7GB, 41k images\n",
  789. "%mv ./test2017 ../coco/images # move to /coco"
  790. ],
  791. "execution_count": null,
  792. "outputs": []
  793. },
  794. {
  795. "cell_type": "code",
  796. "metadata": {
  797. "id": "29GJXAP_lPrt"
  798. },
  799. "source": [
  800. "# Run YOLOv5s on COCO test-dev2017 using --task test\n",
  801. "!python val.py --weights yolov5s.pt --data coco.yaml --task test"
  802. ],
  803. "execution_count": null,
  804. "outputs": []
  805. },
  806. {
  807. "cell_type": "markdown",
  808. "metadata": {
  809. "id": "VUOiNLtMP5aG"
  810. },
  811. "source": [
  812. "# 3. Train\n",
  813. "\n",
  814. "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)."
  815. ]
  816. },
  817. {
  818. "cell_type": "code",
  819. "metadata": {
  820. "id": "Knxi2ncxWffW",
  821. "colab": {
  822. "base_uri": "https://localhost:8080/",
  823. "height": 66,
  824. "referenced_widgets": [
  825. "6ff8a710ded44391a624dec5c460b771",
  826. "3c19729b51cd45d4848035da06e96ff8",
  827. "23b2f0ae3d46438c8de375987c77f580",
  828. "dd9498c321a9422da6faf17a0be026d4",
  829. "d8dda4b2ce864fd682e558b9a48f602e",
  830. "ff8151449e444a14869684212b9ab14e",
  831. "0f84fe609bcf4aa9afdc32a8cf076909",
  832. "8fda673769984e2b928ef820d34c85c3"
  833. ]
  834. },
  835. "outputId": "4510c6b0-8d2a-436c-d3f4-c8f8470d913a"
  836. },
  837. "source": [
  838. "# Download COCO128\n",
  839. "torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip', 'tmp.zip')\n",
  840. "!unzip -q tmp.zip -d ../ && rm tmp.zip"
  841. ],
  842. "execution_count": 12,
  843. "outputs": [
  844. {
  845. "output_type": "display_data",
  846. "data": {
  847. "application/vnd.jupyter.widget-view+json": {
  848. "model_id": "6ff8a710ded44391a624dec5c460b771",
  849. "version_minor": 0,
  850. "version_major": 2
  851. },
  852. "text/plain": [
  853. "HBox(children=(FloatProgress(value=0.0, max=6984509.0), HTML(value='')))"
  854. ]
  855. },
  856. "metadata": {
  857. "tags": []
  858. }
  859. },
  860. {
  861. "output_type": "stream",
  862. "text": [
  863. "\n"
  864. ],
  865. "name": "stdout"
  866. }
  867. ]
  868. },
  869. {
  870. "cell_type": "markdown",
  871. "metadata": {
  872. "id": "_pOkGLv1dMqh"
  873. },
  874. "source": [
  875. "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",
  876. "\n",
  877. "All training results are saved to `runs/train/` with incrementing run directories, i.e. `runs/train/exp2`, `runs/train/exp3` etc.\n"
  878. ]
  879. },
  880. {
  881. "cell_type": "code",
  882. "metadata": {
  883. "id": "bOy5KI2ncnWd"
  884. },
  885. "source": [
  886. "# Tensorboard (optional)\n",
  887. "%load_ext tensorboard\n",
  888. "%tensorboard --logdir runs/train"
  889. ],
  890. "execution_count": null,
  891. "outputs": []
  892. },
  893. {
  894. "cell_type": "code",
  895. "metadata": {
  896. "id": "2fLAV42oNb7M"
  897. },
  898. "source": [
  899. "# Weights & Biases (optional)\n",
  900. "%pip install -q wandb\n",
  901. "import wandb\n",
  902. "wandb.login()"
  903. ],
  904. "execution_count": null,
  905. "outputs": []
  906. },
  907. {
  908. "cell_type": "code",
  909. "metadata": {
  910. "id": "1NcFxRcFdJ_O",
  911. "colab": {
  912. "base_uri": "https://localhost:8080/"
  913. },
  914. "outputId": "cd8ac17d-19a8-4e87-ab6a-31af1edac1ef"
  915. },
  916. "source": [
  917. "# Train YOLOv5s on COCO128 for 3 epochs\n",
  918. "!python train.py --img 640 --batch 16 --epochs 3 --data coco128.yaml --weights yolov5s.pt --cache"
  919. ],
  920. "execution_count": 13,
  921. "outputs": [
  922. {
  923. "output_type": "stream",
  924. "text": [
  925. "\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_images=True, 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\n",
  926. "\u001b[34m\u001b[1mgithub: \u001b[0mup to date with https://github.com/ultralytics/yolov5 ✅\n",
  927. "YOLOv5 🚀 v5.0-330-g18f6ba7 torch 1.9.0+cu102 CUDA:0 (Tesla V100-SXM2-16GB, 16160.5MB)\n",
  928. "\n",
  929. "\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",
  930. "\u001b[34m\u001b[1mWeights & Biases: \u001b[0mrun 'pip install wandb' to automatically track and visualize YOLOv5 🚀 runs (RECOMMENDED)\n",
  931. "\u001b[34m\u001b[1mTensorBoard: \u001b[0mStart with 'tensorboard --logdir runs/train', view at http://localhost:6006/\n",
  932. "2021-07-29 22:56:52.096481: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library libcudart.so.11.0\n",
  933. "\n",
  934. "WARNING: Dataset not found, nonexistent paths: ['/content/datasets/coco128/images/train2017']\n",
  935. "Downloading https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip ...\n",
  936. "100% 6.66M/6.66M [00:00<00:00, 44.0MB/s]\n",
  937. "Dataset autodownload success\n",
  938. "\n",
  939. "\n",
  940. " from n params module arguments \n",
  941. " 0 -1 1 3520 models.common.Focus [3, 32, 3] \n",
  942. " 1 -1 1 18560 models.common.Conv [32, 64, 3, 2] \n",
  943. " 2 -1 1 18816 models.common.C3 [64, 64, 1] \n",
  944. " 3 -1 1 73984 models.common.Conv [64, 128, 3, 2] \n",
  945. " 4 -1 1 156928 models.common.C3 [128, 128, 3] \n",
  946. " 5 -1 1 295424 models.common.Conv [128, 256, 3, 2] \n",
  947. " 6 -1 1 625152 models.common.C3 [256, 256, 3] \n",
  948. " 7 -1 1 1180672 models.common.Conv [256, 512, 3, 2] \n",
  949. " 8 -1 1 656896 models.common.SPP [512, 512, [5, 9, 13]] \n",
  950. " 9 -1 1 1182720 models.common.C3 [512, 512, 1, False] \n",
  951. " 10 -1 1 131584 models.common.Conv [512, 256, 1, 1] \n",
  952. " 11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
  953. " 12 [-1, 6] 1 0 models.common.Concat [1] \n",
  954. " 13 -1 1 361984 models.common.C3 [512, 256, 1, False] \n",
  955. " 14 -1 1 33024 models.common.Conv [256, 128, 1, 1] \n",
  956. " 15 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n",
  957. " 16 [-1, 4] 1 0 models.common.Concat [1] \n",
  958. " 17 -1 1 90880 models.common.C3 [256, 128, 1, False] \n",
  959. " 18 -1 1 147712 models.common.Conv [128, 128, 3, 2] \n",
  960. " 19 [-1, 14] 1 0 models.common.Concat [1] \n",
  961. " 20 -1 1 296448 models.common.C3 [256, 256, 1, False] \n",
  962. " 21 -1 1 590336 models.common.Conv [256, 256, 3, 2] \n",
  963. " 22 [-1, 10] 1 0 models.common.Concat [1] \n",
  964. " 23 -1 1 1182720 models.common.C3 [512, 512, 1, False] \n",
  965. " 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",
  966. "Model Summary: 283 layers, 7276605 parameters, 7276605 gradients, 17.1 GFLOPs\n",
  967. "\n",
  968. "Transferred 362/362 items from yolov5s.pt\n",
  969. "Scaled weight_decay = 0.0005\n",
  970. "\u001b[34m\u001b[1moptimizer:\u001b[0m SGD with parameter groups 59 weight, 62 weight (no decay), 62 bias\n",
  971. "\u001b[34m\u001b[1malbumentations: \u001b[0mversion 1.0.3 required by YOLOv5, but version 0.1.12 is currently installed\n",
  972. "\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, 2021.98it/s]\n",
  973. "\u001b[34m\u001b[1mtrain: \u001b[0mNew cache created: ../datasets/coco128/labels/train2017.cache\n",
  974. "\u001b[34m\u001b[1mtrain: \u001b[0mCaching images (0.1GB): 100% 128/128 [00:00<00:00, 273.58it/s]\n",
  975. "\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<00:00, 506004.63it/s]\n",
  976. "\u001b[34m\u001b[1mval: \u001b[0mCaching images (0.1GB): 100% 128/128 [00:01<00:00, 121.71it/s]\n",
  977. "[W pthreadpool-cpp.cc:90] Warning: Leaking Caffe2 thread-pool after fork. (function pthreadpool)\n",
  978. "[W pthreadpool-cpp.cc:90] Warning: Leaking Caffe2 thread-pool after fork. (function pthreadpool)\n",
  979. "Plotting labels... \n",
  980. "\n",
  981. "\u001b[34m\u001b[1mautoanchor: \u001b[0mAnalyzing anchors... anchors/target = 4.27, Best Possible Recall (BPR) = 0.9935\n",
  982. "Image sizes 640 train, 640 val\n",
  983. "Using 2 dataloader workers\n",
  984. "Logging results to runs/train/exp\n",
  985. "Starting training for 3 epochs...\n",
  986. "\n",
  987. " Epoch gpu_mem box obj cls labels img_size\n",
  988. " 0/2 3.64G 0.0441 0.06646 0.02229 290 640: 100% 8/8 [00:04<00:00, 1.93it/s]\n",
  989. " Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 4/4 [00:01<00:00, 3.45it/s]\n",
  990. " all 128 929 0.696 0.562 0.644 0.419\n",
  991. "\n",
  992. " Epoch gpu_mem box obj cls labels img_size\n",
  993. " 1/2 5.04G 0.04573 0.06289 0.021 226 640: 100% 8/8 [00:01<00:00, 5.46it/s]\n",
  994. " Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 4/4 [00:01<00:00, 3.16it/s]\n",
  995. " all 128 929 0.71 0.567 0.654 0.424\n",
  996. "\n",
  997. " Epoch gpu_mem box obj cls labels img_size\n",
  998. " 2/2 5.04G 0.04542 0.0715 0.02028 242 640: 100% 8/8 [00:01<00:00, 5.12it/s]\n",
  999. " Class Images Labels P R mAP@.5 mAP@.5:.95: 100% 4/4 [00:02<00:00, 1.46it/s]\n",
  1000. " all 128 929 0.731 0.563 0.658 0.427\n",
  1001. "3 epochs completed in 0.006 hours.\n",
  1002. "\n",
  1003. "Optimizer stripped from runs/train/exp/weights/last.pt, 14.8MB\n",
  1004. "Optimizer stripped from runs/train/exp/weights/best.pt, 14.8MB\n"
  1005. ],
  1006. "name": "stdout"
  1007. }
  1008. ]
  1009. },
  1010. {
  1011. "cell_type": "markdown",
  1012. "metadata": {
  1013. "id": "15glLzbQx5u0"
  1014. },
  1015. "source": [
  1016. "# 4. Visualize"
  1017. ]
  1018. },
  1019. {
  1020. "cell_type": "markdown",
  1021. "metadata": {
  1022. "id": "DLI1JmHU7B0l"
  1023. },
  1024. "source": [
  1025. "## Weights & Biases Logging 🌟 NEW\n",
  1026. "\n",
  1027. "[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",
  1028. "\n",
  1029. "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",
  1030. "\n",
  1031. "<img align=\"left\" src=\"https://user-images.githubusercontent.com/26833433/125274843-a27bc600-e30e-11eb-9a44-62af0b7a50a2.png\" width=\"800\">"
  1032. ]
  1033. },
  1034. {
  1035. "cell_type": "markdown",
  1036. "metadata": {
  1037. "id": "-WPvRbS5Swl6"
  1038. },
  1039. "source": [
  1040. "## Local Logging\n",
  1041. "\n",
  1042. "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",
  1043. "\n",
  1044. "> <img src=\"https://user-images.githubusercontent.com/26833433/124931219-48bf8700-e002-11eb-84f0-e05d95b118dd.jpg\" width=\"700\"> \n",
  1045. "`train_batch0.jpg` shows train batch 0 mosaics and labels\n",
  1046. "\n",
  1047. "> <img src=\"https://user-images.githubusercontent.com/26833433/124931217-4826f080-e002-11eb-87b9-ae0925a8c94b.jpg\" width=\"700\"> \n",
  1048. "`test_batch0_labels.jpg` shows val batch 0 labels\n",
  1049. "\n",
  1050. "> <img src=\"https://user-images.githubusercontent.com/26833433/124931209-46f5c380-e002-11eb-9bd5-7a3de2be9851.jpg\" width=\"700\"> \n",
  1051. "`test_batch0_pred.jpg` shows val batch 0 _predictions_\n",
  1052. "\n",
  1053. "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",
  1054. "\n",
  1055. "```python\n",
  1056. "from utils.plots import plot_results \n",
  1057. "plot_results('path/to/results.csv') # plot 'results.csv' as 'results.png'\n",
  1058. "```\n",
  1059. "\n",
  1060. "<img align=\"left\" width=\"800\" alt=\"COCO128 Training Results\" src=\"https://user-images.githubusercontent.com/26833433/126906780-8c5e2990-6116-4de6-b78a-367244a33ccf.png\">"
  1061. ]
  1062. },
  1063. {
  1064. "cell_type": "markdown",
  1065. "metadata": {
  1066. "id": "Zelyeqbyt3GD"
  1067. },
  1068. "source": [
  1069. "# Environments\n",
  1070. "\n",
  1071. "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",
  1072. "\n",
  1073. "- **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",
  1074. "- **Google Cloud** Deep Learning VM. See [GCP Quickstart Guide](https://github.com/ultralytics/yolov5/wiki/GCP-Quickstart)\n",
  1075. "- **Amazon** Deep Learning AMI. See [AWS Quickstart Guide](https://github.com/ultralytics/yolov5/wiki/AWS-Quickstart)\n",
  1076. "- **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"
  1077. ]
  1078. },
  1079. {
  1080. "cell_type": "markdown",
  1081. "metadata": {
  1082. "id": "6Qu7Iesl0p54"
  1083. },
  1084. "source": [
  1085. "# Status\n",
  1086. "\n",
  1087. "![CI CPU testing](https://github.com/ultralytics/yolov5/workflows/CI%20CPU%20testing/badge.svg)\n",
  1088. "\n",
  1089. "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"
  1090. ]
  1091. },
  1092. {
  1093. "cell_type": "markdown",
  1094. "metadata": {
  1095. "id": "IEijrePND_2I"
  1096. },
  1097. "source": [
  1098. "# Appendix\n",
  1099. "\n",
  1100. "Optional extras below. Unit tests validate repo functionality and should be run on any PRs submitted.\n"
  1101. ]
  1102. },
  1103. {
  1104. "cell_type": "code",
  1105. "metadata": {
  1106. "id": "mcKoSIK2WSzj"
  1107. },
  1108. "source": [
  1109. "# Reproduce\n",
  1110. "for x in 'yolov5s', 'yolov5m', 'yolov5l', 'yolov5x':\n",
  1111. " !python val.py --weights {x}.pt --data coco.yaml --img 640 --conf 0.25 --iou 0.45 # speed\n",
  1112. " !python val.py --weights {x}.pt --data coco.yaml --img 640 --conf 0.001 --iou 0.65 # mAP"
  1113. ],
  1114. "execution_count": null,
  1115. "outputs": []
  1116. },
  1117. {
  1118. "cell_type": "code",
  1119. "metadata": {
  1120. "id": "GMusP4OAxFu6"
  1121. },
  1122. "source": [
  1123. "# PyTorch Hub\n",
  1124. "import torch\n",
  1125. "\n",
  1126. "# Model\n",
  1127. "model = torch.hub.load('ultralytics/yolov5', 'yolov5s')\n",
  1128. "\n",
  1129. "# Images\n",
  1130. "dir = 'https://ultralytics.com/images/'\n",
  1131. "imgs = [dir + f for f in ('zidane.jpg', 'bus.jpg')] # batch of images\n",
  1132. "\n",
  1133. "# Inference\n",
  1134. "results = model(imgs)\n",
  1135. "results.print() # or .show(), .save()"
  1136. ],
  1137. "execution_count": null,
  1138. "outputs": []
  1139. },
  1140. {
  1141. "cell_type": "code",
  1142. "metadata": {
  1143. "id": "FGH0ZjkGjejy"
  1144. },
  1145. "source": [
  1146. "# Unit tests\n",
  1147. "%%shell\n",
  1148. "export PYTHONPATH=\"$PWD\" # to run *.py. files in subdirectories\n",
  1149. "\n",
  1150. "rm -rf runs # remove runs/\n",
  1151. "for m in yolov5s; do # models\n",
  1152. " python train.py --weights $m.pt --epochs 3 --img 320 --device 0 # train pretrained\n",
  1153. " python train.py --weights '' --cfg $m.yaml --epochs 3 --img 320 --device 0 # train scratch\n",
  1154. " for d in 0 cpu; do # devices\n",
  1155. " python detect.py --weights $m.pt --device $d # detect official\n",
  1156. " python detect.py --weights runs/train/exp/weights/best.pt --device $d # detect custom\n",
  1157. " python val.py --weights $m.pt --device $d # val official\n",
  1158. " python val.py --weights runs/train/exp/weights/best.pt --device $d # val custom\n",
  1159. " done\n",
  1160. " python hubconf.py # hub\n",
  1161. " python models/yolo.py --cfg $m.yaml # inspect\n",
  1162. " python export.py --weights $m.pt --img 640 --batch 1 # export\n",
  1163. "done"
  1164. ],
  1165. "execution_count": null,
  1166. "outputs": []
  1167. },
  1168. {
  1169. "cell_type": "code",
  1170. "metadata": {
  1171. "id": "gogI-kwi3Tye"
  1172. },
  1173. "source": [
  1174. "# Profile\n",
  1175. "from utils.torch_utils import profile\n",
  1176. "\n",
  1177. "m1 = lambda x: x * torch.sigmoid(x)\n",
  1178. "m2 = torch.nn.SiLU()\n",
  1179. "results = profile(input=torch.randn(16, 3, 640, 640), ops=[m1, m2], n=100)"
  1180. ],
  1181. "execution_count": null,
  1182. "outputs": []
  1183. },
  1184. {
  1185. "cell_type": "code",
  1186. "metadata": {
  1187. "id": "RVRSOhEvUdb5"
  1188. },
  1189. "source": [
  1190. "# Evolve\n",
  1191. "!python train.py --img 640 --batch 64 --epochs 100 --data coco128.yaml --weights yolov5s.pt --cache --noautoanchor --evolve\n",
  1192. "!d=runs/train/evolve && cp evolve.* $d && zip -r evolve.zip $d && gsutil mv evolve.zip gs://bucket # upload results (optional)"
  1193. ],
  1194. "execution_count": null,
  1195. "outputs": []
  1196. },
  1197. {
  1198. "cell_type": "code",
  1199. "metadata": {
  1200. "id": "BSgFCAcMbk1R"
  1201. },
  1202. "source": [
  1203. "# VOC\n",
  1204. "for b, m in zip([64, 48, 32, 16], ['yolov5s', 'yolov5m', 'yolov5l', 'yolov5x']): # zip(batch_size, model)\n",
  1205. " !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}"
  1206. ],
  1207. "execution_count": null,
  1208. "outputs": []
  1209. }
  1210. ]
  1211. }