{"metadata":{"colab":{"gpuType":"T4","provenance":[]},"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.9.13"},"widgets":{"application/vnd.jupyter.widget-state+json":{"05743219f1ed458c852673fa600070fc":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"0787766b236a4fd3b4b972ba4f1dccce":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"0a8168f947ee48a9a823946bbeca1e5e":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_b0d22c052b2f4f38bcbf2e5a742ee7e6","placeholder":"​","style":"IPY_MODEL_c39e233e62324ee4936ab3e17713fa29","value":"100%"}},"0b5d4d22a27b410292e657f997fb7105":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"0d64793f14304d3097a0a075bc376b2c":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"1389335942ba4fffad5afa020acadf0d":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"16f4d1f58f0547e8a6890125fbda7ce9":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_0b5d4d22a27b410292e657f997fb7105","placeholder":"​","style":"IPY_MODEL_1e20182e2c4f4a3eb86ae07f679dd03e","value":" 10/10 [05:55&lt;00:00, 41.40s/it]"}},"17c536dc0fe34023a1a7b8f575a1130b":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_ec5b2ede7da04f3f8423b101dd55ba6f","placeholder":"​","style":"IPY_MODEL_bac5f32d731b4a91b5dd74b4d17abf3d","value":"100%"}},"17ceaad85d52413f8d4da591e9dbac8d":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"1856873e983e4b4c9f1701dc3d1ebe93":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_282ea3066b4f49fca8d15b865be8c924","max":1291,"min":0,"orientation":"horizontal","style":"IPY_MODEL_31e8230a9bc54dacbbeeb51af084e993","value":1291}},"1993948015f347a0bfb71f5648e97a53":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_4a896d23f91b40d889363ef85924fd9c","placeholder":"​","style":"IPY_MODEL_1389335942ba4fffad5afa020acadf0d","value":" 23501/23501 [00:01&lt;00:00, 17757.55it/s]"}},"1e20182e2c4f4a3eb86ae07f679dd03e":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"1f09ff0993f445afbaf5be18f437a381":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"1f21ba2e6a7c4c7b862ca93b7b87db40":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_e0d94f30364049638a8b8155bdaf2d2e","placeholder":"​","style":"IPY_MODEL_f57aa394581c4bcdb050b760564d11c0","value":" 1291/1291 [00:00&lt;00:00, 3489.59it/s]"}},"204ac8738afe43c8a0ee2a32c32c36af":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"21e791facc544f8392ddb01ca5866485":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_5f2e4c7d6a7f49abbbeec0f758abae4f","placeholder":"​","style":"IPY_MODEL_ab9bd01ae3ae48c89bf8688cd9d661f7","value":" 279/279 [00:00&lt;00:00, 1747.91it/s]"}},"2765c0ff597b4ef49f9c5f17f97f5fd2":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_94d0d4209d5c4a8ebf2323d4fa2743ac","max":276,"min":0,"orientation":"horizontal","style":"IPY_MODEL_3f12bdf4b91a41e4ba46cd9bc7cc108f","value":276}},"282ea3066b4f49fca8d15b865be8c924":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"2aca09c426874cb684db633b47ae750a":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"2ae61efcfbbb43adaf46c3a657ff8863":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"2b141bc7c22f486aa57d0002c42ee81a":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_42a5d885ada04b468f82772b5fe972aa","placeholder":"​","style":"IPY_MODEL_9b8b628b27094903828385d5e40cbaef","value":" 276/276 [00:03&lt;00:00, 38.42it/s]"}},"31e8230a9bc54dacbbeeb51af084e993":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"37d5f942826b43139bf765b25cfbb7bd":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_f47b19c552474357a689a2038ba965a9","placeholder":"​","style":"IPY_MODEL_b5028e4e138d44ea93c397bacaf97b6c","value":"100%"}},"3f12bdf4b91a41e4ba46cd9bc7cc108f":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"4273d63ce2694d76ae49a0f7b879eeb7":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_85a3c706de134d54ab1ec6798a5d13b9","placeholder":"​","style":"IPY_MODEL_0d64793f14304d3097a0a075bc376b2c","value":"100%"}},"42a5d885ada04b468f82772b5fe972aa":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"4a896d23f91b40d889363ef85924fd9c":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"55d208be66ce4b8bad1d1514bd705ae4":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_9eb23a8b03da49bc984e3cbb7fd63cbb","placeholder":"​","style":"IPY_MODEL_8d86328381bc4fc7a896c8f8632949c0","value":" 276/276 [00:00&lt;00:00, 1535.85it/s]"}},"55e8184b5c8647b5bae885cd8e075f7e":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"58bcd813a1a64b21899a0cd947ddb482":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"5c6d8f2dbb654e1b975d92b4ddfed82b":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"5f2e4c7d6a7f49abbbeec0f758abae4f":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"5fff7232bccc4bcaa0d4b42f90f39f7e":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"68773aef964844e5abb7504419d960f8":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_96ed796ec211477cb4147e54e6c33a4f","placeholder":"​","style":"IPY_MODEL_b395c65ad09648488688da92c712ceae","value":"100%"}},"6904c22052e042bb893c11fa65100498":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"6cb9d73ed7ce4542b758561becd4b667":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"70b70829d8774649a39f4ace08f94b4c":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"7265375999014cc0bcf45dc0244fdb7e":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_e8bac8283ae74ef89d74db14672e018d","max":279,"min":0,"orientation":"horizontal","style":"IPY_MODEL_a03bd4a212814f1cabfe1dbc9f068f27","value":279}},"7606e3926d45459a991ef50783a81fea":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_0a8168f947ee48a9a823946bbeca1e5e","IPY_MODEL_f7e58aca099e41f2866d0c09f14d53d5","IPY_MODEL_7b25ee74b15b472899023e244d2b7497"],"layout":"IPY_MODEL_aedaac0151f44f0ba8fd89cc44b6185f"}},"7b25ee74b15b472899023e244d2b7497":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_b977698035024a2591d80394acf72a05","placeholder":"​","style":"IPY_MODEL_da311a85134749ef980687d4eeebf463","value":" 279/279 [00:10&lt;00:00, 103.55it/s]"}},"7e5dac362f1d4612a96573d2aa6a1021":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"7edc834627854e678f059a16396e977b":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"7fe07ee90d054a15aa25410636931ee6":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"827dd8defb9a4da7a0085e0ae6662979":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_f17be2a7455f4129b82463a5ea62ae09","IPY_MODEL_da6e4886defb40b8bcc73e1a0d2dd7a2","IPY_MODEL_55d208be66ce4b8bad1d1514bd705ae4"],"layout":"IPY_MODEL_d3ab8e683cfe4326852d1c1e4ebe4181"}},"85a3c706de134d54ab1ec6798a5d13b9":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"88ff3e3607fe4e1f82cf98e1e52f50e2":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"8924576ec3fb4c1db5d64edcf9e74cce":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_88ff3e3607fe4e1f82cf98e1e52f50e2","max":23501,"min":0,"orientation":"horizontal","style":"IPY_MODEL_5fff7232bccc4bcaa0d4b42f90f39f7e","value":23501}},"89e20781b4094ab29c5f8e46e07ef284":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_68773aef964844e5abb7504419d960f8","IPY_MODEL_e25e4e2bcc40469e98978f6afb2e2cbc","IPY_MODEL_16f4d1f58f0547e8a6890125fbda7ce9"],"layout":"IPY_MODEL_f2bd98dd9b49440a9967aa825a4f372c"}},"8c9406e85f7c4cbfb9b3869f810b3310":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_d65417873e4941f0aed85c5f15809790","IPY_MODEL_1856873e983e4b4c9f1701dc3d1ebe93","IPY_MODEL_1f21ba2e6a7c4c7b862ca93b7b87db40"],"layout":"IPY_MODEL_7fe07ee90d054a15aa25410636931ee6"}},"8d86328381bc4fc7a896c8f8632949c0":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"8e6bbd284d7c4e4c9e79edc390b9d4bb":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"92ac32b149a3499898cd198bf8689694":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"94d0d4209d5c4a8ebf2323d4fa2743ac":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"96ed796ec211477cb4147e54e6c33a4f":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"9722b810120e4f0ba889a48fcdb5129b":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_6904c22052e042bb893c11fa65100498","placeholder":"​","style":"IPY_MODEL_6cb9d73ed7ce4542b758561becd4b667","value":" 1291/1291 [00:08&lt;00:00, 254.89it/s]"}},"977261cfecda4bf1a26a31aff7a38cd9":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"9b8b628b27094903828385d5e40cbaef":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"9eb23a8b03da49bc984e3cbb7fd63cbb":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"a03bd4a212814f1cabfe1dbc9f068f27":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"a68ed9806b504c779e1fb85540f099a1":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_92ac32b149a3499898cd198bf8689694","placeholder":"​","style":"IPY_MODEL_e92f1c40d0654716bfa33f114ef70e5a","value":"100%"}},"a7e39c6cc07148b29cc46d0e55d67d44":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_17c536dc0fe34023a1a7b8f575a1130b","IPY_MODEL_b5d17ff8f6954ce49f37b85f0232bd47","IPY_MODEL_9722b810120e4f0ba889a48fcdb5129b"],"layout":"IPY_MODEL_05743219f1ed458c852673fa600070fc"}},"a96803387a454948be305237fa653e3a":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_abd8eee2c2d343e899d51aa374d4b247","placeholder":"​","style":"IPY_MODEL_977261cfecda4bf1a26a31aff7a38cd9","value":" 279/279 [00:00&lt;00:00, 868.18it/s]"}},"ab9bd01ae3ae48c89bf8688cd9d661f7":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"abd8eee2c2d343e899d51aa374d4b247":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"aedaac0151f44f0ba8fd89cc44b6185f":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"b0d22c052b2f4f38bcbf2e5a742ee7e6":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"b395c65ad09648488688da92c712ceae":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"b5028e4e138d44ea93c397bacaf97b6c":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"b5d17ff8f6954ce49f37b85f0232bd47":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_fcc4b0aa708349dc91b932b85978ef5f","max":1291,"min":0,"orientation":"horizontal","style":"IPY_MODEL_2ae61efcfbbb43adaf46c3a657ff8863","value":1291}},"b7c8f13c2495497a8502534b3b716d1c":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_a68ed9806b504c779e1fb85540f099a1","IPY_MODEL_7265375999014cc0bcf45dc0244fdb7e","IPY_MODEL_21e791facc544f8392ddb01ca5866485"],"layout":"IPY_MODEL_cbb8fead08204bab9069252432959ebc"}},"b7fa7316c8f34750a3ff5e5fa02b496f":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"b977698035024a2591d80394acf72a05":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"bac5f32d731b4a91b5dd74b4d17abf3d":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"c39e233e62324ee4936ab3e17713fa29":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"c64a3acd05704d91abec8d2bbc51f323":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_4273d63ce2694d76ae49a0f7b879eeb7","IPY_MODEL_2765c0ff597b4ef49f9c5f17f97f5fd2","IPY_MODEL_2b141bc7c22f486aa57d0002c42ee81a"],"layout":"IPY_MODEL_b7fa7316c8f34750a3ff5e5fa02b496f"}},"cbb8fead08204bab9069252432959ebc":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"cd7a1b6750bd4be6a5e8cde3ea5ed841":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"d3ab8e683cfe4326852d1c1e4ebe4181":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"d65417873e4941f0aed85c5f15809790":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_8e6bbd284d7c4e4c9e79edc390b9d4bb","placeholder":"​","style":"IPY_MODEL_204ac8738afe43c8a0ee2a32c32c36af","value":"100%"}},"da311a85134749ef980687d4eeebf463":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"da6e4886defb40b8bcc73e1a0d2dd7a2":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_55e8184b5c8647b5bae885cd8e075f7e","max":276,"min":0,"orientation":"horizontal","style":"IPY_MODEL_2aca09c426874cb684db633b47ae750a","value":276}},"da79a696a26d411ea9a31b429824be8d":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e0d94f30364049638a8b8155bdaf2d2e":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e25e4e2bcc40469e98978f6afb2e2cbc":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_7edc834627854e678f059a16396e977b","max":10,"min":0,"orientation":"horizontal","style":"IPY_MODEL_0787766b236a4fd3b4b972ba4f1dccce","value":10}},"e8bac8283ae74ef89d74db14672e018d":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"e92f1c40d0654716bfa33f114ef70e5a":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"e9bb2ebe36e54b988f1ee482792532a4":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_5c6d8f2dbb654e1b975d92b4ddfed82b","max":279,"min":0,"orientation":"horizontal","style":"IPY_MODEL_7e5dac362f1d4612a96573d2aa6a1021","value":279}},"ec5b2ede7da04f3f8423b101dd55ba6f":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"ed2bc76253d94b8d992981b09327b42c":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"ed83ca9d84544974a7e7a1f5b4d5c459":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_1f09ff0993f445afbaf5be18f437a381","placeholder":"​","style":"IPY_MODEL_ed2bc76253d94b8d992981b09327b42c","value":"100%"}},"f17be2a7455f4129b82463a5ea62ae09":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HTMLView","description":"","description_tooltip":null,"layout":"IPY_MODEL_da79a696a26d411ea9a31b429824be8d","placeholder":"​","style":"IPY_MODEL_58bcd813a1a64b21899a0cd947ddb482","value":"100%"}},"f2bd98dd9b49440a9967aa825a4f372c":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"f47b19c552474357a689a2038ba965a9":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"f51819fb50664d39ad962004ba521575":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"f57aa394581c4bcdb050b760564d11c0":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"DescriptionStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"DescriptionStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"StyleView","description_width":""}},"f7e58aca099e41f2866d0c09f14d53d5":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"ProgressView","bar_style":"success","description":"","description_tooltip":null,"layout":"IPY_MODEL_70b70829d8774649a39f4ace08f94b4c","max":279,"min":0,"orientation":"horizontal","style":"IPY_MODEL_17ceaad85d52413f8d4da591e9dbac8d","value":279}},"f8af80c91ca94e739282cf5fded869dc":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_37d5f942826b43139bf765b25cfbb7bd","IPY_MODEL_e9bb2ebe36e54b988f1ee482792532a4","IPY_MODEL_a96803387a454948be305237fa653e3a"],"layout":"IPY_MODEL_cd7a1b6750bd4be6a5e8cde3ea5ed841"}},"f98e82fedb39415eb1376e55566de0d0":{"model_module":"@jupyter-widgets/controls","model_module_version":"1.5.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_ed83ca9d84544974a7e7a1f5b4d5c459","IPY_MODEL_8924576ec3fb4c1db5d64edcf9e74cce","IPY_MODEL_1993948015f347a0bfb71f5648e97a53"],"layout":"IPY_MODEL_f51819fb50664d39ad962004ba521575"}},"fcc4b0aa708349dc91b932b85978ef5f":{"model_module":"@jupyter-widgets/base","model_module_version":"1.2.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"1.2.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"1.2.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"overflow_x":null,"overflow_y":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}}}}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"<h1 style=\"background-color: #01b0ed; color: white; text-align: center;\">Star-Fish Detection ⭐</h1>\n\n<!-- <p align=\"center\"><img src=\"https://i.ibb.co/mJH8qhY/starfish-sample.png\" alt=\"Seabed with starfish\"></p> -->\n\n<!-- <p align=\"center\"><img src=\"https://storage.googleapis.com/kaggle-media/competitions/Google-Tensorflow/video_thumb_kaggle.png\" alt=\"Seabed with starfish\"></p> -->\n\n<img src=\"https://i.ibb.co/QfM9nMs/Clouds-Convert-maxresdefault-1685913043.jpg\" alt=\"hq720\" width=1280>\n\n## Introduction\n\nThe goal of this project is to accurately identify starfish in real-time by building an object detection model trained on underwater videos of coral reefs.\n\nAustralia's stunningly beautiful Great Barrier Reef is the world’s largest coral reef and home to 1,500 species of fish, 400 species of corals, 130 species of sharks, rays, and a massive variety of other sea life.\n\nUnfortunately, the reef is under threat, in part because of the overpopulation of one particular starfish – the coral-eating crown-of-thorns starfish (or COTS for short). Scientists, tourism operators, and reef managers established a large-scale intervention program to control COTS outbreaks to ecologically sustainable levels.\n\n## Project Overview\n\nIn this object detection project, we will be training a computer vision model [YOLOv5](https://github.com/ultralytics/yolov5). While there are a galaxy of models out there, I've chosen v5 to strut its stuff on my system's dance floor – it's like the ideal dance partner for my resources! \n\nWe will try to implement different computer vision techniques such as data augmentation, splitting the frame into multiple tiles, and a bunch of different preprocessing techniques. We will also perform Hyperparameter tuning to get much out of the model and get the best model for our problem statement.","metadata":{"id":"cLlPOeqbp7ue"}},{"cell_type":"markdown","source":"**Check out notebook [here](https://github.com/lunaSnowflake/StarFish-Object-Detection#-acknowledgements) for full outputs. Don't forget to leave a like 👍 before you leave. 😀**","metadata":{}},{"cell_type":"code","source":"# Check GPU availability\n!nvidia-smi","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:22:55.585061Z","iopub.status.busy":"2023-06-01T09:22:55.584691Z","iopub.status.idle":"2023-06-01T09:22:56.637011Z","shell.execute_reply":"2023-06-01T09:22:56.635875Z","shell.execute_reply.started":"2023-06-01T09:22:55.585030Z"},"id":"fSXeziiFp7uo","outputId":"1e772add-3d48-4324-818b-dfacb45fd7fe"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Libraries","metadata":{"id":"nf_aK4L8p7us"}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\nimport ast\nfrom tqdm.notebook import tqdm\nimport IPython.display as ipd\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport cv2\n%matplotlib inline\nplt.style.use('ggplot')","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:09:33.299367Z","iopub.status.busy":"2023-06-04T05:09:33.298690Z","iopub.status.idle":"2023-06-04T05:09:33.308355Z","shell.execute_reply":"2023-06-04T05:09:33.307330Z","shell.execute_reply.started":"2023-06-04T05:09:33.299330Z"},"id":"grHP4AC9p7ut"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"HOME            = '/kaggle/working/'\nTRAIN_VID_PATH  = '/kaggle/input/tensorflow-great-barrier-reef/train_images/'","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:09:33.310423Z","iopub.status.busy":"2023-06-04T05:09:33.310036Z","iopub.status.idle":"2023-06-04T05:09:33.318010Z","shell.execute_reply":"2023-06-04T05:09:33.316970Z","shell.execute_reply.started":"2023-06-04T05:09:33.310385Z"},"id":"YUtqO2-Xp7uu"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/tensorflow-great-barrier-reef/train.csv')\ntrain_df.head()","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:09:33.321219Z","iopub.status.busy":"2023-06-04T05:09:33.319565Z","iopub.status.idle":"2023-06-04T05:09:33.365681Z","shell.execute_reply":"2023-06-04T05:09:33.364467Z","shell.execute_reply.started":"2023-06-04T05:09:33.321191Z"},"id":"XlRFlFhip7uu","outputId":"01dfdbc3-f83e-4e46-b0b2-4dcba60a14d2"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.shape","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:22:59.159514Z","iopub.status.busy":"2023-06-01T09:22:59.158834Z","iopub.status.idle":"2023-06-01T09:22:59.166023Z","shell.execute_reply":"2023-06-01T09:22:59.165066Z","shell.execute_reply.started":"2023-06-01T09:22:59.159481Z"},"id":"w0BBxJ-0p7uv","outputId":"76a63d76-2382-4f6b-b822-2c8f6859d8fd"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Preprocessing","metadata":{"id":"3Ua_Z5azp7uw"}},{"cell_type":"code","source":"def get_path(row):\n    ''' Get Frame File Path '''\n    row['image_path'] = f'{TRAIN_VID_PATH}video_{row.video_id}/{row.video_frame}.jpg'\n    return row","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:09:45.271570Z","iopub.status.busy":"2023-06-04T05:09:45.271130Z","iopub.status.idle":"2023-06-04T05:09:45.283632Z","shell.execute_reply":"2023-06-04T05:09:45.282630Z","shell.execute_reply.started":"2023-06-04T05:09:45.271534Z"},"id":"ftHpAmuPp7ux"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_new_df = train_df.copy()\ntrain_new_df = train_new_df.apply(get_path, axis=1)\ntrain_new_df['annotations'] = train_new_df['annotations'].apply(lambda x: ast.literal_eval(x))","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:09:46.101614Z","iopub.status.busy":"2023-06-04T05:09:46.101246Z","iopub.status.idle":"2023-06-04T05:10:05.394547Z","shell.execute_reply":"2023-06-04T05:10:05.393571Z","shell.execute_reply.started":"2023-06-04T05:09:46.101584Z"},"id":"7-8M_XD3p7ux"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_new_df['num_bbox'] = train_new_df['annotations'].apply(lambda x: len(x))\ntrain_new_df.head()","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:05.396705Z","iopub.status.busy":"2023-06-04T05:10:05.396373Z","iopub.status.idle":"2023-06-04T05:10:05.430816Z","shell.execute_reply":"2023-06-04T05:10:05.429851Z","shell.execute_reply.started":"2023-06-04T05:10:05.396672Z"},"id":"D77TyymMp7uy","outputId":"ca629afe-0645-4f48-bf78-91a35a89cb36"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%matplotlib inline\nfig, axs = plt.subplots(1, 3, figsize=(15,5), sharey=True)\naxs = axs.flatten()\n((train_new_df[train_new_df['video_id']==0].num_bbox>0).value_counts()/len(train_new_df[train_new_df['video_id']==0])*100).plot(kind='bar', ax=axs[0], color='0.8', title='Video 0')\n((train_new_df[train_new_df['video_id']==1].num_bbox>0).value_counts()/len(train_new_df[train_new_df['video_id']==1])*100).plot(kind='bar', ax=axs[1], color='0.8', title='Video 1')\n((train_new_df[train_new_df['video_id']==2].num_bbox>0).value_counts()/len(train_new_df[train_new_df['video_id']==2])*100).plot(kind='bar', ax=axs[2], color='0.8', title='Video 2')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2023-05-31T04:46:33.361160Z","iopub.status.busy":"2023-05-31T04:46:33.360494Z","iopub.status.idle":"2023-05-31T04:46:33.939148Z","shell.execute_reply":"2023-05-31T04:46:33.938124Z","shell.execute_reply.started":"2023-05-31T04:46:33.361125Z"},"id":"el6LgLHwp7uz","outputId":"62bdfd2c-159d-4850-ea6a-dbe74e44ed44"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### False means, the Frame has no Starfish. We can see the number of frame that are empty are more than double compared to the frame with starfish. Especially in 3rd video, the number of frames w/ no Starfish is significant.\n\n<font color='Red'> **Data is Highly Imbalance!!** </font>","metadata":{"id":"hOc2Vz3Vp7uz"}},{"cell_type":"markdown","source":"# Image EDA","metadata":{"id":"h73SsD9up7u0"}},{"cell_type":"code","source":"def show_img(img, size=12):\n    ''' plot image inline '''\n    if not img is None:\n        plt.figure(figsize=(size,size))\n        plt.imshow(img)\n        plt.axis('off')\n        plt.show()","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:15.660837Z","iopub.status.busy":"2023-06-04T05:10:15.660480Z","iopub.status.idle":"2023-06-04T05:10:15.666480Z","shell.execute_reply":"2023-06-04T05:10:15.665488Z","shell.execute_reply.started":"2023-06-04T05:10:15.660807Z"},"id":"KKA6puTmp7u0"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def scrap_annotation(annot_str):\n    ''' change string list to actual list '''\n    res = ast.literal_eval(annot_str)\n    return res","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:15.669705Z","iopub.status.busy":"2023-06-04T05:10:15.668961Z","iopub.status.idle":"2023-06-04T05:10:15.682029Z","shell.execute_reply":"2023-06-04T05:10:15.676673Z","shell.execute_reply.started":"2023-06-04T05:10:15.669672Z"},"id":"b3GId0vOp7u0"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def annot_img(img, annots):\n    ''' Apply annotations (Bounding Boxes) to a frame '''\n    img_cp = img.copy()\n    if len(annots) > 0:\n        for annot in annots:\n            pt1 = annot['x'], annot['y']\n            pt2 = annot['x'] + annot['width'], annot['y'] + annot['height']\n            cv2.rectangle(img_cp, pt1, pt2, color=(255,133,0), thickness=2)\n    return img_cp","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:16.226848Z","iopub.status.busy":"2023-06-04T05:10:16.225871Z","iopub.status.idle":"2023-06-04T05:10:16.234229Z","shell.execute_reply":"2023-06-04T05:10:16.233209Z","shell.execute_reply.started":"2023-06-04T05:10:16.226811Z"},"id":"dmntOrGmp7u1"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_num = 16\nimg = cv2.imread(f'{TRAIN_VID_PATH}video_0/{img_num}.jpg')[...,::-1]\nshow_img(img)","metadata":{"execution":{"iopub.execute_input":"2023-05-15T04:29:57.478718Z","iopub.status.busy":"2023-05-15T04:29:57.478188Z","iopub.status.idle":"2023-05-15T04:29:58.148311Z","shell.execute_reply":"2023-05-15T04:29:58.147065Z","shell.execute_reply.started":"2023-05-15T04:29:57.478679Z"},"id":"8cOdJJndp7u1","outputId":"d3639428-0125-4a47-bef9-c83d35af2bee"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"annots = scrap_annotation((train_df[((train_df.video_id==0) & (train_df.video_frame==img_num))]['annotations'].values)[0])\nprint(annots)\nimg_cp = annot_img(img, annots)\nshow_img(img_cp, 16)","metadata":{"execution":{"iopub.execute_input":"2023-05-15T04:29:58.153288Z","iopub.status.busy":"2023-05-15T04:29:58.152739Z","iopub.status.idle":"2023-05-15T04:29:59.185247Z","shell.execute_reply":"2023-05-15T04:29:59.177751Z","shell.execute_reply.started":"2023-05-15T04:29:58.153253Z"},"id":"_9StPqIYp7u2","outputId":"54850409-96a6-4505-fe0d-dee5ad831d7f"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_num = 101\nimg = cv2.imread(f'{TRAIN_VID_PATH}video_0/{img_num}.jpg')[...,::-1]\nannots = scrap_annotation((train_df[((train_df.video_id==0) & (train_df.video_frame==img_num))]['annotations'].values)[0])\nprint(annots)\nimg_cp = annot_img(img, annots)\nshow_img(img_cp, 16)","metadata":{"execution":{"iopub.execute_input":"2023-05-15T04:29:59.811545Z","iopub.status.busy":"2023-05-15T04:29:59.810358Z","iopub.status.idle":"2023-05-15T04:30:00.610747Z","shell.execute_reply":"2023-05-15T04:30:00.609684Z","shell.execute_reply.started":"2023-05-15T04:29:59.811493Z"},"id":"Wfu--Ve0p7u2","outputId":"da6193d5-9db8-4b36-cb3e-8fb5b97f0d06"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_num = 461\nimg = cv2.imread(f'{TRAIN_VID_PATH}video_1/{img_num}.jpg')[...,::-1]\nannots = scrap_annotation((train_df[((train_df.video_id==1) & (train_df.video_frame==img_num))]['annotations'].values)[0])\nprint(annots)\nimg_cp = annot_img(img, annots)\nshow_img(img_cp, 16)","metadata":{"execution":{"iopub.execute_input":"2023-05-15T04:30:01.263487Z","iopub.status.busy":"2023-05-15T04:30:01.262910Z","iopub.status.idle":"2023-05-15T04:30:02.146314Z","shell.execute_reply":"2023-05-15T04:30:02.145347Z","shell.execute_reply.started":"2023-05-15T04:30:01.263451Z"},"id":"dLEnEES0p7u3","outputId":"8a67c646-ee46-4f34-9177-ef3d395859d7"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_num = 5754\nimg = cv2.imread(f'{TRAIN_VID_PATH}video_2/{img_num}.jpg')[...,::-1]\nannots = scrap_annotation((train_df[((train_df.video_id==2) & (train_df.video_frame==img_num))]['annotations'].values)[0])\nprint(annots)\nimg_cp = annot_img(img, annots)\nshow_img(img_cp, 16)","metadata":{"execution":{"iopub.execute_input":"2023-05-15T04:30:02.799321Z","iopub.status.busy":"2023-05-15T04:30:02.798946Z","iopub.status.idle":"2023-05-15T04:30:03.646218Z","shell.execute_reply":"2023-05-15T04:30:03.643767Z","shell.execute_reply.started":"2023-05-15T04:30:02.799280Z"},"id":"uSmRqT3Ap7u4","outputId":"4903a5a7-59e9-4c70-f606-32dacf23c465"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### We can notice, the starfish as an object is very small.\n#### It camouflages perfectly with the seabed, making it harder to detect (even with the naked eye).\n\n#### The one important feature to distinguish starfish and seabed, is its arms.","metadata":{"id":"54Nlp2GSp7u4"}},{"cell_type":"code","source":"''' The frames of all the videos in our case have same resolution of (720, 1280).\n    If that would not be the case we would have applied technique like resizing.\n'''\nIMAGE_HEIGHT, IMAGE_WIDTH = cv2.imread(f'{TRAIN_VID_PATH}video_0/0.jpg').shape[:2]","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:21.139360Z","iopub.status.busy":"2023-06-04T05:10:21.138977Z","iopub.status.idle":"2023-06-04T05:10:21.203646Z","shell.execute_reply":"2023-06-04T05:10:21.202704Z","shell.execute_reply.started":"2023-06-04T05:10:21.139328Z"},"id":"QwJrt1T2p7u5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''' Formats of bbox cordinates '''\ndef coco2voc(bboxes):\n    \"\"\"\n        coco => [xmin, ymin, w, h]\n        voc  => [x1, y1, x2, y2]\n    \"\"\"\n    bboxes[2] = bboxes[0] + bboxes[2]\n    bboxes[3] = bboxes[1] + bboxes[3]\n    return bboxes\n\ndef voc2coco(bboxes):\n    \"\"\"\n        voc  => [x1, y1, x2, y2]\n        coco => [xmin, ymin, w, h]\n    \"\"\"\n    bboxes[2] = bboxes[2] - bboxes[0]\n    bboxes[3] = bboxes[3] - bboxes[1]\n    return bboxes\n\ndef coco2yolo(annot, image_width=IMAGE_WIDTH, image_height=IMAGE_HEIGHT):\n    \"\"\"\n        coco => [xmin, ymin, w, h] (denormalized)\n        yolo => [xcen, ycen, w, h] (normalized)\n    \"\"\"\n    try: \n        x_min = annot['x']\n        y_min = annot['y']\n        x_max = annot['x'] + annot['width']\n        y_max = annot['y'] + annot['height']\n    except:\n        x_min = annot[0]\n        y_min = annot[1]\n        x_max = annot[0] + annot[2]\n        y_max = annot[1] + annot[3]\n    \n    # calculate normalized bounding box coordinates\n    x_cen = (x_min + x_max) / (2.0 * image_width)\n    y_cen = (y_min + y_max) / (2.0 * image_height)\n    w = (x_max - x_min) / image_width\n    h = (y_max - y_min) / image_height\n    \n    return [np.round(elem,6) for elem in [x_cen, y_cen, w, h]]\n\ndef yolo2coco(annot, image_width=IMAGE_WIDTH, image_height=IMAGE_HEIGHT):\n    \"\"\"\n        yolo => [xcen, ycen, w, h] (normalized)\n        coco => [xmin, ymin, w, h] (denormalized)\n    \"\"\"\n    x_cen = annot[0]\n    y_cen = annot[1]\n    w = annot[2]\n    h = annot[3]\n    \n    # calculate denormalized bounding box coordinates\n    x_min = (x_cen - (w / 2.0)) * image_width\n    y_min = (y_cen - (h / 2.0)) * image_height\n    x_max = (x_cen + (w / 2.0)) * image_width\n    y_max = (y_cen + (h / 2.0)) * image_height\n    \n    w = x_max - x_min\n    h = y_max - y_min\n    \n    return [np.round(elem,6) for elem in [x_min, y_min, w, h]]","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:21.557072Z","iopub.status.busy":"2023-06-04T05:10:21.556680Z","iopub.status.idle":"2023-06-04T05:10:21.569551Z","shell.execute_reply":"2023-06-04T05:10:21.568389Z","shell.execute_reply.started":"2023-06-04T05:10:21.557041Z"},"id":"dhcSfTecp7u5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"object_centers = []\nfor row in tqdm(train_new_df.iterrows(), total=len(train_new_df)):\n    row = row[1]\n    for annot in row['annotations']:        \n        x_cen, y_cen, w, h = coco2yolo(annot)\n        object_centers.append([x_cen, y_cen])","metadata":{"execution":{"iopub.execute_input":"2023-05-21T02:48:57.145777Z","iopub.status.busy":"2023-05-21T02:48:57.145292Z","iopub.status.idle":"2023-05-21T02:48:58.459437Z","shell.execute_reply":"2023-05-21T02:48:58.458528Z","shell.execute_reply.started":"2023-05-21T02:48:57.145745Z"},"id":"15gpMeaBp7u6","outputId":"6c3a554f-8ea5-4d61-c495-064ed194f548"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = object_centers\na = [x[0] for x in data]\nb = [x[1] for x in data]\n\n# plot\nplt.figure(figsize=(13, 8))\nplt.scatter(a, b, s=50, marker='s', alpha=0.6, edgecolors='none', c=sns.xkcd_rgb['sea blue'])\nplt.xlim(0, 1); plt.ylim(0, 1)\nplt.title('Star Fish Distribution along the frame')\nplt.xlabel('X co-ordinates'); plt.ylabel('Y co-ordinates')\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2023-05-21T02:51:25.860043Z","iopub.status.busy":"2023-05-21T02:51:25.859686Z","iopub.status.idle":"2023-05-21T02:51:26.333606Z","shell.execute_reply":"2023-05-21T02:51:26.332618Z","shell.execute_reply.started":"2023-05-21T02:51:25.860014Z"},"id":"yVVGkntEp7u6","outputId":"ea7cfeaf-3613-421f-913b-4741e649105b"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train-Dev-Test split","metadata":{"id":"N9DALmaAp7u7"}},{"cell_type":"code","source":"def train_dev_test_split(data):\n    '''\n        Train-Dev-Test Split (0.7-0.15-0.15);\n        From each video take images w/ and w/o starfish in the ratio of 80:20\n    '''\n    np.random.seed(42)\n    \n    train = pd.DataFrame()\n    val = pd.DataFrame()\n    test = pd.DataFrame()\n    for i in range(3):\n        data_main = (data[data['video_id']==i]).sort_values('video_frame')\n        \n        # split frames type\n        data_1 = data_main[data_main['num_bbox']>0]  # w/ starfish\n        data_0 = data_main[data_main['num_bbox']==0] # w/o starfish\n        \n        # select only subset of frames (as lot of the frame have same pixels with little to no variation)\n        data_1 = data_1.sample(frac=0.3)\n        data_0 = data_0.sample(frac=0.3)\n        \n        ''' Train 70 % '''\n        data_temp = data_1.sample(frac=0.7)\n        train = pd.concat((train, data_temp))\n        data_1 = data_1[~data_1.index.isin(data_temp.index)]\n        frac_20 = ( ( ( len(data_temp) * 100 ) / 80 ) - len(data_temp) ) / len(data_0) # 20 % of images w/ starfish\n        data_temp = data_0.sample(frac=frac_20)\n        train = pd.concat((train, data_temp))\n        data_0 = data_0[~data_0.index.isin(data_temp.index)]\n        \n        ''' Val 15 % '''\n        data_temp = data_1.sample(frac=0.5)\n        val = pd.concat((val, data_temp))\n        data_1 = data_1[~data_1.index.isin(data_temp.index)]\n        frac_20 = ( ( ( len(data_temp) * 100 ) / 80 ) - len(data_temp) ) / len(data_0) # 20 % of images w/ starfish\n        data_temp = data_0.sample(frac=frac_20)\n        val = pd.concat((val, data_temp))\n        data_0 = data_0[~data_0.index.isin(data_temp.index)]\n        \n        ''' Test 15 % '''\n        data_temp = data_1.sample(frac=1)\n        test = pd.concat((test, data_temp))\n        frac_20 = ( ( ( len(data_temp) * 100 ) / 80 ) - len(data_temp) ) / len(data_0) # 20 % of images w/ starfish\n        data_temp = data_0.sample(frac=frac_20)\n        test = pd.concat((test, data_temp))\n        \n    return train, val, test","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:27.718528Z","iopub.status.busy":"2023-06-04T05:10:27.717855Z","iopub.status.idle":"2023-06-04T05:10:27.730499Z","shell.execute_reply":"2023-06-04T05:10:27.729438Z","shell.execute_reply.started":"2023-06-04T05:10:27.718493Z"},"id":"wGWzqmCLp7u7"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train, val, test = train_dev_test_split(train_new_df)\ntrain.shape, val.shape, test.shape","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:28.135973Z","iopub.status.busy":"2023-06-04T05:10:28.135210Z","iopub.status.idle":"2023-06-04T05:10:28.194956Z","shell.execute_reply":"2023-06-04T05:10:28.194028Z","shell.execute_reply.started":"2023-06-04T05:10:28.135909Z"},"id":"7DPusVNAp7u8","outputId":"12027095-6731-455e-8824-34f96187c90e"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%matplotlib inline\nfig, axs = plt.subplots(1, 3, figsize=(15,5), sharey=True)\naxs = axs.flatten()\n((train.num_bbox>0).value_counts()/len(train)).plot(kind='bar', ax=axs[0], color='0.7', title='Train')\n((val.num_bbox>0).value_counts()/len(val)).plot(kind='bar', ax=axs[1], color='0.7', title='Val')\n((test.num_bbox>0).value_counts()/len(test)).plot(kind='bar', ax=axs[2], color='0.7', title='Test')\nplt.tight_layout()\nplt.show()","metadata":{"execution":{"iopub.execute_input":"2023-05-21T02:52:07.661161Z","iopub.status.busy":"2023-05-21T02:52:07.660672Z","iopub.status.idle":"2023-05-21T02:52:08.469931Z","shell.execute_reply":"2023-05-21T02:52:08.468910Z","shell.execute_reply.started":"2023-05-21T02:52:07.661115Z"},"id":"0tJ_4vT7p7u8","outputId":"3f3cead4-87c3-49f6-ab23-5ed35c2541cd"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### True    - Frame w/ objects\n#### False  - Frame w/o objects\n\n#### We have now Train-Dev-Test set with 80:20 ratio of frame.\n#### Remember We have kept frames with no object so to train the model also for empty frames.","metadata":{"id":"OdzTwU6Yp7u9"}},{"cell_type":"markdown","source":"# Prepare Images and Labels Directory for training","metadata":{"id":"TsmKimVMp7u9"}},{"cell_type":"code","source":"import shutil\n\ndef make_images_dir(data, dest):\n    ''' change images path '''\n    os.makedirs(dest, exist_ok=True)\n    for row in tqdm(data.iterrows(), total=len(data)):\n        row = row[1]\n        image_id = row['image_id']\n        scr = row['image_path']\n        shutil.copyfile(scr, f\"{dest}/{image_id}.jpg\")","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:31.277732Z","iopub.status.busy":"2023-06-04T05:10:31.277364Z","iopub.status.idle":"2023-06-04T05:10:31.283732Z","shell.execute_reply":"2023-06-04T05:10:31.282758Z","shell.execute_reply.started":"2023-06-04T05:10:31.277701Z"},"id":"eKrc06Ewp7u9"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"make_images_dir(train, dest=f'{HOME}img_data/images/train')\nmake_images_dir(val, dest=f'{HOME}img_data/images/val')","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:10:34.284480Z","iopub.status.busy":"2023-06-04T05:10:34.283980Z","iopub.status.idle":"2023-06-04T05:11:04.754095Z","shell.execute_reply":"2023-06-04T05:11:04.752982Z","shell.execute_reply.started":"2023-06-04T05:10:34.284452Z"},"id":"5bAlsU9bp7u9","outputId":"6dc85dcf-255f-4bb1-f98a-751fbe30708a"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls {HOME}/img_data/images -GFlash --color\n!ls {HOME}/img_data/images/train | wc -l\n!ls {HOME}/img_data/images/val | wc -l","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:23:44.665231Z","iopub.status.busy":"2023-06-01T09:23:44.664309Z","iopub.status.idle":"2023-06-01T09:23:47.552509Z","shell.execute_reply":"2023-06-01T09:23:47.551206Z","shell.execute_reply.started":"2023-06-01T09:23:44.665194Z"},"id":"p4tz_OUMp7vJ","outputId":"8f7fe56c-1431-4246-d68a-1ccdc9f15812"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Make Yolo Annotation file","metadata":{"id":"lo71DftMp7vJ"}},{"cell_type":"code","source":"def yolo_annotations_dir(data, dest):\n    ''' Make YOLO format Annotation file for each frame '''\n    \n    # Class\n    class_id = 0 #Start Fish\n    \n    os.makedirs(dest, exist_ok=True)\n    \n    # Iterate DataFrame\n    for row in tqdm(data.iterrows(), total=len(data)):\n        row = row[1]\n        image_id = row['image_id']\n\n        # Write to Yolo Format\n        with open(f'{dest}/{image_id}.txt', 'w') as f:\n            for annot in row['annotations']:\n                x_cen, y_cen, w, h = coco2yolo(annot)\n\n                # write YOLO formatted data to a text file\n                line = f\"{class_id} {x_cen:.6f} {y_cen:.6f} {w:.6f} {h:.6f}\\n\"\n                f.write(line)","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:04.756827Z","iopub.status.busy":"2023-06-04T05:11:04.756214Z","iopub.status.idle":"2023-06-04T05:11:04.766598Z","shell.execute_reply":"2023-06-04T05:11:04.764776Z","shell.execute_reply.started":"2023-06-04T05:11:04.756790Z"},"id":"iofMH5L7p7vK"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"yolo_annotations_dir(train, dest=f'{HOME}img_data/labels/train')\nyolo_annotations_dir(val, dest=f'{HOME}img_data/labels/val')","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:04.768585Z","iopub.status.busy":"2023-06-04T05:11:04.768011Z","iopub.status.idle":"2023-06-04T05:11:05.328605Z","shell.execute_reply":"2023-06-04T05:11:05.327496Z","shell.execute_reply.started":"2023-06-04T05:11:04.768552Z"},"id":"3CBVSN10p7vK","outputId":"4ef79a39-4b2c-4e3c-c019-60eb3b49f0db"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls {HOME}/img_data/labels -GFlash --color\n!ls {HOME}/img_data/labels/train | wc -l\n!ls {HOME}/img_data/labels/val | wc -l","metadata":{"execution":{"iopub.execute_input":"2023-05-28T04:46:02.898685Z","iopub.status.busy":"2023-05-28T04:46:02.898300Z","iopub.status.idle":"2023-05-28T04:46:05.858210Z","shell.execute_reply":"2023-05-28T04:46:05.856957Z","shell.execute_reply.started":"2023-05-28T04:46:02.898655Z"},"id":"moJ0ZsXVp7vK","outputId":"719a27b2-d185-4716-ff4e-36d2a1e407e1"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Install Yolov5","metadata":{"id":"svUkpcrgp7vL"}},{"cell_type":"code","source":"!git clone https://github.com/ultralytics/yolov5  # clone\n%cd {HOME}yolov5\n%pip install -qr requirements.txt","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:05.332060Z","iopub.status.busy":"2023-06-04T05:11:05.331667Z","iopub.status.idle":"2023-06-04T05:11:36.896519Z","shell.execute_reply":"2023-06-04T05:11:36.895017Z","shell.execute_reply.started":"2023-06-04T05:11:05.332025Z"},"id":"slPFp1L2p7vL","outputId":"6924392d-7f66-405a-ea0c-9214c7a991b6"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Make Custom Data YAML file","metadata":{"id":"jNNG6_X9p7vL"}},{"cell_type":"code","source":"# with open(f'/kaggle/working/yolov5/data/coco128.yaml', 'r') as f:\n#     print(f.read())","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:36.900297Z","iopub.status.busy":"2023-06-04T05:11:36.899823Z","iopub.status.idle":"2023-06-04T05:11:36.910240Z","shell.execute_reply":"2023-06-04T05:11:36.903883Z","shell.execute_reply.started":"2023-06-04T05:11:36.900252Z"},"id":"YIL86XM6p7vL"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def update_data_yaml(yaml_path, path, train_path, val_path, test_path):\n    ''' Make Custom Data YAML File '''\n    \n    yaml_script = f'''# Custom Dataset of Star Fish - created by Sain\n\n# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]\npath: {path}  # dataset root dir\ntrain: {train_path}  # train images (relative to 'path')\nval: {val_path}  # val images (relative to 'path')\ntest: {test_path} # test images (optional)\n\n# Classes\nnames:\n 0: starfish\n'''\n    \n    # update\n    with open(yaml_path, 'w') as f:\n        f.write(yaml_script)\n    \n    # Check\n    with open(yaml_path, 'r') as f:\n        print(f.read())","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:36.912547Z","iopub.status.busy":"2023-06-04T05:11:36.911901Z","iopub.status.idle":"2023-06-04T05:11:37.033544Z","shell.execute_reply":"2023-06-04T05:11:37.032478Z","shell.execute_reply.started":"2023-06-04T05:11:36.912506Z"},"id":"ha8BrwUXp7vM"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Update Yaml\nyaml_path   = f\"{HOME}/yolov5/data/starfish.yaml\"\npath        = f'{HOME}img_data'\ntrain_path  = 'images/train'\nval_path    = 'images/val'\ntest_path   = ''\nupdate_data_yaml(yaml_path, path, train_path, val_path, test_path)","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:37.035549Z","iopub.status.busy":"2023-06-04T05:11:37.035162Z","iopub.status.idle":"2023-06-04T05:11:37.049793Z","shell.execute_reply":"2023-06-04T05:11:37.048679Z","shell.execute_reply.started":"2023-06-04T05:11:37.035512Z"},"id":"P6xcibr1p7vM","outputId":"16cee176-0d94-408d-f972-cf8f21ad903e"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train\n\n## Yolo Architecture\n<img src=\"https://blog.roboflow.com/content/images/2020/08/image-33.png\" alt=\"Yolo Architecture\" style=\"width: 1000px; height: auto;\">\n\n## Loss Function of Yolov5\nThe loss function is composition of several individual loss components, each addressing a specific aspect of the model's performance.\n\n### The YOLOv5 model commonly uses three main loss components:\n\n- **Box (Localization) Loss:** This loss measures the discrepancy between the predicted bounding box coordinates (x, y, width, height) and the ground truth box coordinates. It encourages the model to accurately localize objects by minimizing the differences between the predicted and actual box parameters.\n\n- **Class Loss:** The class loss is calculated based on the predicted class probabilities and the ground truth class labels. It penalizes incorrect class predictions and encourages the model to accurately classify the detected objects.\n\n- **Objectness Loss:** The objectness loss is related to the confidence scores assigned to each bounding box. It measures the discrepancy between the predicted objectness scores (indicating the presence of an object) and the ground truth objectness labels. This loss encourages the model to predict high confidence scores for true positive detections and low scores for false positives and background regions.\n<br>\nThe overall loss function is typically a weighted sum of these individual loss components. The weights assigned to each loss term, such as box, cls, and obj is a Hyperparameter that can be adjusted.","metadata":{"id":"X3ZY74x2p7vM"}},{"cell_type":"code","source":"''' Set Logger '''\n\nlogger = 'Comet'  # ref: https://docs.ultralytics.com/yolov5/tutorials/comet_logging_integration/\n    \nif logger == 'Comet':\n    \n    # Install Commet\n    !pip install -q comet_ml\n    ipd.clear_output(wait=True)\n    \n    # Import Comet API Key from kaggle secret (Add-ons > secret)\n    from kaggle_secrets import UserSecretsClient\n    secret_label = \"COMET_API\"\n    secret_value = UserSecretsClient().get_secret(secret_label)\n    \n    # Initialize Comet\n    import comet_ml\n    comet_ml.init(api_key=secret_value, project_name='StarFish-Yolov5')\n    \nelif logger == 'ClearML':\n    \n    !pip install -q clearml\n    ipd.clear_output(wait=True)\n    import clearml; clearml.browser_login()\n    \nelif logger == 'TensorBoard':\n    \n    !load_ext tensorboard\n    %tensorboard --logdir runs/train","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:37.052180Z","iopub.status.busy":"2023-06-04T05:11:37.051405Z","iopub.status.idle":"2023-06-04T05:11:52.470991Z","shell.execute_reply":"2023-06-04T05:11:52.469896Z","shell.execute_reply.started":"2023-06-04T05:11:37.052145Z"},"id":"d0CTGHxJp7vN"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_yolo_results(result_png, path, row=1, col=1, sizeR=30, sizeC=30):\n    ''' Plot Yolo Result Images '''\n    \n    plt.rcParams.update({'font.size': 18}) # set font size to 18\n    fig, axs = plt.subplots(row, col, figsize=(sizeR, sizeC))\n    \n    if (row==1 and col==1) or (len(result_png) == 1):\n        \n        for i in range(len(result_png)):\n            \n            img = cv2.imread(f\"{path}/{result_png[i]}\")[...,::-1]\n            axs.imshow(img)\n            axs.set_title(result_png[i][:-4])\n            axs.axis('off')\n            \n    else:\n        \n        axs = axs.flatten()\n        \n        for i in range(len(result_png)):\n            \n            img = cv2.imread(f\"{path}/{result_png[i]}\")[...,::-1]\n            axs[i].imshow(img)\n            axs[i].set_title(result_png[i][:-4])\n            axs[i].axis('off')\n\n    plt.tight_layout()\n    plt.show()\n\ndef update_hyperparameter_yaml(hyperparams, make_new = False):\n    ''' Make Custom Hyperparameter YAML File '''\n    \n    # make a copy of original hyp yaml file    \n    source_file = f'{HOME}/yolov5/data/hyps/hyp.scratch-low.yaml'\n    destination_file = f'{HOME}/yolov5/data/hyps/hyp.starfish.yaml'\n    if make_new:\n        shutil.copy(source_file, destination_file)\n    else:\n        if not os.path.exists(destination_file):\n            shutil.copy(source_file, destination_file)\n\n    # Read the content of the file\n    with open(destination_file, 'r') as file:\n        content = file.read()\n\n    # Update each hyperparameter\n    for key in hyperparams.keys():\n\n        # Replace the value of mixup\n        n1 = content.find(key)\n        n2 = content.find('#', n1)\n        find_str = content[n1:n2].strip()\n        replace_str = key + ': ' + str(hyperparams[key])\n        print(f'Changing Hyperparameter \"{find_str}\" with \"{replace_str}\"')\n        content = content.replace(find_str, replace_str)\n    \n    # Write the modified content back to the file\n    with open(destination_file, 'w') as file:\n        file.write(content)\n\n    # Check\n    with open(destination_file, 'r') as f:\n        print('\\n', f.read())\n\nimport urllib.request\ndef download_custom_model(link, name='best.pt'):\n    ''' Download custom trained model '''\n    filepath = f'{HOME}{name}'\n    urllib.request.urlretrieve(link, filepath) # !wget {link} -O {filepath}\n    return filepath","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:52.473265Z","iopub.status.busy":"2023-06-04T05:11:52.472820Z","iopub.status.idle":"2023-06-04T05:11:52.489844Z","shell.execute_reply":"2023-06-04T05:11:52.488604Z","shell.execute_reply.started":"2023-06-04T05:11:52.473223Z"},"id":"atOCQC7Hp7vN"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\ndevice = 'cuda:0' if torch.cuda.is_available() else 'cpu'\n# empty the cache to free up GPU memory\ntorch.cuda.empty_cache()","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:52.493895Z","iopub.status.busy":"2023-06-04T05:11:52.493553Z","iopub.status.idle":"2023-06-04T05:11:55.556694Z","shell.execute_reply":"2023-06-04T05:11:55.555729Z","shell.execute_reply.started":"2023-06-04T05:11:52.493863Z"},"id":"zDEdkNBtp7vO"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''\nPyTorch's memory management configuration to avoid fragmentation is a way to avoid memory fragmentation, \nwhich can occur when memory is allocated and deallocated multiple times, leaving smaller chunks of memory that are not large enough to be used. \nThis can lead to inefficient memory usage and decreased performance.\n\nThe configuration setting max_split_size_mb specifies the maximum size of a contiguous memory block that can be split into smaller pieces.\nBy setting this value appropriately, PyTorch can avoid creating too many small memory blocks, which can lead to memory fragmentation.\n\nHowever, setting max_split_size_mb too small can also reduce the amount of available memory, as larger contiguous blocks may not be split when needed. \nTherefore, it is important to find a balance between reducing fragmentation and maintaining enough available memory for the application.\n'''\ntorch.backends.cuda.max_split_size_mb = 1024 # set it to 1GB","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:55.559055Z","iopub.status.busy":"2023-06-04T05:11:55.558321Z","iopub.status.idle":"2023-06-04T05:11:55.566422Z","shell.execute_reply":"2023-06-04T05:11:55.563502Z","shell.execute_reply.started":"2023-06-04T05:11:55.559019Z"},"id":"UsZywAG2p7vO"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 1: Initial Training on Yolov5 's' model\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights yolov5s.pt \\\n    --img 1280 \\\n    --batch 16 \\\n    --epoch 30 \\\n    --data starfish.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --hyp data/hyps/hyp.scratch-low.yaml \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-05-19T09:49:42.257586Z","iopub.status.busy":"2023-05-19T09:49:42.257208Z","iopub.status.idle":"2023-05-19T11:11:01.121838Z","shell.execute_reply":"2023-05-19T11:11:01.120616Z","shell.execute_reply.started":"2023-05-19T09:49:42.257557Z"},"id":"4LyOmamGp7vP","outputId":"219fd208-4162-495d-f65d-647980f666e8"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Training Result\n| Epoch | Batch_size | Precision | Recall | mAP50 | mAP50:95 | Training Comment\n| :--: | :--: | :--: | :--: | :--: | :--: | :--: |\n| 30 | 16 | 0.928 | 0.839 | 0.904 | 0.492 | Simple Training |\n\nWe have a pretty good Precision and Recall, we can try to increase mAP50:95 further!","metadata":{"id":"6GIOFCVMp7vQ"}},{"cell_type":"markdown","source":"**We can Increase iou_t (iou_threshold) to eleminate more close bbox in NMS, by doing this we are saying, we are confident objects will not be very close, and hopefully this will reduce False Positives!**","metadata":{"id":"AZPdnFjBp7vR"}},{"cell_type":"code","source":"# Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish7/weights/best.pt')\n\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish7/weights/best.pt', f'{HOME}/best.pt')\n# !cp {HOME}/yolov5/runs/train/custom_starfish7/weights/best.pt {HOME}","metadata":{"execution":{"iopub.execute_input":"2023-05-19T11:45:42.597341Z","iopub.status.busy":"2023-05-19T11:45:42.596454Z","iopub.status.idle":"2023-05-19T11:45:43.588934Z","shell.execute_reply":"2023-05-19T11:45:43.587441Z","shell.execute_reply.started":"2023-05-19T11:45:42.597294Z"},"id":"Zkz6CtwYp7vS"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### From the Log Analysis (CometML), the loss can be reduce further.\n#### This time also let's add Mixup Augmentation to Training","metadata":{"id":"6Hj81t-dp7vS"}},{"cell_type":"code","source":"# Download my custom previous trained model\nlink = 'https://docs.google.com/uc?export=download&id=1xpcpIFkO59bjfsYqC0BADZRydUGoUohN'\ndownload_custom_model(link, name='best.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-20T04:12:02.076053Z","iopub.status.busy":"2023-05-20T04:12:02.075339Z","iopub.status.idle":"2023-05-20T04:12:05.375506Z","shell.execute_reply":"2023-05-20T04:12:05.374229Z","shell.execute_reply.started":"2023-05-20T04:12:02.076015Z"},"id":"5f7priU3p7vS","outputId":"358621dd-34ca-46bf-deeb-aa9e1d1dd81f"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Allow Mixup Augmentation with Probability 0.6\nupdate_hyperparameter_yaml({'mixup' : 0.6})","metadata":{"execution":{"iopub.execute_input":"2023-05-20T07:35:21.111736Z","iopub.status.busy":"2023-05-20T07:35:21.110928Z","iopub.status.idle":"2023-05-20T07:35:21.132007Z","shell.execute_reply":"2023-05-20T07:35:21.128878Z","shell.execute_reply.started":"2023-05-20T07:35:21.111685Z"},"id":"92DR47bNp7vT","outputId":"61275b97-4c88-476e-b4ec-4e019b1a8868"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 2: Load Last Checkpoint, and train for another 40 epochs\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights {HOME}/best.pt \\\n    --img 1280 \\\n    --batch 16 \\\n    --epoch 40 \\\n    --data starfish.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --hyp data/hyps/hyp.starfish.yaml \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-05-20T04:24:45.030589Z","iopub.status.busy":"2023-05-20T04:24:45.030175Z"},"id":"gSen0VqUp7vT","outputId":"5f59139e-c53b-4653-ec00-cc2f5aee01f5"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We got a improvement over Recall and mAP50, but Precision minor affected.","metadata":{"id":"_DXdsk73p7vT"}},{"cell_type":"code","source":"# Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish/weights/best.pt', f'{HOME}/best2.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-20T07:10:12.688178Z","iopub.status.busy":"2023-05-20T07:10:12.687750Z","iopub.status.idle":"2023-05-20T07:10:12.695444Z","shell.execute_reply":"2023-05-20T07:10:12.694453Z","shell.execute_reply.started":"2023-05-20T07:10:12.688144Z"},"id":"L9BK7L-xp7vT"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot yolo result\nresult_png = ['confusion_matrix.png']\n\nplot_yolo_results(result_png, path=f'{HOME}/yolov5/runs/train/custom_starfish', sizeR=8, sizeC=8)","metadata":{"execution":{"iopub.execute_input":"2023-05-20T07:22:49.302289Z","iopub.status.busy":"2023-05-20T07:22:49.301217Z","iopub.status.idle":"2023-05-20T07:22:50.467373Z","shell.execute_reply":"2023-05-20T07:22:50.466344Z","shell.execute_reply.started":"2023-05-20T07:22:49.302235Z"},"id":"cNbUNUqup7vU","outputId":"ef81486c-77e1-4f75-e5f2-fccd6dcde914"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot yolo result\nresult_png = ['val_batch0_labels.jpg',\n              'val_batch0_pred.jpg',]\n\nplot_yolo_results(result_png, path=f'{HOME}/yolov5/runs/train/custom_starfish', row=2, col=1)","metadata":{"execution":{"iopub.execute_input":"2023-05-20T07:26:01.148646Z","iopub.status.busy":"2023-05-20T07:26:01.147253Z","iopub.status.idle":"2023-05-20T07:26:06.754936Z","shell.execute_reply":"2023-05-20T07:26:06.752496Z","shell.execute_reply.started":"2023-05-20T07:26:01.148603Z"},"id":"sKYVwlSZp7vU","outputId":"a52aa462-4e4b-4f55-d0e1-bc50e9ed94c6"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''' \n    Lets increase the emphasis on loss component: Box loss gain 'box', to prioritize accurate localization of objects\n    also lets try reducing Class loss gain 'cls' component effect as we just have 1 object class\n'''\nupdate_hyperparameter_yaml({'box': '0.5', 'cls': '0.2'})","metadata":{"execution":{"iopub.execute_input":"2023-05-20T07:51:33.082502Z","iopub.status.busy":"2023-05-20T07:51:33.082066Z","iopub.status.idle":"2023-05-20T07:51:33.096474Z","shell.execute_reply":"2023-05-20T07:51:33.094608Z","shell.execute_reply.started":"2023-05-20T07:51:33.082463Z"},"id":"W4Bkel6Yp7vU","outputId":"d355b23c-aff4-4980-bd55-2c916752e854"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 3: Load Last Checkpoint, and train for another 10 epochs\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights {HOME}/best2.pt \\\n    --img 1280 \\\n    --batch 16 \\\n    --epoch 10 \\\n    --data starfish.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --hyp data/hyps/hyp.starfish.yaml \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-05-20T07:51:39.614918Z","iopub.status.busy":"2023-05-20T07:51:39.614525Z","iopub.status.idle":"2023-05-20T08:33:13.793390Z","shell.execute_reply":"2023-05-20T08:33:13.791340Z","shell.execute_reply.started":"2023-05-20T07:51:39.614887Z"},"id":"JCzUjzICp7vV","outputId":"9e57421b-fce1-4145-825b-c0981f6eb9ba"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish3/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish3/weights/best.pt', f'{HOME}/best3.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-20T08:45:24.594783Z","iopub.status.busy":"2023-05-20T08:45:24.594292Z","iopub.status.idle":"2023-05-20T08:45:24.599817Z","shell.execute_reply":"2023-05-20T08:45:24.598815Z","shell.execute_reply.started":"2023-05-20T08:45:24.594745Z"},"id":"t8lAAhyxp7vV"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot yolo result\nresult_png = ['confusion_matrix.png']\n\nplot_yolo_results(result_png, path=f'{HOME}/yolov5/runs/train/custom_starfish3', sizeR=8, sizeC=8)","metadata":{"execution":{"iopub.execute_input":"2023-05-20T08:44:26.860631Z","iopub.status.busy":"2023-05-20T08:44:26.860184Z","iopub.status.idle":"2023-05-20T08:44:27.999375Z","shell.execute_reply":"2023-05-20T08:44:27.998341Z","shell.execute_reply.started":"2023-05-20T08:44:26.860591Z"},"id":"zuym8Ptmp7vW","outputId":"ec031812-eb81-4a8f-ebdf-84dfff5ecf0d"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Not so good of a result**","metadata":{"id":"f0xV5kD4p7vW"}},{"cell_type":"markdown","source":"# Custom Data Augmentation Technique","metadata":{"id":"flE-HnFKp7vW"}},{"cell_type":"code","source":"import albumentations as A\nfrom albumentations.pytorch import ToTensorV2\n\ndef data_aug_cutout(df):\n    '''\n        Add Random Size Black/Blur Patch On Random Bounding Box(s) of a Frame\n    '''\n    \n    # Seed\n    np.random.seed(42)\n        \n    # Take subset of df to apply augmentation\n    df = df.sample(frac=0.4)\n    \n    # Make new Dir to save augmented images\n    os.makedirs(f'{HOME}/img_data/images/aug_train/', exist_ok=True)\n    os.makedirs(f'{HOME}/img_data/labels/aug_train/', exist_ok=True)\n    \n    n_augmented=0\n        \n    for i, row in tqdm(enumerate(df.iterrows()), total=len(df)):\n        \n        row = row[1]\n        \n        # Define the bounding boxes - in the format [x_min, y_min, x_max, y_max]\n        bboxes = []\n        annots = row['annotations']\n        for annot in annots:\n            bbox = list(annot.values())\n            bboxes.append(coco2voc(bbox))\n\n        # Load image\n        img_path = row['image_path']\n        image = cv2.cvtColor(cv2.imread(img_path), cv2.COLOR_BGR2RGB)\n        \n        n = 0\n        \n        # For every bbox add patch\n        for bbox in bboxes:\n\n            ran_prob = np.random.rand()\n            # probability to add a patch to a bbox is 50%\n            \n            if ran_prob > 0.5:\n                n=+1\n\n                ''' Randomly select the portion of bbox to be patched\n                    ran_x1, ran_y1 of patch can be between x1, some dist. to x2 and y1, some dist. to y2 resp.\n                    ran_x2, ran_y2 of patch can be between ran_x1, some dist. to x2 and ran_y1, some dist. to y2 resp.\n                    Note: \"some dist.\" is some percent (Ex: 15%) of the remaining dist. from the \n                    initial co-ordinates to x2, y2 of the bbox\n                '''\n                patch_x1 = int(bbox[0] + ((bbox[2] - bbox[0]) * np.random.uniform(0.2, 0.6)))\n                patch_y1 = int(bbox[1] + ((bbox[3] - bbox[1]) * np.random.uniform(0.2, 0.6)))\n                patch_x2 = int(patch_x1 + ((bbox[2] - patch_x1) * np.random.uniform(0.1, 0.5)))\n                patch_y2 = int(patch_y1 + ((bbox[3] - patch_y1) * np.random.uniform(0.1, 0.5)))\n\n                # Randomly select Patch type (0 or 1)\n                ran_patch = np.random.randint(0,2)\n\n                # Black Patch\n                if ran_patch == 0:\n\n                    # patch co-ordinates\n                    pt1 = patch_x1, patch_y1\n                    pt2 = patch_x2, patch_y2\n\n                    # plot patch\n                    cv2.rectangle(image, pt1, pt2, color=(0,0,0), thickness=-1)\n\n                # Blur Patch\n                else:\n\n                    # Extract the region of interest (ROI)\n                    roi = image[patch_y1:patch_y2, patch_x1:patch_x2]\n\n                    # Apply Gaussian blur to the ROI\n                    blurred_roi = cv2.GaussianBlur(roi, (25, 25), 0)\n\n                    # Replace the ROI with the blurred patch\n                    image[patch_y1:patch_y2, patch_x1:patch_x2] = blurred_roi        \n        \n        if n>0: n_augmented+=1\n        \n        # Save new augmented image and copy labels\n        file_name = row['image_id']\n        aug_file_name = f'_{i}'\n        plt.imsave(f'{HOME}img_data/images/aug_train/{aug_file_name}.jpg', image)\n        shutil.copy(f'{HOME}img_data/labels/train/{file_name}.txt', f'{HOME}img_data/labels/aug_train/{aug_file_name}.txt')\n\n    print(f'{np.round((n_augmented/len(df))*100, 2)}% images augmented out of {len(df)}')","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:24:39.281566Z","iopub.status.busy":"2023-06-01T09:24:39.281165Z","iopub.status.idle":"2023-06-01T09:24:40.400244Z","shell.execute_reply":"2023-06-01T09:24:40.399293Z","shell.execute_reply.started":"2023-06-01T09:24:39.281526Z"},"id":"aFk68Vjyp7vW"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_aug_cutout(train)","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:24:40.402211Z","iopub.status.busy":"2023-06-01T09:24:40.401844Z","iopub.status.idle":"2023-06-01T09:25:03.439273Z","shell.execute_reply":"2023-06-01T09:25:03.438247Z","shell.execute_reply.started":"2023-06-01T09:24:40.402178Z"},"id":"WJV2dCxpp7vX","outputId":"24911c06-5471-404e-c431-0fa81ed40218"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls {HOME}/img_data/images/aug_train | wc -l\n!ls {HOME}/img_data/labels/aug_train | wc -l","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:25:03.441796Z","iopub.status.busy":"2023-06-01T09:25:03.441064Z","iopub.status.idle":"2023-06-01T09:25:05.434937Z","shell.execute_reply":"2023-06-01T09:25:05.433792Z","shell.execute_reply.started":"2023-06-01T09:25:03.441760Z"},"id":"E1r8EvmAp7vY","outputId":"c82e1929-a435-46c5-a579-41c9f7b66572"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check sample\nimg = plt.imread(f'{HOME}img_data/images/aug_train/_0.jpg')\nannots = []\nwith open(f'{HOME}img_data/labels/aug_train/_0.txt', 'r') as f:\n    for line in f:\n        box = line.strip()\n        box = box.split(' ')[1:]\n        box = [float(elem) for elem in box]\n        box = yolo2coco(box)\n        box = [int(elem) for elem in box]\n        annot = {'x': box[0], 'y': box[1], 'width': box[2], 'height': box[3]}\n        annots.append(annot)\nimg = annot_img(img, annots)\nplt.figure(figsize=(10,8))\nplt.imshow(img);","metadata":{"execution":{"iopub.execute_input":"2023-06-01T08:04:54.201044Z","iopub.status.busy":"2023-06-01T08:04:54.199874Z","iopub.status.idle":"2023-06-01T08:04:54.823216Z","shell.execute_reply":"2023-06-01T08:04:54.822255Z","shell.execute_reply.started":"2023-06-01T08:04:54.200996Z"},"id":"SGyla-HVp7vY","outputId":"732b220b-9f13-4953-be1f-d4611ae72032"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We have randomly apply Blur and Black Patches on random bounding boxes","metadata":{"id":"uq9qvZ9Wp7vY"}},{"cell_type":"code","source":"# Update Yaml\nyaml_path   = f\"{HOME}/yolov5/data/starfish_custom_aug.yaml\" #changed starfish.yaml to starfish_custom_aug.yaml\npath        = f'{HOME}img_data'\ntrain_path  = 'images/aug_train' #changed train to aug_train\nval_path    = 'images/val'\ntest_path   = ''\nupdate_data_yaml(yaml_path, path, train_path, val_path, test_path)","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:25:05.438398Z","iopub.status.busy":"2023-06-01T09:25:05.437992Z","iopub.status.idle":"2023-06-01T09:25:05.445376Z","shell.execute_reply":"2023-06-01T09:25:05.444395Z","shell.execute_reply.started":"2023-06-01T09:25:05.438363Z"},"id":"ohou-9H7p7vZ","outputId":"9aec33c7-175f-4caf-f5fc-0eaec3db7f83"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Train on Augmented Data","metadata":{"id":"h-WEwVAXp7vZ"}},{"cell_type":"code","source":"# 4: Load Last Checkpoint, and train for another 30 epochs on new yaml (augmented data)\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights {HOME}/best3.pt \\\n    --img 1280 \\\n    --batch 16 \\\n    --epoch 30 \\\n    --data starfish_custom_aug.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --hyp data/hyps/hyp.starfish.yaml \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-05-20T10:39:30.451633Z","iopub.status.busy":"2023-05-20T10:39:30.450798Z","iopub.status.idle":"2023-05-20T11:21:32.183961Z","shell.execute_reply":"2023-05-20T11:21:32.181959Z","shell.execute_reply.started":"2023-05-20T10:39:30.451595Z"},"id":"xFNAYWOJp7vZ","outputId":"78a1673c-c54b-45ac-e12c-e2d42089dfe1"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish4/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish4/weights/best.pt', f'{HOME}/best4.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-20T11:28:51.912323Z","iopub.status.busy":"2023-05-20T11:28:51.911933Z","iopub.status.idle":"2023-05-20T11:28:51.916787Z","shell.execute_reply":"2023-05-20T11:28:51.915710Z","shell.execute_reply.started":"2023-05-20T11:28:51.912291Z"},"id":"4c0nAkZop7va"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot yolo result\nresult_png = ['confusion_matrix.png']\nplot_yolo_results(result_png, path=f'{HOME}/yolov5/runs/train/custom_starfish4', sizeR=8, sizeC=8)","metadata":{"execution":{"iopub.execute_input":"2023-05-20T11:21:42.820369Z","iopub.status.busy":"2023-05-20T11:21:42.819501Z","iopub.status.idle":"2023-05-20T11:21:45.545606Z","shell.execute_reply":"2023-05-20T11:21:45.544375Z","shell.execute_reply.started":"2023-05-20T11:21:42.820324Z"},"id":"eVp7vWKtp7va","outputId":"98e09d9a-3fa0-45be-ae83-0d3ba4d8b1c9"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Download my custom previous trained model\nlink = 'https://docs.google.com/uc?export=download&id=1VWgnXySuRNnBUazqjO4-gA6JoFoUDVAT'\ndownload_custom_model(link, name='best3.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-21T03:28:06.452786Z","iopub.status.busy":"2023-05-21T03:28:06.452361Z","iopub.status.idle":"2023-05-21T03:28:07.971839Z","shell.execute_reply":"2023-05-21T03:28:07.970851Z","shell.execute_reply.started":"2023-05-21T03:28:06.452750Z"},"id":"o0zmfnEmp7vb","outputId":"caaf5fdc-7bc2-46f1-faf5-41a4214ef5c4"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Download my custom previous trained model\nlink = 'https://docs.google.com/uc?export=download&id=1MEdv-n6O9fHA9Eemw0g1SrA7j61mDtR4'\ndownload_custom_model(link, name='best2.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-21T03:57:57.794500Z","iopub.status.busy":"2023-05-21T03:57:57.793717Z","iopub.status.idle":"2023-05-21T03:58:01.882222Z","shell.execute_reply":"2023-05-21T03:58:01.881209Z","shell.execute_reply.started":"2023-05-21T03:57:57.794459Z"},"id":"3gFrmno5p7vb","outputId":"32859c63-bead-440a-fbb5-67e6ca1e0cdc"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"update_hyperparameter_yaml({})","metadata":{"execution":{"iopub.execute_input":"2023-05-21T04:34:33.513271Z","iopub.status.busy":"2023-05-21T04:34:33.512873Z","iopub.status.idle":"2023-05-21T04:34:33.524858Z","shell.execute_reply":"2023-05-21T04:34:33.523945Z","shell.execute_reply.started":"2023-05-21T04:34:33.513240Z"},"id":"ID2p5gAXp7vc","outputId":"e7e6deca-ac6e-44fd-fc8b-c500f899b694"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 2_1: Load Previous (before data augmentation) Checkpoint, and train for another 30 epochs on new yaml (augmented data) and defualt hyp.yaml\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights {HOME}/best2.pt \\\n    --img 1280 \\\n    --batch 16 \\\n    --epoch 30 \\\n    --data starfish_custom_aug.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-05-21T03:58:47.885415Z","iopub.status.busy":"2023-05-21T03:58:47.885024Z","iopub.status.idle":"2023-05-21T04:29:16.202985Z","shell.execute_reply":"2023-05-21T04:29:16.201578Z","shell.execute_reply.started":"2023-05-21T03:58:47.885384Z"},"id":"5-6xtc3ip7vc","outputId":"9812c46c-43da-4992-8fc6-1e59805ca257"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish5/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish5/weights/best.pt', f'{HOME}/best2_1.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-21T04:36:13.828283Z","iopub.status.busy":"2023-05-21T04:36:13.827785Z","iopub.status.idle":"2023-05-21T04:36:13.833321Z","shell.execute_reply":"2023-05-21T04:36:13.832235Z","shell.execute_reply.started":"2023-05-21T04:36:13.828248Z"},"id":"FlgycqIMp7vc"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot yolo result\nresult_png = ['confusion_matrix.png']\nplot_yolo_results(result_png, path=f'{HOME}/yolov5/runs/train/custom_starfish5', sizeR=8, sizeC=8)","metadata":{"execution":{"iopub.execute_input":"2023-05-21T04:36:13.835989Z","iopub.status.busy":"2023-05-21T04:36:13.835079Z","iopub.status.idle":"2023-05-21T04:36:15.031551Z","shell.execute_reply":"2023-05-21T04:36:15.030566Z","shell.execute_reply.started":"2023-05-21T04:36:13.835955Z"},"id":"heMavIyqp7vd","outputId":"4aa30f43-25f7-46e3-db6f-59a230d7cdaa"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Train Model on Tiles","metadata":{"id":"sSc07iL_p7vd"}},{"cell_type":"code","source":"def data_preprocess_tiles(df, directory, n_tiles=(2,2), frac=0.3, bbox_tile_threshold=1):\n    '''\n        Split an Image in n_tiles (n_tiles must be perfect square)\n        bbox_tile_threshold=1 means a bbox should be completely in a single tile (100% bbox area)\n    '''\n    from sympy import isprime\n    \n    # Seed\n    np.random.seed(42)\n    \n    # Check if n_tiles is prime\n    try:\n        if len(n_tiles)>2:\n            raise Exception('n_tiles must have atmost 2 spliting cordinates')\n    except:\n        n_tiles = (n_tiles, n_tiles)\n    if isprime(np.prod(n_tiles)):\n        raise Exception('Product of n_tiles spliting cordinates must be a non prime number')\n    \n    # Cut Image in n_tiles (half of height and width)\n    cut_by_x = n_tiles[0]\n    cut_by_y = n_tiles[1]\n    tile_height = IMAGE_HEIGHT // cut_by_y\n    tile_width = IMAGE_WIDTH // cut_by_x\n    \n    n_tiles = np.prod(n_tiles)\n    \n    # Compute Tiles coordinates\n    tile_xs = [0]\n    tile_ys = [0]\n    for i in range(cut_by_x):\n        tile_xs.append(tile_width + (tile_width*i))\n    for i in range(cut_by_y):\n        tile_ys.append(tile_height + (tile_height*i))\n    tile_xs.append(IMAGE_WIDTH)\n    tile_ys.append(IMAGE_HEIGHT)\n    \n    # Compute Tiles \n    tile_areas = []\n    for i in range(cut_by_y):\n        y1 = tile_ys[i]\n        y2 = tile_ys[i+1]\n        for i in range(cut_by_x):\n            x1 = tile_xs[i]\n            x2 = tile_xs[i+1]\n            tile_areas.append((x1, y1, x2, y2))\n                \n    # Take subset of df to apply augmentation\n    df = df[df['num_bbox']>=1]\n    df = df.sample(frac=frac)\n    \n    # Make new Dir to save augmented images\n    os.makedirs(f'{HOME}/img_data/images/{directory}/', exist_ok=True)\n    os.makedirs(f'{HOME}/img_data/labels/{directory}/', exist_ok=True)\n    \n    n=0\n    for i, row in tqdm(enumerate(df.iterrows()), total=len(df)):\n        \n        row = row[1]\n    \n        # Load image\n        img_path = row['image_path']\n        image = cv2.cvtColor(cv2.imread(img_path), cv2.COLOR_BGR2RGB)\n        \n        # Define the bounding boxes - in the format [x_min, y_min, x_max, y_max]\n        bboxes = []\n        annots = row['annotations']\n        for annot in annots:\n            bbox = list(annot.values())\n            bboxes.append(coco2voc(bbox))\n            \n        # Extract Tiles (image shape => (h, w, c))\n        tiles = [image[tile_areas[i][1]:tile_areas[i][3], tile_areas[i][0]:tile_areas[i][2], ...]\n                   for i in range(n_tiles)]\n        \n        ''' Eliminate every bbox overlapping multiple Tiles '''\n        # Loop through all bboxes\n        final_bboxes = {i: [] for i in range(n_tiles)}\n        for bbox in bboxes:\n            x = bbox[0]\n            y = bbox[1]\n            x2 = bbox[2]\n            y2 = bbox[3]\n            w = x2 - x\n            h = y2 - y\n            bbox_area = w * h\n            # Loop through all tiles\n            yi_n = cut_by_y\n            for i, (tx, ty, tx2, ty2) in enumerate(tile_areas):\n                xi = i % cut_by_x\n                if xi == 0:\n                    yi = (cut_by_y-yi_n)\n                    yi_n -= 1\n                ''' Checking if any Tile contain current bbox's bbox_tile_threshold area. '''\n                # Check the percentage of bounding box area in each tile\n                tile_bbox = [max(tx, x), max(ty, y), min(tx2, x2), min(ty2, y2)]\n                tile_bbox_area = max(0, tile_bbox[2] - tile_bbox[0]) * max(0, tile_bbox[3] - tile_bbox[1])\n                if tile_bbox_area >= bbox_area * bbox_tile_threshold:               \n                    # Adjust bbox coordinate according to new Tile resolution\n                    new_bbox = bbox\n                    new_bbox[0] -= tile_xs[xi]\n                    new_bbox[2] -= tile_xs[xi]\n                    new_bbox[1] -= tile_ys[yi]\n                    new_bbox[3] -= tile_ys[yi]\n\n                    new_bbox[0] = max(new_bbox[0], 0)\n                    new_bbox[1] = max(new_bbox[1], 0)\n                    new_bbox[2] = min(new_bbox[2], tile_width)\n                    new_bbox[3] = min(new_bbox[3], tile_height)\n\n                    new_bbox = [int(elem) for elem in new_bbox]\n                    new_bbox = voc2coco(new_bbox)\n                    final_bboxes[i].append(new_bbox)\n                    break\n        \n        # Check if not more than 50% tiles are empty\n        if [len(val) for val in final_bboxes.values()].count(0)<=n_tiles//2:\n            n+=1\n            # save tiles and annotations\n            for i in range(n_tiles):\n                aug_file_name = f\"{row['image_id']}_{i}\"\n                plt.imsave(f'{HOME}img_data/images/{directory}/{aug_file_name}.jpg', tiles[i])\n                with open(f'{HOME}img_data/labels/{directory}/{aug_file_name}.txt', 'w') as f:\n                    for box in final_bboxes[i]:\n                        x_cen, y_cen, w, h = coco2yolo(box, image_width=tile_width, image_height=tile_height)\n                        f.write(f\"{0} {x_cen} {y_cen} {w} {h}\\n\")\n                        \n    print(f'{n} preprocessed images saved out of {len(df)}')\n    \n# Check sample\ndef check_prep_sample(img_id, n_tiles, directory):\n    # Plot Original Image\n    fig, ax = plt.subplots(1,1,figsize=(10, 8))\n    img = plt.imread(f'{HOME}img_data/images/train/{img_id}.jpg')\n    annots = (train[train['image_id']==img_id]['annotations'].values)[0]\n    img = annot_img(img, annots)\n    ax.imshow(img)\n    for i in range(N_TILES[1]-1): ax.axhline(IMAGE_HEIGHT/N_TILES[1]*(i+1), color='w', linestyle='--')\n    for i in range(N_TILES[0]-1): ax.axvline(IMAGE_WIDTH/N_TILES[0]*(i+1), color='w', linestyle='--')\n    ax.set_title('Original Image' + ' (0, 0, 1280, 720) ')\n\n    # Plot Tiles\n    fig, axs = plt.subplots(N_TILES[1], N_TILES[0], figsize=(10, 8))\n    axs = axs.flatten()\n    for i in range(np.prod(N_TILES)):\n        img = plt.imread(f'{HOME}img_data/images/{directory}/{img_id}_{i}.jpg')\n        image_width = img.shape[1]\n        image_height = img.shape[0]\n        annots = []\n        with open(f'{HOME}img_data/labels/{directory}/{img_id}_{i}.txt', 'r') as f:\n            for line in f:\n                box = line.strip()\n                box = box.split(' ')[1:]\n                box = [float(elem) for elem in box]\n                box = yolo2coco(box, image_width, image_height)\n                box = [int(elem) for elem in box]\n                annot = {'x': box[0], 'y': box[1], 'width': box[2], 'height': box[3]}\n                annots.append(annot)\n        img = annot_img(img, annots)\n        axs[i].imshow(img)\n        axs[i].set_title(f'{i}')\n    fig.suptitle(f'Tiles ({N_TILES[0]}x{N_TILES[1]})')\n    plt.show()","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:25:05.450515Z","iopub.status.busy":"2023-06-01T09:25:05.449958Z","iopub.status.idle":"2023-06-01T09:25:05.482500Z","shell.execute_reply":"2023-06-01T09:25:05.481564Z","shell.execute_reply.started":"2023-06-01T09:25:05.450474Z"},"id":"wFmaZIJBp7ve"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Preprocess Train and Val Data\nN_TILES = (2, 2)\ndata_preprocess_tiles(train, 'prep_train', n_tiles=N_TILES, frac=1)\ndata_preprocess_tiles(val, 'prep_val', n_tiles=N_TILES, frac=1)","metadata":{"execution":{"iopub.execute_input":"2023-05-31T07:29:53.990566Z","iopub.status.busy":"2023-05-31T07:29:53.990160Z","iopub.status.idle":"2023-05-31T07:30:27.783803Z","shell.execute_reply":"2023-05-31T07:30:27.782863Z","shell.execute_reply.started":"2023-05-31T07:29:53.990535Z"},"id":"-QoutnILp7ve","outputId":"7bb460ef-79b4-489c-b8b6-aca2d719f3e2"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls {HOME}/img_data/images/prep_train | wc -l\n!ls {HOME}/img_data/labels/prep_train | wc -l\n!ls {HOME}/img_data/images/prep_val | wc -l\n!ls {HOME}/img_data/labels/prep_val | wc -l","metadata":{"execution":{"iopub.execute_input":"2023-05-31T07:24:44.283237Z","iopub.status.busy":"2023-05-31T07:24:44.282870Z","iopub.status.idle":"2023-05-31T07:24:48.135756Z","shell.execute_reply":"2023-05-31T07:24:48.134571Z","shell.execute_reply.started":"2023-05-31T07:24:44.283207Z"},"id":"kqAPsYXxp7vf","outputId":"d7892e31-9639-4e16-9204-a46728f2f38f"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !rm -r {HOME}/img_data/images/prep_train | wc -l\n# !rm -r {HOME}/img_data/labels/prep_train | wc -l\n# !rm -r {HOME}/img_data/images/prep_val | wc -l\n# !rm -r {HOME}/img_data/labels/prep_val | wc -l","metadata":{"execution":{"iopub.execute_input":"2023-05-31T07:24:48.139100Z","iopub.status.busy":"2023-05-31T07:24:48.138694Z","iopub.status.idle":"2023-05-31T07:24:48.143801Z","shell.execute_reply":"2023-05-31T07:24:48.142882Z","shell.execute_reply.started":"2023-05-31T07:24:48.139061Z"},"id":"mMerD82np7vf"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check sample\ncheck_prep_sample(img_id = '1-9126', n_tiles=N_TILES, directory='prep_train')","metadata":{"execution":{"iopub.execute_input":"2023-05-31T07:31:15.989791Z","iopub.status.busy":"2023-05-31T07:31:15.989409Z","iopub.status.idle":"2023-05-31T07:31:17.345165Z","shell.execute_reply":"2023-05-31T07:31:17.344300Z","shell.execute_reply.started":"2023-05-31T07:31:15.989759Z"},"id":"NrxQWDuIp7vg","outputId":"03ee1cbe-c271-4ab9-ba0b-7128f1ec0dd4"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Update Yaml\nyaml_path   = f\"{HOME}/yolov5/data/starfish_custom_prep.yaml\" #changed starfish_custom_aug.yaml to starfish_custom_prep.yaml\npath        = f'{HOME}img_data'\ntrain_path  = 'images/prep_train' #changed aug_train to prep_train\nval_path    = 'images/prep_val'  #changed val to prep_val\ntest_path   = ''\nupdate_data_yaml(yaml_path, path, train_path, val_path, test_path)","metadata":{"execution":{"iopub.execute_input":"2023-05-30T19:12:35.437767Z","iopub.status.busy":"2023-05-30T19:12:35.437044Z","iopub.status.idle":"2023-05-30T19:12:35.445260Z","shell.execute_reply":"2023-05-30T19:12:35.444287Z","shell.execute_reply.started":"2023-05-30T19:12:35.437725Z"},"id":"Gy6zwO10p7vg","outputId":"59b3e834-6a4a-4542-c662-fdb1f6dccc67"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''' 5: New Training with preprocessed tiles of 640 image size, 30 epochs and defualt hyp.yaml\nNote: Remember later we will need to preprocess all new data too!\n'''\n\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights yolov5s.pt \\\n    --img 640 \\\n    --batch 16 \\\n    --epoch 30 \\\n    --data starfish_custom_prep.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-05-29T07:08:13.860690Z","iopub.status.busy":"2023-05-29T07:08:13.859874Z","iopub.status.idle":"2023-05-29T07:23:30.838896Z","shell.execute_reply":"2023-05-29T07:23:30.837627Z","shell.execute_reply.started":"2023-05-29T07:08:13.860633Z"},"id":"iz1FHYekp7vh","outputId":"e2782aae-385e-4337-9159-9ebe9c5570eb"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish4/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish4/weights/best.pt', f'{HOME}/best5.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-29T07:33:32.570145Z","iopub.status.busy":"2023-05-29T07:33:32.569757Z","iopub.status.idle":"2023-05-29T07:33:36.964142Z","shell.execute_reply":"2023-05-29T07:33:36.962061Z","shell.execute_reply.started":"2023-05-29T07:33:32.570117Z"},"id":"XhPeZX4wp7vh","outputId":"fdb7d0c5-84da-4d98-a891-f539874971a0"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Download my custom previous trained model\nlink = 'https://docs.google.com/uc?export=download&id=1eegdO29E_JF9Nb9K80Df-fOrwGSgmw8b'\ndownload_custom_model(link, name='best5.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-30T19:09:57.983613Z","iopub.status.busy":"2023-05-30T19:09:57.982717Z","iopub.status.idle":"2023-05-30T19:10:01.631411Z","shell.execute_reply":"2023-05-30T19:10:01.630434Z","shell.execute_reply.started":"2023-05-30T19:09:57.983578Z"},"id":"BgfENdxrp7vh","outputId":"039640a5-e318-4069-facf-cd9e1e3ed72e"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Add Mixup Augmentation\nupdate_hyperparameter_yaml({'box': '0.7', 'cls': '0.1', 'mixup': '0.5', 'iou_t': '0.1'})","metadata":{"execution":{"iopub.execute_input":"2023-05-30T19:10:09.972079Z","iopub.status.busy":"2023-05-30T19:10:09.971738Z","iopub.status.idle":"2023-05-30T19:10:09.978843Z","shell.execute_reply":"2023-05-30T19:10:09.977819Z","shell.execute_reply.started":"2023-05-30T19:10:09.972050Z"},"id":"zVaFe0_gp7vi","outputId":"22ebb6b8-6ca4-4cea-d2a7-e6e1e9b36878"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 6: Load Last checkpoint trained on prepocessed tiles, using custom hyp with mixup aug and loss thresholds\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights {HOME}/best5.pt \\\n    --img 640 \\\n    --batch 16 \\\n    --epoch 40 \\\n    --data starfish_custom_prep.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --hyp data/hyps/hyp.starfish.yaml \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-05-30T19:12:46.573559Z","iopub.status.busy":"2023-05-30T19:12:46.573192Z","iopub.status.idle":"2023-05-30T19:38:24.545335Z","shell.execute_reply":"2023-05-30T19:38:24.544086Z","shell.execute_reply.started":"2023-05-30T19:12:46.573528Z"},"id":"UXvy_AQ4p7vi","outputId":"47ffc9ca-8deb-4792-fa8d-6ffbeeed51fd"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish/weights/best.pt', f'{HOME}/best6.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-30T19:44:15.429378Z","iopub.status.busy":"2023-05-30T19:44:15.428918Z","iopub.status.idle":"2023-05-30T19:44:20.842955Z","shell.execute_reply":"2023-05-30T19:44:20.841387Z","shell.execute_reply.started":"2023-05-30T19:44:15.429341Z"},"id":"HahILoOFp7vj","outputId":"75c9da42-28f2-424a-df96-d9c35a2497cb"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### We notice there is a lot of starfish in the middel of the frame which gets ignored when the frame is split, therefore let's try to retain the starfish to a tile if a specific amount of area is present in that tile even though 100% is not present. Also let's split the frame in (3,2) instead of (2,2)","metadata":{"id":"ALQrdUSWp7vj"}},{"cell_type":"code","source":"# Preprocess Train and Val Data\nN_TILES = (3, 2)\ndata_preprocess_tiles(train, 'prep_train_2', n_tiles=N_TILES, frac=1, bbox_tile_threshold=0.5)\ndata_preprocess_tiles(val, 'prep_val_2', n_tiles=N_TILES, frac=1, bbox_tile_threshold=0.5)","metadata":{"execution":{"iopub.execute_input":"2023-06-01T07:00:42.147051Z","iopub.status.busy":"2023-06-01T07:00:42.146259Z","iopub.status.idle":"2023-06-01T07:01:14.053310Z","shell.execute_reply":"2023-06-01T07:01:14.052398Z","shell.execute_reply.started":"2023-06-01T07:00:42.147017Z"},"id":"x4lYz0fap7vj","outputId":"4ad7385d-164a-4d68-f396-2c9be7986e44"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls {HOME}/img_data/images/prep_train_2 | wc -l\n!ls {HOME}/img_data/labels/prep_train_2 | wc -l\n!ls {HOME}/img_data/images/prep_val_2 | wc -l\n!ls {HOME}/img_data/labels/prep_val_2 | wc -l","metadata":{"execution":{"iopub.execute_input":"2023-06-01T07:01:14.056245Z","iopub.status.busy":"2023-06-01T07:01:14.055321Z","iopub.status.idle":"2023-06-01T07:01:17.958308Z","shell.execute_reply":"2023-06-01T07:01:17.957068Z","shell.execute_reply.started":"2023-06-01T07:01:14.056207Z"},"id":"r572JV_mp7vk","outputId":"9e3fb686-b18b-4bfc-93b2-f7b58fc9d039"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !rm -r {HOME}/img_data/images/prep_train_2 | wc -l\n# !rm -r {HOME}/img_data/labels/prep_train_2 | wc -l\n# !rm -r {HOME}/img_data/images/prep_val_2 | wc -l\n# !rm -r {HOME}/img_data/labels/prep_val_2 | wc -l","metadata":{"execution":{"iopub.execute_input":"2023-05-31T05:57:07.093803Z","iopub.status.busy":"2023-05-31T05:57:07.093422Z","iopub.status.idle":"2023-05-31T05:57:07.098468Z","shell.execute_reply":"2023-05-31T05:57:07.096987Z","shell.execute_reply.started":"2023-05-31T05:57:07.093770Z"},"id":"gQj4Bsfdp7vk"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Check sample\ncheck_prep_sample(img_id = '1-9126', n_tiles=N_TILES, directory='prep_train_2')","metadata":{"execution":{"iopub.execute_input":"2023-06-01T07:01:17.962208Z","iopub.status.busy":"2023-06-01T07:01:17.961874Z","iopub.status.idle":"2023-06-01T07:01:19.856810Z","shell.execute_reply":"2023-06-01T07:01:19.855082Z","shell.execute_reply.started":"2023-06-01T07:01:17.962175Z"},"id":"KQzKN99Zp7vk","outputId":"511c4c43-33e7-40dc-aae1-5a2fb37681c5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Update Yaml\nyaml_path   = f\"{HOME}/yolov5/data/starfish_custom_prep_2.yaml\" #changed starfish_custom_prep.yaml to starfish_custom_prep_2.yaml\npath        = f'{HOME}img_data'\ntrain_path  = 'images/prep_train_2' #changed prep_train to prep_train_2\nval_path    = 'images/prep_val_2'  #changed prep_val to prep_val_2\ntest_path   = ''\nupdate_data_yaml(yaml_path, path, train_path, val_path, test_path)","metadata":{"execution":{"iopub.execute_input":"2023-06-01T07:01:19.859997Z","iopub.status.busy":"2023-06-01T07:01:19.858992Z","iopub.status.idle":"2023-06-01T07:01:19.866224Z","shell.execute_reply":"2023-06-01T07:01:19.865492Z","shell.execute_reply.started":"2023-06-01T07:01:19.859962Z"},"id":"VaNBDbuAp7vl","outputId":"71145340-8c59-4a85-e10d-250129e236c2"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''' 7: New Training with preprocessed tiles of 426 image size, 30 epochs and defualt hyp.yaml '''\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights yolov5s.pt \\\n    --img 426 \\\n    --batch 16 \\\n    --epoch 30 \\\n    --data starfish_custom_prep_2.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-05-31T07:45:13.055826Z","iopub.status.busy":"2023-05-31T07:45:13.055022Z","iopub.status.idle":"2023-05-31T07:53:50.339525Z","shell.execute_reply":"2023-05-31T07:53:50.338140Z","shell.execute_reply.started":"2023-05-31T07:45:13.055793Z"},"id":"FEtrq1Dyp7vl","outputId":"3f7de299-f759-4dea-fcbf-aa88f043a874"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish/weights/best.pt', f'{HOME}/best7.pt')","metadata":{"execution":{"iopub.execute_input":"2023-05-31T08:13:41.905521Z","iopub.status.busy":"2023-05-31T08:13:41.904787Z","iopub.status.idle":"2023-05-31T08:13:45.976811Z","shell.execute_reply":"2023-05-31T08:13:45.975651Z","shell.execute_reply.started":"2023-05-31T08:13:41.905479Z"},"id":"yGxUSwPCp7vl","outputId":"eef36560-7db6-45bb-d2e5-55dc00517f51"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Compare to earlier (2,2) tiling condition, this time we achieve Precision of 0.84 which is significantly higher than 0.73 achieved with (2,2) tiling. <br>\nAlas, we got lower Recall of 0.67 which also decently lower than 0.73 achieved previously. <br>\nThis show lower False Positives, but higher False Negatives.","metadata":{"id":"AkElxJKZp7vm"}},{"cell_type":"code","source":"# Add Mixup Augmentation\nupdate_hyperparameter_yaml({'box': '0.7', 'cls': '0.1', 'mixup': '0.5', 'iou_t': '0.1'})","metadata":{"execution":{"iopub.execute_input":"2023-06-01T07:00:24.132038Z","iopub.status.busy":"2023-06-01T07:00:24.131291Z","iopub.status.idle":"2023-06-01T07:00:24.141135Z","shell.execute_reply":"2023-06-01T07:00:24.139979Z","shell.execute_reply.started":"2023-06-01T07:00:24.131987Z"},"id":"xon4vpoYp7vm","outputId":"de3d2588-30fb-4c63-f286-f02a97053234"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 8: Load Last checkpoint trained on prepocessed tiles, train for another 40 epochs using custom hyp with mixup aug and loss thresholds\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights {HOME}/best7.pt \\\n    --img 426 \\\n    --batch 16 \\\n    --epoch 40 \\\n    --data starfish_custom_prep_2.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --hyp data/hyps/hyp.starfish.yaml \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-05-31T08:50:15.130243Z","iopub.status.busy":"2023-05-31T08:50:15.129742Z","iopub.status.idle":"2023-05-31T09:04:16.316759Z","shell.execute_reply":"2023-05-31T09:04:16.315562Z","shell.execute_reply.started":"2023-05-31T08:50:15.130207Z"},"id":"UoPN7Qj5p7vm","outputId":"26a56fcb-7bad-4682-e8b9-af58f5645b02"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish3/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish3/weights/best.pt', f'{HOME}/best8.pt')","metadata":{"execution":{"iopub.execute_input":"2023-06-01T06:48:08.945570Z","iopub.status.busy":"2023-06-01T06:48:08.944804Z","iopub.status.idle":"2023-06-01T06:48:08.949679Z","shell.execute_reply":"2023-06-01T06:48:08.948779Z","shell.execute_reply.started":"2023-06-01T06:48:08.945532Z"},"id":"y1SVxrrnp7vn"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Download my custom previous trained model\nlink = 'https://docs.google.com/uc?export=download&id=1QC1akGTB94rGcBM7heQL_lLjnFtwe6sD'\ndownload_custom_model(link, name='best8.pt')","metadata":{"execution":{"iopub.execute_input":"2023-06-01T07:00:04.536640Z","iopub.status.busy":"2023-06-01T07:00:04.536246Z","iopub.status.idle":"2023-06-01T07:00:06.667748Z","shell.execute_reply":"2023-06-01T07:00:06.666741Z","shell.execute_reply.started":"2023-06-01T07:00:04.536609Z"},"id":"ZD9yz6Vcp7vn","outputId":"c514dc07-eacd-4f3f-ea7a-685a78e6247e"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 9: Load Last checkpoint trained on prepocessed tiles, train for another 40 epochs using custom hyp with mixup aug and loss thresholds\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights {HOME}/best8.pt \\\n    --img 426 \\\n    --batch 16 \\\n    --epoch 40 \\\n    --data starfish_custom_prep_2.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --hyp data/hyps/hyp.starfish.yaml \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-06-01T07:02:01.491499Z","iopub.status.busy":"2023-06-01T07:02:01.491103Z","iopub.status.idle":"2023-06-01T07:16:04.670995Z","shell.execute_reply":"2023-06-01T07:16:04.669767Z","shell.execute_reply.started":"2023-06-01T07:02:01.491466Z"},"id":"hT6N-gW7p7vo","outputId":"6c6c00f0-2f3a-460d-b176-09bafd01c503"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish/weights/best.pt', f'{HOME}/best9.pt')","metadata":{"execution":{"iopub.execute_input":"2023-06-01T07:30:45.217165Z","iopub.status.busy":"2023-06-01T07:30:45.216717Z","iopub.status.idle":"2023-06-01T07:30:45.223927Z","shell.execute_reply":"2023-06-01T07:30:45.222217Z","shell.execute_reply.started":"2023-06-01T07:30:45.217118Z"},"id":"oiQJtEdJp7vo"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Let's merge both orginal train data and custom augmented data","metadata":{"execution":{"iopub.execute_input":"2023-05-21T06:53:17.129092Z","iopub.status.busy":"2023-05-21T06:53:17.127958Z","iopub.status.idle":"2023-05-21T06:53:18.129719Z","shell.execute_reply":"2023-05-21T06:53:18.128562Z","shell.execute_reply.started":"2023-05-21T06:53:17.129041Z"},"id":"OGYBoN5Cp7vp"}},{"cell_type":"code","source":"shutil.copytree(f'{HOME}img_data/images/train', f'{HOME}img_data/images/train_and_aug', dirs_exist_ok=True)\nshutil.copytree(f'{HOME}img_data/images/aug_train', f'{HOME}img_data/images/train_and_aug', dirs_exist_ok=True)\nshutil.copytree(f'{HOME}img_data/labels/train', f'{HOME}img_data/labels/train_and_aug', dirs_exist_ok=True)\nshutil.copytree(f'{HOME}img_data/labels/aug_train', f'{HOME}img_data/labels/train_and_aug', dirs_exist_ok=True)","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:25:07.247320Z","iopub.status.busy":"2023-06-01T09:25:07.246924Z","iopub.status.idle":"2023-06-01T09:25:08.449033Z","shell.execute_reply":"2023-06-01T09:25:08.448024Z","shell.execute_reply.started":"2023-06-01T09:25:07.247291Z"},"id":"QgtQuRwop7vp","outputId":"2407daa4-5105-4ed2-b835-74b240d65a80"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls {HOME}img_data/images/train_and_aug | wc -l\n!ls {HOME}img_data/labels/train_and_aug | wc -l","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:25:08.452375Z","iopub.status.busy":"2023-06-01T09:25:08.451657Z","iopub.status.idle":"2023-06-01T09:25:10.381657Z","shell.execute_reply":"2023-06-01T09:25:10.380499Z","shell.execute_reply.started":"2023-06-01T09:25:08.452348Z"},"id":"HcIbbIQ4p7vp","outputId":"e6dbe974-6c98-44f1-c07d-2faf0a1a605e"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Update Yaml\nyaml_path   = f\"{HOME}/yolov5/data/starfish_train_and_aug.yaml\" #changed starfish_custom_aug.yaml to starfish_train_and_aug.yaml\npath        = f'{HOME}img_data'\ntrain_path  = 'images/train_and_aug' #changed aug_train to train_and_aug\nval_path    = 'images/val'\ntest_path   = ''\nupdate_data_yaml(yaml_path, path, train_path, val_path, test_path)","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:25:10.385725Z","iopub.status.busy":"2023-06-01T09:25:10.384055Z","iopub.status.idle":"2023-06-01T09:25:10.394382Z","shell.execute_reply":"2023-06-01T09:25:10.393483Z","shell.execute_reply.started":"2023-06-01T09:25:10.385682Z"},"id":"BTzahWqyp7vq","outputId":"3d8fd569-45ec-4d1c-e13c-a78ee568ebc2"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''' In NMS, the IOU threshold is the minimum overlap required between two bounding boxes for one of them to be suppressed, by doing this we are saying, \n    we are confident that objects will not be very close, and hopefully this will reduce False Positives, result in increasing Precision! \n'''\nupdate_hyperparameter_yaml({'box': '0.7', 'cls': '0.1', 'mixup': '0.5', 'iou_t': '0.1'}, make_new=True)","metadata":{"execution":{"iopub.execute_input":"2023-06-01T08:06:41.994486Z","iopub.status.busy":"2023-06-01T08:06:41.994059Z","iopub.status.idle":"2023-06-01T08:06:42.004341Z","shell.execute_reply":"2023-06-01T08:06:42.003244Z","shell.execute_reply.started":"2023-06-01T08:06:41.994449Z"},"id":"Uw4yVKhEp7vq","outputId":"f7b9ce0a-b6d9-489c-ccf4-336bcecccdc8"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Download my custom previous trained model\nlink = 'https://docs.google.com/uc?export=download&id=1bFdP4NLWsyH7cjZ7s4ZwX4V91HCFbDOt'\ndownload_custom_model(link, name='best2_1.pt')","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:26:57.316333Z","iopub.status.busy":"2023-06-01T09:26:57.315959Z","iopub.status.idle":"2023-06-01T09:26:59.266818Z","shell.execute_reply":"2023-06-01T09:26:59.265754Z","shell.execute_reply.started":"2023-06-01T09:26:57.316302Z"},"id":"R99Cvzicp7vq","outputId":"99a03c6d-2890-47dd-d682-b2777be0910f"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 2_2: Load 2_1 Checkpoint, and train for another 100 epochs ON normal train data + custom augmneted data and custom hyperparameters\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights {HOME}/best2_1.pt \\\n    --img 1280 \\\n    --batch 16 \\\n    --epoch 100 \\\n    --data starfish_train_and_aug.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --hyp data/hyps/hyp.starfish.yaml \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-06-01T08:09:14.634930Z","iopub.status.busy":"2023-06-01T08:09:14.634562Z","iopub.status.idle":"2023-06-01T09:11:01.451927Z","shell.execute_reply":"2023-06-01T09:11:01.450757Z","shell.execute_reply.started":"2023-06-01T08:09:14.634901Z"},"id":"lFVDeYCFp7vr","outputId":"20732e07-fde2-42e9-8e3c-430401b7f0ba"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish3/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish3/weights/best.pt', f'{HOME}/best2_2.pt')","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:16:48.940906Z","iopub.status.busy":"2023-06-01T09:16:48.940450Z","iopub.status.idle":"2023-06-01T09:16:48.949899Z","shell.execute_reply":"2023-06-01T09:16:48.948901Z","shell.execute_reply.started":"2023-06-01T09:16:48.940871Z"},"id":"MBRq2ud5p7vr"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 2_3: Load 2_1 Checkpoint, and train for another 100 epochs ON normal train data + custom augmneted data and Defualt Hyp\n%cd {HOME}/yolov5\n!python train.py \\\n    --weights {HOME}/best2_1.pt \\\n    --img 1280 \\\n    --batch 16 \\\n    --epoch 100 \\\n    --data starfish_train_and_aug.yaml \\\n    --optimizer AdamW \\\n    --patience 10 \\\n    --name custom_starfish \\\n    --seed 42 \\\n    --device {device} \\\n    --save-period 10","metadata":{"execution":{"iopub.execute_input":"2023-06-01T09:27:07.446876Z","iopub.status.busy":"2023-06-01T09:27:07.446295Z","iopub.status.idle":"2023-06-01T11:33:37.026671Z","shell.execute_reply":"2023-06-01T11:33:37.025436Z","shell.execute_reply.started":"2023-06-01T09:27:07.446842Z"},"id":"tTZUF03tp7vr","outputId":"5379013d-84f1-4d68-f033-70f8b87a409d"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Getting best.pt\n# from comet_ml import Experiment\n# exp = Experiment()\n# exp.log_model(\"best.pt\", f'{HOME}/yolov5/runs/train/custom_starfish2/weights/best.pt')\n# shutil.copy(f'{HOME}/yolov5/runs/train/custom_starfish2/weights/best.pt', f'{HOME}/best2_3.pt')","metadata":{"execution":{"iopub.execute_input":"2023-06-01T11:45:18.203593Z","iopub.status.busy":"2023-06-01T11:45:18.203120Z","iopub.status.idle":"2023-06-01T11:45:22.416256Z","shell.execute_reply":"2023-06-01T11:45:22.415120Z","shell.execute_reply.started":"2023-06-01T11:45:18.203552Z"},"id":"ZJ6bt9Gkp7vs","outputId":"4c35738b-ed59-4065-dd19-e0dc1e39db8f"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### In the evaluation of object detection models, we check how much overlap of bounding boxes with respect to the ground truth data should be considered as successful recognition. For this purpose, IOUs are used, and mAP50 (mean Average Precision 50%) is the accuracy when IOU=50, i.e., if there is more than 50% overlap, the detection is considered successful.\n\n| Index | Weights | Epoch | Batch_size | Precision | Recall | mAP50 | mAP50:95 | Training Comment\n| :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: |\n| 1 | new | 30 | 16 | 0.928 | 0.839 | 0.904 | 0.492 | Simple Training |\n| 2 | 1 | +40 | 16 | 0.91 | 0.86 | 0.92 | 0.49 | Added Mixup Augmentation |\n|   | 2 | +30 | 16 | 0.946 | 0.846 | 0.918 | 0.508 | Default Hyp.yaml and Custom Augmented Data (Patches) |\n|   | 2_1 | +100 | 16 | 0.888 | 0.771 | 0.848 | 0.436 | - Custom hyp.starfish.yaml : Inc. 'box': '0.7', Dec. 'cls': '0.1', Dec. 'iou_t': '0.1' <br> - Added Mixup <br> - train data + custom augmneted data |\n|   | 2_1 | +100 | 16 | 0.91 | 0.908 | 0.939 | 0.556 | Default Hyp.yaml and train data + custom augmneted data |\n| 3 | 2 | +10 | 16 | 0.905 | 0.805 | 0.895 | 0.475 | Custom hyp.starfish.yaml : Inc. 'box': '0.5', Dec. 'cls': '0.2' |\n| 4 | 3 | +30 | 16 | 0.882 | 0.807 | 0.884 | 0.485 | Custom Data Augmentation (Patches) |\n| 5 | new | 30 | 16 | 0.737 | 0.734 | 0.75 | 0.378 | Preprocessed Tiles Data (2x2) (simple Training) |\n| 6 | 5 | +40 | 16 | 0.785 | 0.723 | 0.776 | 0.416 | - Custom hyp.starfish.yaml : Inc. 'box': '0.7', Dec. 'cls': '0.1', Dec. 'iou_t': '0.1' <br> - Added Mixup Augmentation |\n| 7 | new | 30 | 16 | 0.846 | 0.67 | 0.758 | 0.345 | Preprocessed Tiles Data (3x2) w/ bbox_tile_threshold=0.5 (simple Training) |\n| 8 | 7 | +40 | 16 | 0.774 | 0.694 | 0.758 | 0.395 | - Custom hyp.starfish.yaml : Inc. 'box': '0.7', Dec. 'cls': '0.1', Dec. 'iou_t': '0.1' <br> - Added Mixup Augmentation |\n| 9 | 8 | +40 | 16 | 0.821 | 0.725 | 0.793 | 0.433 | - Custom hyp.starfish.yaml : Inc. 'box': '0.7', Dec. 'cls': '0.1', Dec. 'iou_t': '0.1' <br> - Added Mixup Augmentation |","metadata":{"id":"QiHqEfyMp7vs"}},{"cell_type":"markdown","source":"#### So far the best result is given by the training index 2_3 with performance:\n- Precision: 0.91 \n- Recall: 0.908 \n- mAP50: 0.939\n- mAP50:95: 0.556\n\nEven though the best Precision of 0.946 is achieved through the training run 2_1, we tend to get the best Recall with 2_3, and significantly higher mAP50:95 of 0.55 among all other runs.","metadata":{"id":"c5Am2pYMp7vt"}},{"cell_type":"markdown","source":"# Inference on Validation Set","metadata":{"id":"RM3hMC4yp7vt"}},{"cell_type":"code","source":"# Download my custom previous trained model\nlink = 'https://docs.google.com/uc?export=download&id=16qFBPGgL2yx_UMlYdE7WV0i3hkJJpbxv'\ndownload_custom_model(link, name='best2_3.pt')","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:55.568968Z","iopub.status.busy":"2023-06-04T05:11:55.568364Z","iopub.status.idle":"2023-06-04T05:11:58.817571Z","shell.execute_reply":"2023-06-04T05:11:58.816600Z","shell.execute_reply.started":"2023-06-04T05:11:55.568910Z"},"id":"qu8zBf8qp7vt","outputId":"7681193a-d4e5-42f0-a8a4-9db1bd136c9b"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python val.py \\\n    --weights {HOME}/best2_3.pt \\\n    --img 1280 \\\n    --data starfish.yaml \\\n    --task val \\\n    --iou-thres 0.2 \\\n    --name custom_starfish \\\n    --device {device}","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:11:58.820407Z","iopub.status.busy":"2023-06-04T05:11:58.820016Z","iopub.status.idle":"2023-06-04T05:12:33.753785Z","shell.execute_reply":"2023-06-04T05:12:33.752576Z","shell.execute_reply.started":"2023-06-04T05:11:58.820371Z"},"id":"UuN90Io1p7vu","outputId":"a425d764-197a-46df-d490-4fa5d41b472e"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls {HOME}/yolov5/runs/val/custom_starfish -GFlash --color","metadata":{"execution":{"iopub.execute_input":"2023-06-03T10:03:38.877318Z","iopub.status.busy":"2023-06-03T10:03:38.876267Z","iopub.status.idle":"2023-06-03T10:03:40.016192Z","shell.execute_reply":"2023-06-03T10:03:40.014833Z","shell.execute_reply.started":"2023-06-03T10:03:38.877268Z"},"id":"IMUN9J8Xp7vu","outputId":"d471a86b-7026-4fae-e489-74baebb2761c"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot yolo result\nresult_png = ['F1_curve.png',\n              'PR_curve.png',\n              'P_curve.png',\n              'R_curve.png']\n\nplot_yolo_results(result_png, path=f'{HOME}/yolov5/runs/val/custom_starfish', row=2, col=2)","metadata":{"execution":{"iopub.execute_input":"2023-06-03T10:13:58.930063Z","iopub.status.busy":"2023-06-03T10:13:58.929644Z","iopub.status.idle":"2023-06-03T10:14:02.105451Z","shell.execute_reply":"2023-06-03T10:14:02.104526Z","shell.execute_reply.started":"2023-06-03T10:13:58.930029Z"},"id":"0XrjS7fpp7vu","outputId":"50b9ee5d-b385-491a-a0e7-b19d82c5d8ec"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot yolo result\nresult_png = ['confusion_matrix.png']\n\nplot_yolo_results(result_png, path=f'{HOME}/yolov5/runs/val/custom_starfish', sizeR=8, sizeC=8)","metadata":{"execution":{"iopub.execute_input":"2023-06-03T10:14:02.108235Z","iopub.status.busy":"2023-06-03T10:14:02.107312Z","iopub.status.idle":"2023-06-03T10:14:03.241566Z","shell.execute_reply":"2023-06-03T10:14:03.240555Z","shell.execute_reply.started":"2023-06-03T10:14:02.108178Z"},"id":"2tpJ7hNOp7vv","outputId":"655ab3ea-5e31-45bc-dbb1-851077e3c1f5"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot yolo result\nresult_png = ['val_batch0_labels.jpg',\n              'val_batch0_pred.jpg',]\n\nplot_yolo_results(result_png, path=f'{HOME}/yolov5/runs/val/custom_starfish', row=2, col=1)","metadata":{"execution":{"iopub.execute_input":"2023-06-03T10:14:03.243117Z","iopub.status.busy":"2023-06-03T10:14:03.242781Z","iopub.status.idle":"2023-06-03T10:14:08.929026Z","shell.execute_reply":"2023-06-03T10:14:08.925721Z","shell.execute_reply.started":"2023-06-03T10:14:03.243090Z"},"id":"tOjGSpENp7vv","outputId":"ee9bf3ca-6698-4b7d-ebab-dd6bdb03f444"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The performance of the model is pretty good with metrics:\n- Precision: 0.927 \n- Recall: 0.903\n- mAP50: 0.938\n- mAP50:95: 0.556","metadata":{"id":"CpYYfDHep7vw"}},{"cell_type":"markdown","source":"**Let's also evaluate the model with augmentation**","metadata":{"id":"dPQyej7Sp7vw"}},{"cell_type":"code","source":"!python val.py \\\n    --weights {HOME}/best2_3.pt \\\n    --img 1280 \\\n    --data starfish.yaml \\\n    --task val \\\n    --iou-thres 0.2 \\\n    --augment \\\n    --name custom_starfish \\\n    --device {device}","metadata":{"execution":{"iopub.execute_input":"2023-06-03T10:24:51.311209Z","iopub.status.busy":"2023-06-03T10:24:51.310745Z","iopub.status.idle":"2023-06-03T10:25:20.883004Z","shell.execute_reply":"2023-06-03T10:25:20.881811Z","shell.execute_reply.started":"2023-06-03T10:24:51.311173Z"},"id":"n5cQ4thAp7vw","outputId":"4c6e31a0-e012-4fc0-de3f-3c35d44af92c"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Pretty Good!** <br> <br>","metadata":{"id":"i-i6_nu8p7vx"}},{"cell_type":"code","source":"#find the best IOU Threshold based on Precision\nimport subprocess\nimport re\n\nprecision_records = []\nrecall_records = []\nmAP50_records = []\n\ndef extract_precision_from_output(string):\n    precision = re.findall(\"all\\s+\\d+\\s+\\d+\\s+(\\d+\\.\\d+)\", string)\n    return float(precision[0])\n\ndef extract_recall_from_output(string):\n    recall = re.findall(\"all\\s+\\d+\\s+\\d+\\s+\\d+\\.\\d+\\s+(\\d+\\.\\d+)\", string)\n    return float(recall[0])\n\ndef extract_mAP50_from_output(string):\n    mAP50 = re.findall(\"all\\s+\\d+\\s+\\d+\\s+\\d+\\.\\d+\\s+\\d+\\.\\d+\\s+(\\d+\\.\\d+)\", string)\n    return float(mAP50[0])\n\niouThresholds = np.arange(0.1, 1.1, 0.1)\nfor iou_t in tqdm(iouThresholds, total=len(iouThresholds)):\n    command = [\n        \"python\", \"val.py\",\n        \"--weights\", f\"{HOME}/best2_3.pt\",\n        \"--img\", \"1280\",\n        \"--data\", \"starfish.yaml\",\n        \"--task\", \"val\",\n        \"--iou-thres\", str(iou_t),\n        \"--augment\",\n        \"--name\", \"custom_starfish\",\n        \"--device\", device\n    ]\n    \n    output = str(subprocess.run(command, capture_output=True, text=True))\n    # Extract precision value from the output\n    precision = extract_precision_from_output(output)\n    # Extract recall value from the output\n    recall = extract_recall_from_output(output)\n    # Extract mAP50 value from the output\n    mAP50 = extract_mAP50_from_output(output)\n    \n    precision_records.append(precision)\n    recall_records.append(recall)\n    mAP50_records.append(mAP50)\n    \nprint(\"Precision:\", precision_records, \"Highest:\", max(precision_records), \"Best IOU:\", iouThresholds[np.argmax(precision_records)])\nprint(\"Recall:\", recall_records, \"Highest:\", max(recall_records), \"Best IOU:\", iouThresholds[np.argmax(recall_records)])\nprint(\"mAP50:\", mAP50_records, \"Highest:\", max(mAP50_records), \"Best IOU:\", iouThresholds[np.argmax(mAP50_records)])","metadata":{"execution":{"iopub.execute_input":"2023-06-04T05:26:43.971536Z","iopub.status.busy":"2023-06-04T05:26:43.970897Z"},"id":"Xv7p7W07p7vx","outputId":"d8a4634b-3aa0-4f53-e9e5-97b2310cf047"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(iouThresholds, precision_records)\nplt.plot(iouThresholds, recall_records)\nplt.plot(iouThresholds, mAP50_records)\nplt.legend(['Precision-IOU Curve', 'Recall-IOU Curve', 'mAP50-IOU Curve'], bbox_to_anchor=(1,1))\nplt.title('Metrics v IOU Thresholds')\nplt.show()","metadata":{"id":"ouAKffirp7vy","outputId":"ce0bc425-4968-45f9-9260-abd1fec22091"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Let's stick to: <br>\n- IOU Threshold: 0.3\n- Confidence Threshold: 0.4\n\n","metadata":{"id":"Tx6pMI0uF8S8"}},{"cell_type":"markdown","source":"# Inference on Test Set","metadata":{"id":"zLmhDJR6p7vz"}},{"cell_type":"code","source":"# Make Image and Label Dir for Test set\nmake_images_dir(test, dest=f'{HOME}img_data/images/test')\nyolo_annotations_dir(test, dest=f'{HOME}img_data/labels/test')\n!ls {HOME}/img_data/images/test | wc -l\n!ls {HOME}/img_data/labels/test | wc -l","metadata":{"execution":{"iopub.execute_input":"2023-05-16T03:25:46.679995Z","iopub.status.busy":"2023-05-16T03:25:46.679615Z","iopub.status.idle":"2023-05-16T03:25:49.974438Z","shell.execute_reply":"2023-05-16T03:25:49.973093Z","shell.execute_reply.started":"2023-05-16T03:25:46.679966Z"},"id":"bSj3lLX_p7vz","outputId":"784b6674-8881-4379-b904-b56e494d7257"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Detect on test set\n%cd {HOME}/yolov5\n!python detect.py \\\n    --weights {HOME}/best2_3.pt \\\n    --img 1280 \\\n    --source {HOME}img_data/images/test \\\n    --iou-thres 0.3 \\\n    --conf-thres 0.4 \\\n    --name custom_starfish \\\n    --device {device} \\\n    --save-txt \\\n    --save-conf","metadata":{"execution":{"iopub.execute_input":"2023-05-16T03:27:51.129626Z","iopub.status.busy":"2023-05-16T03:27:51.129194Z","iopub.status.idle":"2023-05-16T03:28:11.626085Z","shell.execute_reply":"2023-05-16T03:28:11.624845Z","shell.execute_reply.started":"2023-05-16T03:27:51.129591Z"},"id":"aJ5K1zkKp7v0","outputId":"9edce777-c8b4-411e-b8b0-97994c39e5e3"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"directory = f\"{HOME}/yolov5/runs/detect/custom_starfish3/\"","metadata":{"id":"QWUMWpCu1Fuz"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img_id = \"2-5754\"\n\nimg = plt.imread(f'{directory}/{img_id}.jpg')\n\nannots = (test[test['image_id']==img_id]['annotations'].values)[0]\nimg = annot_img(img, annots)\nshow_img(img, 16)","metadata":{"id":"v-fXEs3HL2I-","outputId":"ba2a032d-b920-42ab-b2dd-68d912db0db8"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Update Yaml\nyaml_path   = f\"{HOME}/yolov5/data/starfish.yaml\"\npath = f'{HOME}img_data'\ntrain_path = 'images/train'\nval_path = 'images/val'\ntest_path = 'images/test'\nupdate_data_yaml(yaml_path, path, train_path, val_path, test_path)","metadata":{"execution":{"iopub.execute_input":"2023-05-16T03:47:11.000219Z","iopub.status.busy":"2023-05-16T03:47:10.999397Z","iopub.status.idle":"2023-05-16T03:47:11.008051Z","shell.execute_reply":"2023-05-16T03:47:11.006746Z","shell.execute_reply.started":"2023-05-16T03:47:11.000174Z"},"id":"TFfJJzx0p7v0","outputId":"82650c4f-ac7d-4925-918d-59a57a158865"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python val.py \\\n    --weights {HOME}/best2_3.pt \\\n    --img 1280 \\\n    --data starfish.yaml \\\n    --task test \\\n    --iou-thres 0.3 \\\n    --conf-thres 0.4 \\\n    --name custom_starfish \\\n    --device {device}","metadata":{"id":"h4_FWDUbHqD4","outputId":"55a4e02e-0290-43f1-d815-a6f0c343d972"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def iou(box1, box2):\n    # Convert boxes cordinates from (x_cen, y_cen, w, h) to (x_min, y_min, x_max, y_max) format\n    '''\n                       (x_max, y_max)\n        |--------------------|\n        |       |            |\n        |       h            |\n        |       |            |\n        |       - * (xc,yc)  |\n        |----w----|          |\n        |                    |\n        |                    |\n        |--------------------|\n  (x_min, y_min)\n  \n        x_min = x_cen - w\n        y_min = y_cen - h\n        x_max = x_cen + w\n        y_max = y_cen + h\n    '''\n    box1 = [box1[0] - box1[2]/2, box1[1] - box1[3]/2, box1[0] + box1[2]/2, box1[1] + box1[3]/2]\n    box2 = [box2[0] - box2[2]/2, box2[1] - box2[3]/2, box2[0] + box2[2]/2, box2[1] + box2[3]/2]\n\n    # Calculate Intersection Area\n    x_min = max(box1[0], box2[0])\n    y_min = max(box1[1], box2[1])\n    x_max = min(box1[2], box2[2])\n    y_max = min(box1[3], box2[3])\n    intersection_area = max(0, x_max - x_min) * max(0, y_max - y_min)\n\n    # Calculate Union Area\n    box1_area = (box1[2] - box1[0]) * (box1[3] - box1[1]) #w*h\n    box2_area = (box2[2] - box2[0]) * (box2[3] - box2[1]) #w*h\n    union_area = box1_area + box2_area - intersection_area\n    \n    # Calculate IOU (0 <= IOU <= 1)\n    iou = intersection_area / union_area\n    return iou","metadata":{"execution":{"iopub.execute_input":"2023-05-15T05:27:00.431972Z","iopub.status.busy":"2023-05-15T05:27:00.431495Z","iopub.status.idle":"2023-05-15T05:27:00.447440Z","shell.execute_reply":"2023-05-15T05:27:00.446247Z","shell.execute_reply.started":"2023-05-15T05:27:00.431937Z"},"id":"L2R_bGcap7v2"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Loop through all records (frames)\nlables_dir = directory+\"/labels\"\n\n# IOU Threshold\niou_t = 0.5\n\nPrecisions = []\nfor row in tqdm(test.iterrows(), total=len(test)):\n# for row in test[test['image_id']=='0-9549'].iterrows():\n    \n    # Ground Truth\n    row = row[1]\n    img_id = row['image_id']\n    annots_gt = row['annotations']\n    \n    # Predicted Labels \n    try:\n        with open(f\"{lables_dir}/{img_id}.txt\", 'r') as f:\n            annots_pred = [line.rstrip() for line in f]\n    except:\n        #for frame with no detection there is no label file\n        annots_pred = []\n    else:\n        True_pos = 0\n        # Loop through all object in a frame (ground truth)\n        for annot_gt in annots_gt:\n            \n            x_cen, y_cen, w, h = coco2yolo(annot_gt)\n        \n            pred_box = [x_cen, y_cen, w, h]\n            \n            # Loop through all predicted object in a frame, and match the gt with all pred bbox, and finď the best IOU\n            idx = 0\n            best_iou = 0\n            conf = 0\n            for i, annot_pred in enumerate(annots_pred):\n                annot_pred = (annot_pred.split())\n                gt_box = [float(elem) for elem in annot_pred[1:-1]]        \n                _iou = iou(gt_box, pred_box)\n                if best_iou < _iou:\n                    idx = i\n                    best_iou = _iou\n                    conf = annot_pred[-1]\n            \n            if best_iou >= iou_t:\n                del annots_pred[idx]\n                True_pos += 1\n\n        if len(annots_gt)>0:\n            False_pos = len(annots_pred)\n            Precision = True_pos/(True_pos+False_pos)\n            Precisions.append(Precision)\n\nprint(f'mAP{iou_t}:', np.average(Precisions))","metadata":{"execution":{"iopub.execute_input":"2023-05-15T05:40:41.828321Z","iopub.status.busy":"2023-05-15T05:40:41.827435Z","iopub.status.idle":"2023-05-15T05:40:41.843334Z","shell.execute_reply":"2023-05-15T05:40:41.841980Z","shell.execute_reply.started":"2023-05-15T05:40:41.828279Z"},"id":"epIf_ZfBp7v3","outputId":"c801df95-6523-4f0c-c8ac-e46a81172d64"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# The End ⭐\nAs we conclude our starfish object detection project, we reflect on the journey we undertook to achieve accurate and reliable results. This computer vision endeavor involved the detection of starfish in ocean bed imagery captured from three videos, each comprising approximately 6000 frames with a resolution of 720x1280.\n\nThroughout this project, we meticulously fine-tuned our model, continuously evaluating its performance and making adjustments as needed. We diligently analyzed the computed IOUs and mAP scores to assess the model's accuracy and robustness. By analyzing the model's performance across multiple frames and videos, we gained valuable insights into its strengths and weaknesses.\n\nIn conclusion, our starfish object detection project exemplifies the rigorous and iterative process involved in computer vision tasks. Through the implementation of techniques such as mosaic data augmentation, addressing the small object problem, handling imbalanced data, and continuous evaluation and refinement of our model, we have achieved a robust and accurate starfish detection system. \n\nOur work paves the way for further advancements in underwater object detection and contributes to the understanding and preservation of marine ecosystems. ✨\n<br> <br>\n![](https://media.giphy.com/media/dRyXC8ICV1LsUlz4dF/giphy.gif)","metadata":{"id":"5sxpNtybp7wF"}}],"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}}