{"metadata":{"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":22990,"databundleVersionId":2048213,"sourceType":"competition"},{"sourceId":7032575,"sourceType":"datasetVersion","datasetId":4045246},{"sourceId":7037091,"sourceType":"datasetVersion","datasetId":4045253}],"dockerImageVersionId":30558,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true},"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"papermill":{"default_parameters":{},"duration":1779.497699,"end_time":"2023-11-24T00:37:46.857056","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2023-11-24T00:08:07.359357","version":"2.4.0"},"widgets":{"application/vnd.jupyter.widget-state+json":{"state":{"00045c7684d7400f81c4d539110892d6":{"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_ce31758adbf54f5b816a29498bb2989a","placeholder":"​","style":"IPY_MODEL_e017bd0ce2274f56acc5d5eff1b4b319","value":" 47/47 [06:34&lt;00:00,  5.78s/it]"}},"02993fa460ae472abbbfb2f8c14422ec":{"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}},"0a72ccca7cca4609b376c260a46d9a3d":{"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_b2865f7678104b64a488a09adaadbd03","placeholder":"​","style":"IPY_MODEL_715172aad8c24e7c81fa1af332f93568","value":" 58/58 [02:06&lt;00:00,  1.18it/s]"}},"0dd872c7a8b6472da955bd5c8206b457":{"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":""}},"0eb8084407ae4a0aa554fad7ba97ab57":{"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_132015c5572b468ca0b1ce2a95ed0779","IPY_MODEL_b574a2c40e054621852e46a800cec3c1","IPY_MODEL_d88dc7424c444696907d6ce92766c0b7"],"layout":"IPY_MODEL_02993fa460ae472abbbfb2f8c14422ec"}},"0ef323ab50e3417693cd7d7a63e99446":{"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":""}},"132015c5572b468ca0b1ce2a95ed0779":{"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_5c025219efd340a990395ab4579871f6","placeholder":"​","style":"IPY_MODEL_212fed197e744badab847408b464309a","value":"Segmenting Image: 100%"}},"1750eb66a3b94e979635e2b4b79bd260":{"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":""}},"1b561aadb6f345a8b6b78bf816951c1b":{"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_5000713e85ca4a33a2d1324a3b346bc2","max":1,"min":0,"orientation":"horizontal","style":"IPY_MODEL_2edfebd91e15439e8079c41022680ec7","value":1}},"1c3eddf50c92406d92b5e90ecd5d92e7":{"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_859a0527754944819a3eba842bc5432f","placeholder":"​","style":"IPY_MODEL_476dfb3d5a8e4660957bdc6fffd738c9","value":"Segmenting Image: 100%"}},"1f4c9f9dfbb140f592c780d3a3c77592":{"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_e6b0be6ec376407db021b33981c25b0c","placeholder":"​","style":"IPY_MODEL_c5dbeccd6e6b41e78e54fa53499769d0","value":" 92/92 [03:44&lt;00:00,  1.17it/s]"}},"20395e64d51d44ee9c9e032e08ee1e4f":{"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_a15a75bd6ea747b6a8ba7b415615914d","placeholder":"​","style":"IPY_MODEL_0dd872c7a8b6472da955bd5c8206b457","value":"Segmenting Image: 100%"}},"212fed197e744badab847408b464309a":{"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":""}},"21d5c917d082419599b221ef4741cc37":{"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}},"228f6d24f1f349289aecf08043d5b9c9":{"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_b80f698eae3e47a2a88a159edaef11f2","max":47,"min":0,"orientation":"horizontal","style":"IPY_MODEL_3061322ba19345a78d1913e35588d66c","value":47}},"256f6b67d7684535bb28a62944ca7783":{"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}},"28acedf33d704fc89db4a2e7469510a8":{"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_50bb82b1e70e45e3875fea433142df3c","IPY_MODEL_1b561aadb6f345a8b6b78bf816951c1b","IPY_MODEL_393b607f85c84f9fa9b13c94d9609455"],"layout":"IPY_MODEL_5eb8f60deb5c4f0e8dd2ef22eed4d717"}},"2b9bc10d476047df9797676bb043716c":{"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}},"2bdcf9742856470ab8bd9c7f25d731b8":{"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":""}},"2d0a75352fba466a8187dd17b1258b3e":{"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_b04e20b0455148879ecf0ff4176622e5","IPY_MODEL_7a0e3f37064949ffab29f2eae4c00ca5","IPY_MODEL_449b580f60c54024b3fbed30de8e7a32"],"layout":"IPY_MODEL_3678f23794334f55a15d6ca95e6d4d36"}},"2edfebd91e15439e8079c41022680ec7":{"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":""}},"2fc43aef62ac4deda561ba0f0c63625e":{"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_20395e64d51d44ee9c9e032e08ee1e4f","IPY_MODEL_9abbe310c7ff4983abaa8b7eaecd87f2","IPY_MODEL_1f4c9f9dfbb140f592c780d3a3c77592"],"layout":"IPY_MODEL_d96b427cd7a64aee9b44b3a1f2fd1a3e"}},"3061322ba19345a78d1913e35588d66c":{"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":""}},"3235dde6c7a74a199c4398245c7d476e":{"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":""}},"3678f23794334f55a15d6ca95e6d4d36":{"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}},"393b607f85c84f9fa9b13c94d9609455":{"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_2b9bc10d476047df9797676bb043716c","placeholder":"​","style":"IPY_MODEL_3235dde6c7a74a199c4398245c7d476e","value":" 5/? [29:25&lt;00:00, 365.71s/it]"}},"3d5ab9e9464548c2a59d1f212ac063d8":{"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":""}},"425624160e82477db9bdadcda1cf41a6":{"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}},"449b580f60c54024b3fbed30de8e7a32":{"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_b2a5f88f89a54484b489770093ed6961","placeholder":"​","style":"IPY_MODEL_2bdcf9742856470ab8bd9c7f25d731b8","value":" 60/60 [08:07&lt;00:00,  4.35s/it]"}},"476dfb3d5a8e4660957bdc6fffd738c9":{"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":""}},"4c6d9510e7df49e3b0025bb5711ccb0f":{"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}},"5000713e85ca4a33a2d1324a3b346bc2":{"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":"20px"}},"50bb82b1e70e45e3875fea433142df3c":{"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_256f6b67d7684535bb28a62944ca7783","placeholder":"​","style":"IPY_MODEL_d4c403e951a34490bd6033c9fca2e5a7","value":""}},"5308be5fe2d247d6bff364075ee5f0a9":{"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}},"55e94d0cf0ab420cbc5e30fcb797e79b":{"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":""}},"5ad8425eab8249f0a2b8c383feed7d47":{"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":""}},"5c025219efd340a990395ab4579871f6":{"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}},"5eb8f60deb5c4f0e8dd2ef22eed4d717":{"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}},"6c920a3c2aaf49f190f34d71f922bf4c":{"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}},"715172aad8c24e7c81fa1af332f93568":{"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":""}},"7a0e3f37064949ffab29f2eae4c00ca5":{"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_91c105de160443d9951f30c2bdadd7c3","max":60,"min":0,"orientation":"horizontal","style":"IPY_MODEL_ac8e179cf93f4ef2afb4d43f84b3c05e","value":60}},"826b6c5c96f7440fa4951da428ecb729":{"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}},"859a0527754944819a3eba842bc5432f":{"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}},"91c105de160443d9951f30c2bdadd7c3":{"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}},"9abbe310c7ff4983abaa8b7eaecd87f2":{"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_21d5c917d082419599b221ef4741cc37","max":92,"min":0,"orientation":"horizontal","style":"IPY_MODEL_1750eb66a3b94e979635e2b4b79bd260","value":92}},"9dd7e0dc36654aeca1ea6a70e95e1d7e":{"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_e7437d191cbb4d8ab7cb7d411929e90c","IPY_MODEL_c611b115bf0340369dea8183132dce1d","IPY_MODEL_0a72ccca7cca4609b376c260a46d9a3d"],"layout":"IPY_MODEL_e9d410c9ac294a1783f49de9c1a539f2"}},"a15a75bd6ea747b6a8ba7b415615914d":{"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}},"ac8e179cf93f4ef2afb4d43f84b3c05e":{"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":""}},"b04e20b0455148879ecf0ff4176622e5":{"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_e780eeb1da604a53b04f4e4d84ea088f","placeholder":"​","style":"IPY_MODEL_5ad8425eab8249f0a2b8c383feed7d47","value":"Segmenting Image: 100%"}},"b2865f7678104b64a488a09adaadbd03":{"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}},"b2a5f88f89a54484b489770093ed6961":{"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}},"b574a2c40e054621852e46a800cec3c1":{"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_5308be5fe2d247d6bff364075ee5f0a9","max":65,"min":0,"orientation":"horizontal","style":"IPY_MODEL_0ef323ab50e3417693cd7d7a63e99446","value":65}},"b80f698eae3e47a2a88a159edaef11f2":{"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}},"c475d11be383425c8d846c9a405d5c5e":{"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_1c3eddf50c92406d92b5e90ecd5d92e7","IPY_MODEL_228f6d24f1f349289aecf08043d5b9c9","IPY_MODEL_00045c7684d7400f81c4d539110892d6"],"layout":"IPY_MODEL_826b6c5c96f7440fa4951da428ecb729"}},"c5dbeccd6e6b41e78e54fa53499769d0":{"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":""}},"c611b115bf0340369dea8183132dce1d":{"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_6c920a3c2aaf49f190f34d71f922bf4c","max":58,"min":0,"orientation":"horizontal","style":"IPY_MODEL_3d5ab9e9464548c2a59d1f212ac063d8","value":58}},"ce31758adbf54f5b816a29498bb2989a":{"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}},"d4c403e951a34490bd6033c9fca2e5a7":{"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":""}},"d88dc7424c444696907d6ce92766c0b7":{"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_425624160e82477db9bdadcda1cf41a6","placeholder":"​","style":"IPY_MODEL_e20656a653bc4555a1b669f3ddc43aeb","value":" 65/65 [04:01&lt;00:00,  3.63s/it]"}},"d96b427cd7a64aee9b44b3a1f2fd1a3e":{"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}},"e017bd0ce2274f56acc5d5eff1b4b319":{"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":""}},"e20656a653bc4555a1b669f3ddc43aeb":{"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":""}},"e6b0be6ec376407db021b33981c25b0c":{"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}},"e7437d191cbb4d8ab7cb7d411929e90c":{"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_4c6d9510e7df49e3b0025bb5711ccb0f","placeholder":"​","style":"IPY_MODEL_55e94d0cf0ab420cbc5e30fcb797e79b","value":"Segmenting Image: 100%"}},"e780eeb1da604a53b04f4e4d84ea088f":{"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}},"e9d410c9ac294a1783f49de9c1a539f2":{"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}}},"version_major":2,"version_minor":0}}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# Leave lines below uncommented this if you get:\n# OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.\nimport os\nos.environ['KMP_DUPLICATE_LIB_OK']='True'\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":0.866671,"end_time":"2023-11-24T00:08:11.847917","exception":false,"start_time":"2023-11-24T00:08:10.981246","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:32:21.533861Z","iopub.execute_input":"2023-11-24T14:32:21.534270Z","iopub.status.idle":"2023-11-24T14:32:21.897545Z","shell.execute_reply.started":"2023-11-24T14:32:21.534237Z","shell.execute_reply":"2023-11-24T14:32:21.896548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport torch.nn as nn\nfrom torch.utils.data import DataLoader\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Polygon\nfrom tqdm import tqdm\nimport gc\nimport json\nimport cv2\nimport tifffile as tiff\nfrom skimage import color","metadata":{"papermill":{"duration":4.510089,"end_time":"2023-11-24T00:08:16.363021","exception":false,"start_time":"2023-11-24T00:08:11.852932","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:32:21.899450Z","iopub.execute_input":"2023-11-24T14:32:21.899968Z","iopub.status.idle":"2023-11-24T14:32:23.540054Z","shell.execute_reply.started":"2023-11-24T14:32:21.899931Z","shell.execute_reply":"2023-11-24T14:32:23.539050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\n\n# Import functions\nsys.path.insert(0, os.path.join(os.getcwd(), '..', 'input', 'modules'))\nfrom glomerulus import Glomerulus, Patch, KidneySampleDataset, get_glomeruli, generate_glomerulus_patches\nfrom networks import UNet_Large, CBAM_R2UNet_v2_Large\n# from utils import read_tiff","metadata":{"papermill":{"duration":0.50199,"end_time":"2023-11-24T00:08:16.870103","exception":false,"start_time":"2023-11-24T00:08:16.368113","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:32:23.541489Z","iopub.execute_input":"2023-11-24T14:32:23.541955Z","iopub.status.idle":"2023-11-24T14:32:23.837770Z","shell.execute_reply.started":"2023-11-24T14:32:23.541903Z","shell.execute_reply":"2023-11-24T14:32:23.836906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_tiff(image_path):\n    with rasterio.open(image_path) as image:\n        image_data = image.read().astype(np.float32)\n        del image\n        gc.collect()\n        print(image_data.dtype, image_data.shape)\n        \n        if image_data.shape[0] == 1:\n            if image_data.any() > 1:\n                image_data /= 255.0\n                \n            image_data = image_data[0]\n            gc.collect()\n        else:\n            if image_data.any() > 1:\n                image_data /= 255.0\n            \n            if image_data.shape[0] == 3:\n                image_data = np.transpose(image_data, (1, 2, 0))\n            image_data = color.rgb2gray(image_data)\n            \n        print(image_data.shape, image_data.dtype)\n        gc.collect()\n        \n        return image_data","metadata":{"papermill":{"duration":0.014011,"end_time":"2023-11-24T00:08:16.889041","exception":false,"start_time":"2023-11-24T00:08:16.875030","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:32:23.839926Z","iopub.execute_input":"2023-11-24T14:32:23.840398Z","iopub.status.idle":"2023-11-24T14:32:23.848750Z","shell.execute_reply.started":"2023-11-24T14:32:23.840368Z","shell.execute_reply":"2023-11-24T14:32:23.847396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Define paths\nbase_dir = os.path.join(os.getcwd(), '..', 'input')\n\n# Images\nimage_names = [\n    'afa5e8098',\n    '4ef6695ce',\n    'c68fe75ea',\n    '26dc41664',\n    '095bf7a1f',\n    '54f2eec69',\n    '1e2425f28',\n    'e79de561c',\n    'cb2d976f4',\n    'b9a3865fc',\n    '8242609fa',\n    '0486052bb',\n    '2f6ecfcdf',\n    'b2dc8411c',\n    'aaa6a05cc'\n]\ntrain_images_dir = os.path.join(base_dir, 'hubmap-kidney-segmentation/train')\n\ntest_image_path = os.path.join(train_images_dir, '26dc41664.tiff')\ntest_label_path = os.path.join(train_images_dir, '26dc41664.json')\n\n# Models\nmodels_dir = os.path.join(base_dir, 'pretrained')\nunet_path = os.path.join(models_dir, 'UNet_Large_BCE_Dice_0.6_0.4_5000_16_100_best_loss.npz')\ncbam_r2unet_path = os.path.join(models_dir, 'CBAM_R2UNet_v2_Large_BCE_Dice_0.6_0.4_5000_16_100_best_loss.npz')","metadata":{"papermill":{"duration":0.013941,"end_time":"2023-11-24T00:08:16.907455","exception":false,"start_time":"2023-11-24T00:08:16.893514","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:32:23.850056Z","iopub.execute_input":"2023-11-24T14:32:23.850365Z","iopub.status.idle":"2023-11-24T14:32:23.867637Z","shell.execute_reply.started":"2023-11-24T14:32:23.850340Z","shell.execute_reply":"2023-11-24T14:32:23.866840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def test(model,test_image,test_glomeruli,image_value_lb = 100,image_value_ub = 205):\n    out_img = np.zeros((\n        int(np.ceil(test_image.shape[1] / 512) * 512),\n        int(np.ceil(test_image.shape[2] / 512) * 512)\n    ))\n    intersection = 0\n    union = 0\n    smooth = 0.00000001\n    for idx_y in tqdm(range(0, test_image.shape[1], 512)):\n        for idx_x in range(0, test_image.shape[2], 512):\n            center_x = idx_x + 512 // 2\n            center_y = idx_y + 512 // 2\n            test_patch = Patch(\n                center_x = center_x,\n                center_y = center_y,\n                theta = 0,\n                patch_size = 512,\n                glomeruli = test_glomeruli,\n                image = test_image\n            )\n            image = test_patch.render_image()\n            label = test_patch.render_mask()\n            mean = np.mean(image[0])\n            if mean >image_value_ub or mean <image_value_lb:\n                continue\n            out = model.forward(torch.unsqueeze(torch.tensor(image), 0).type(torch.cuda.FloatTensor))\n            out_array = out.cpu().detach().numpy()[0][0]\n            intersection += np.sum(out_array * label[0])\n            union += np.sum(out_array) + np.sum(label[0])\n            out_img[idx_y: idx_y+512, idx_x: idx_x+512] = out_array\n\n    diceLoss = 1 - (2 * intersection + smooth) / (union + smooth)\n    print(\"Dice_loss = \",diceLoss )\n    return out_img , diceLoss\n\ndef test_stride(model,test_image,test_glomeruli,image_value_lb = 100,image_value_ub = 205, stride=100):\n    out_img = np.zeros((\n        int(np.ceil(test_image.shape[1] / 512) * 512),\n        int(np.ceil(test_image.shape[2] / 512) * 512)\n    ))\n#     intersection = 0\n#     union = 0\n#     smooth = 0.00000001\n    for idx_y in tqdm(range(0, test_image.shape[1], stride)):\n        for idx_x in range(0, test_image.shape[2], stride):\n            center_x = idx_x + 512 // 2\n            center_y = idx_y + 512 // 2\n            test_patch = Patch(\n                center_x = center_x,\n                center_y = center_y,\n                theta = 0,\n                patch_size = 512,\n                glomeruli = test_glomeruli,\n                image = test_image\n            )\n            image = test_patch.render_image()\n            mean = np.mean(image[0])\n            if mean >image_value_ub or mean <image_value_lb:\n                continue\n            out = model.forward(torch.unsqueeze(torch.tensor(image), 0).type(torch.cuda.FloatTensor))\n            out_array = out.cpu().detach().numpy()[0][0]\n#             intersection += np.sum(out_array * label[0])\n#             union += np.sum(out_array) + np.sum(label[0])\n            out_img[idx_y: idx_y+512, idx_x: idx_x+512] += out_array\n\n#     diceLoss = 1 - (2 * intersection + smooth) / (union + smooth)\n#     print(\"Dice_loss = \",diceLoss )\n    return out_img\n\ndef test_stride_dataloader(\n        model,\n        test_image,\n        image_value_lb = 100,\n        image_value_ub = 205, \n        stride = 100,\n        windows = False,\n        batch_size = 16,\n        num_workers = 8,\n        prefetch_factor = 1\n    ):\n    \n    # Initialize array for output image\n    out_img = np.zeros((\n        int(np.ceil(test_image.shape[1] / 512) * 512),\n        int(np.ceil(test_image.shape[2] / 512) * 512)\n    ))\n    \n    # Segment input image into patches and storing into list\n    patches = []\n    patch_coordinates = []\n    for idx_y in tqdm(range(0, test_image.shape[1], stride), desc='Segmenting Image'):\n        for idx_x in range(0, test_image.shape[2], stride):\n            center_x = idx_x + 512 // 2\n            center_y = idx_y + 512 // 2\n            test_patch = Patch(\n                center_x = center_x,\n                center_y = center_y,\n                theta = 0,\n                patch_size = 512,\n                glomeruli = None,\n                image = test_image\n            )\n            \n            image = test_patch.render_image()\n            mean = np.mean(image[0])\n            if mean >image_value_ub or mean <image_value_lb:\n                continue\n            \n            patches.append(test_patch)\n            patch_coordinates.append((idx_x, idx_y))\n    \n    # Create dataset and dataloader from patches\n    patches_dataset = KidneySampleDataset(patches)\n    if windows:\n        patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False)\n    else:\n        patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers, prefetch_factor=prefetch_factor)\n    \n    # Run model\n    model.eval()\n    idx = 0\n    with torch.no_grad():\n        for inputs, labels in tqdm(patches_dataloader, desc='Running Model'):\n            # Clear gpu cache\n            gc.collect()\n            torch.cuda.empty_cache()\n            # Move data to GPU\n            inputs = torch.unsqueeze(torch.tensor(inputs.type(torch.cuda.FloatTensor).cuda()), axis=1)\n            # Run model\n            outputs = model.forward(inputs)\n            \n            out_array = torch.squeeze(outputs, axis=1).cpu().detach().numpy()\n            \n            # Loops through model output and transfer onto output image array\n            for patch in out_array:\n                idx_x = patch_coordinates[idx][0]\n                idx_y = patch_coordinates[idx][1]\n                out_img[idx_y: idx_y+512, idx_x: idx_x+512] += patch\n                idx += 1\n    del patches_dataset\n    return out_img\n\ndef test_stride_dataloader_v2(\n        model,\n        test_image,\n        image_value_lb = 100,\n        image_value_ub = 205, \n        stride = 100,\n        windows = False,\n        batch_size = 16,\n        num_workers = 8,\n        prefetch_factor = 1\n    ):\n    \n    # Initialize array for output image\n    out_img = np.zeros((\n        int(np.ceil(test_image.shape[1] / 512) * 512),\n        int(np.ceil(test_image.shape[2] / 512) * 512)\n    ))\n    \n    # Segment input image into patches and storing into list\n    \n    for idx_y in tqdm(range(0, test_image.shape[1], stride), desc='Segmenting Image'):\n        patches = []\n        patch_coordinates = []\n    \n        for idx_x in range(0, test_image.shape[2], stride):\n            center_x = idx_x + 512 // 2\n            center_y = idx_y + 512 // 2\n            test_patch = Patch(\n                center_x = center_x,\n                center_y = center_y,\n                theta = 0,\n                patch_size = 512,\n                glomeruli = None,\n                image = test_image\n            )\n            \n            image = test_patch.render_image()\n            mean = np.mean(image[0])\n            if mean >image_value_ub or mean <image_value_lb:\n                continue\n            \n            patches.append(test_patch)\n            patch_coordinates.append((idx_x, idx_y))\n            \n        if len(patches) > 0:\n            print(patches)\n            # Create dataset and dataloader from patches\n            patches_dataset = KidneySampleDataset(patches)\n\n            if windows:\n                patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False)\n            else:\n                patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers, prefetch_factor=prefetch_factor)\n\n            # Run model\n            model.eval()\n            idx = 0\n            with torch.no_grad():\n                for inputs, labels in patches_dataloader:\n                    # Clear gpu cache\n                    gc.collect()\n                    torch.cuda.empty_cache()\n                    # Move data to GPU\n                    inputs = torch.unsqueeze(torch.tensor(inputs.type(torch.cuda.FloatTensor).cuda()), axis=1)\n                    # Run model\n                    outputs = model.forward(inputs)\n\n                    out_array = torch.squeeze(outputs, axis=1).cpu().detach().numpy()\n\n                    # Loops through model output and transfer onto output image array\n                    for patch in out_array:\n                        idx_x = patch_coordinates[idx][0]\n                        idx_y = patch_coordinates[idx][1]\n                        out_img[idx_y: idx_y+512, idx_x: idx_x+512] += patch\n                        idx += 1\n    return out_img\ndef test_stride_dataloader_v3( \n        model, \n        test_image, \n        image_value_lb = 100, \n        image_value_ub = 205,  \n        stride = 100, \n        windows = False, \n        batch_size = 16, \n        num_workers = 8, \n        prefetch_factor = 1 \n    ): \n     \n    out_img = np.zeros(( \n        int(np.ceil(test_image.shape[1] / 512) * 512), \n        int(np.ceil(test_image.shape[2] / 512) * 512) \n    )) \n    out_img = np.where(out_img >= 0.5, 1, 0).astype(np.uint8)\n    patches = [] \n    patch_coordinates = [] \n    for idx_y in tqdm(range(0, test_image.shape[1], stride), desc='Segmenting Image'): \n        for idx_x in range(0, test_image.shape[2], stride): \n            center_x = idx_x + 512 // 2 \n            center_y = idx_y + 512 // 2 \n            test_patch = Patch( \n                center_x = center_x, \n                center_y = center_y, \n                theta = 0, \n                patch_size = 512, \n                glomeruli = None, \n                image = test_image \n            ) \n             \n            image = test_patch.render_image() \n            mean = np.mean(image[0]) \n            del image\n            if mean >image_value_ub or mean <image_value_lb: \n                continue \n             \n            patches.append(test_patch) \n            patch_coordinates.append((idx_x, idx_y)) \n     \n    patches_dataset = KidneySampleDataset(patches) \n    if windows: \n        patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False) \n    else: \n        patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers, prefetch_factor=prefetch_factor) \n     \n    model.eval() \n    idx = 0 \n    with torch.no_grad(): \n        for inputs, labels in tqdm(patches_dataloader, desc='Running Model'): \n            gc.collect() \n            torch.cuda.empty_cache() \n            # Move data to GPU \n            inputs = torch.unsqueeze(torch.tensor(inputs.type(torch.cuda.FloatTensor).cuda()), axis=1) \n            # Run model \n            outputs = model.forward(inputs) \n             \n            out_array = torch.squeeze(outputs, axis=1).cpu().detach().numpy() \n             \n \n            for patch in out_array: \n                idx_x = patch_coordinates[idx][0] \n                idx_y = patch_coordinates[idx][1] \n                patch = np.where(patch>0.5,1,0).astype(np.uint8)\n                out_img[idx_y: idx_y+512, idx_x: idx_x+512] += patch \n                idx += 1 \n                del patch\n            del inputs\n    del patches_dataloader\n    del patch_coordinates\n    del patches\n    del patches_dataset\n    gc.collect()\n    return out_img\n\ndef test_stride_dataloader_v4(\n        model1,\n        model2,\n        test_image,\n        image_value_lb = 100,\n        image_value_ub = 205, \n        stride = 100,\n        windows = False,\n        batch_size = 16,\n        num_workers = 8,\n        prefetch_factor = 1,\n        size_lowerbound = 10000,\n    ):\n    \n    # Initialize array for output image\n    out_img = np.zeros((test_image.shape[1],test_image.shape[2]), dtype=np.uint8)\n    \n    \n    patches = []\n    patch_coordinates = []\n    \n    # Segment input image into patches and storing into list\n    for idx_y in tqdm(range(0, test_image.shape[1], stride), desc='Segmenting Image'):\n        for idx_x in range(0, test_image.shape[2], stride):\n            \n            # Generate patch object\n            center_x = idx_x + 512 // 2\n            center_y = idx_y + 512 // 2\n            test_patch = Patch(\n                center_x = center_x,\n                center_y = center_y,\n                theta = 0,\n                patch_size = 512,\n                glomeruli = None,\n                image = test_image\n            )\n            \n            # Render patch image and test if kidney sample is present through thresholding\n            # Too dark / light means the patch is empty\n            image = test_patch.render_image()\n            mean = np.mean(image[0])\n            if mean >image_value_ub or mean <image_value_lb:\n                continue\n            \n            # Add patch to list\n            patches.append(test_patch)\n            patch_coordinates.append((idx_x, idx_y))\n            \n            del image\n            \n            # Process patches in batch\n            if len(patches) >= 16:\n                # Create dataset and dataloader from patches\n                patches_dataset = KidneySampleDataset(patches)\n                if windows:\n                    patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False)\n                else:\n                    patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers, prefetch_factor=prefetch_factor)\n\n                # Run model\n                model1.eval()\n                model2.eval()\n                idx = 0\n                with torch.no_grad():\n                    for inputs, labels in patches_dataloader:\n                        # Clear gpu cache\n                        gc.collect()\n                        torch.cuda.empty_cache()\n                        # Move data to GPU\n                        inputs = torch.unsqueeze(torch.tensor(inputs.type(torch.cuda.FloatTensor)), axis=1)\n                        \n                        # Run and get outputs from both models\n                        outputs1 = model1.forward(inputs.cuda(device=0))\n                        outputs2 = model2.forward(inputs.cuda(device=0))\n                        del inputs\n                        \n                        # Transfer output tensors from gpus and convert to numpy\n                        out_array1 = torch.squeeze(outputs1, axis=1).cpu().detach().numpy()\n                        out_array2 = torch.squeeze(outputs2, axis=1).cpu().detach().numpy()\n                        del outputs1\n                        del outputs2\n                        \n                        # === Post processing model1 output ===\n                        \n                        prev_idx = idx\n                        # Loops through model output and transfer onto output image array\n                        for patch in out_array1:\n                            # Convert to binary\n                            patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                            # Find connected components and get area\n                            nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                            areas = stats[1:,cv2.CC_STAT_AREA]\n\n                            del stats\n                            del centroids\n\n                            patch = np.zeros((labels.shape), np.uint8)\n\n                            # Copy over only components with areas above threshold to remove small noise\n                            for i in range(0, nlabels - 1):\n                                if areas[i] >= size_lowerbound:\n                                    patch[labels == i + 1] = 1\n\n                            del nlabels\n                            del labels\n                            \n                            # Transfer postprocessed output to output image\n                            idx_x = patch_coordinates[idx][0]\n                            idx_y = patch_coordinates[idx][1]\n\n                            max_y = min(idx_y+512, test_image.shape[1])\n                            max_x = min(idx_x+512, test_image.shape[2])\n                            \n                            out_img[idx_y: max_y, idx_x: max_x] += patch[:max_y - idx_y, :max_x - idx_x]\n                            idx += 1\n                        del out_array1\n                        \n                        # === Post processing model2 output ===\n                        \n                        idx = prev_idx\n                        # Loops through model output and transfer onto output image array\n                        for patch in out_array2:\n                            # Converty to binary\n                            patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                            # Find connected components and get area\n                            nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                            areas = stats[1:,cv2.CC_STAT_AREA]\n\n                            del stats\n                            del centroids\n\n                            patch = np.zeros((labels.shape), np.uint8)\n\n                            # Copy over only components with areas above threshold to remove small noise\n                            for i in range(0, nlabels - 1):\n                                if areas[i] >= size_lowerbound:\n                                    patch[labels == i + 1] = 1\n\n                            del nlabels\n                            del labels\n                            \n                            # Transfer postprocessed output to output image\n                            idx_x = patch_coordinates[idx][0]\n                            idx_y = patch_coordinates[idx][1]\n                            \n                            max_y = min(idx_y+512, test_image.shape[1])\n                            max_x = min(idx_x+512, test_image.shape[2])\n                            \n                            out_img[idx_y: max_y, idx_x: max_x] = np.where(out_img[idx_y: max_y, idx_x: max_x] + patch[:max_y - idx_y, :max_x - idx_x] >= 1, 1, 0)\n                            idx += 1\n                        del out_array2\n                del patches\n                del patch_coordinates\n                del patches_dataloader\n                \n                patches = []\n                patch_coordinates = []\n                \n    # Process last patches if number of patches isn't divisible by 16\n    if len(patches) > 0:\n        # Create dataset and dataloader from patches\n        patches_dataset = KidneySampleDataset(patches)\n        if windows:\n            patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False)\n        else:\n            patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers, prefetch_factor=prefetch_factor)\n\n        # Run model\n        model1.eval()\n        model2.eval()\n        idx = 0\n        with torch.no_grad():\n            for inputs, labels in patches_dataloader:\n                # Clear gpu cache\n                gc.collect()\n                torch.cuda.empty_cache()\n                # Move data to GPU\n                inputs = torch.unsqueeze(torch.tensor(inputs.type(torch.cuda.FloatTensor)), axis=1)\n                \n                # Run and get outputs from both models\n                outputs1 = model1.forward(inputs.cuda(device=0))\n                outputs2 = model2.forward(inputs.cuda(device=0))\n                del inputs\n\n                # Transfer output tensors from gpus and convert to numpy\n                out_array1 = torch.squeeze(outputs1, axis=1).cpu().detach().numpy()\n                out_array2 = torch.squeeze(outputs2, axis=1).cpu().detach().numpy()\n                del outputs1\n                del outputs2\n                \n                # === Post processing model1 output ===\n                        \n                prev_idx = idx\n                # Loops through model output and transfer onto output image array\n                for patch in out_array1:\n                    # Convert to binary\n                    patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                    # Find connected components and get area\n                    nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                    areas = stats[1:,cv2.CC_STAT_AREA]\n\n                    del stats\n                    del centroids\n\n                    patch = np.zeros((labels.shape), np.uint8)\n\n                    # Copy over only components with areas above threshold to remove small noise\n                    for i in range(0, nlabels - 1):\n                        if areas[i] >= size_lowerbound:\n                            patch[labels == i + 1] = 1\n\n                    del nlabels\n                    del labels\n\n                    # Transfer postprocessed output to output image\n                    idx_x = patch_coordinates[idx][0]\n                    idx_y = patch_coordinates[idx][1]\n                    \n                    max_y = min(idx_y+512, test_image.shape[1])\n                    max_x = min(idx_x+512, test_image.shape[2])\n                    \n                    out_img[idx_y: max_y, idx_x: max_x] += patch[:max_y - idx_y, :max_x - idx_x]\n                    idx += 1\n                del out_array1\n\n                # === Post processing model2 output ===\n\n                idx = prev_idx\n                # Loops through model output and transfer onto output image array\n                for patch in out_array2:\n                    # Converty to binary\n                    patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                    # Find connected components and get area\n                    nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                    areas = stats[1:,cv2.CC_STAT_AREA]\n\n                    del stats\n                    del centroids\n\n                    patch = np.zeros((labels.shape), np.uint8)\n\n                    # Copy over only components with areas above threshold to remove small noise\n                    for i in range(0, nlabels - 1):\n                        if areas[i] >= size_lowerbound:\n                            patch[labels == i + 1] = 1\n\n                    del nlabels\n                    del labels\n\n                    # Transfer postprocessed output to output image\n                    idx_x = patch_coordinates[idx][0]\n                    idx_y = patch_coordinates[idx][1]\n                    max_y = min(idx_y+512, test_image.shape[1])\n                    max_x = min(idx_x+512, test_image.shape[2])\n                    out_img[idx_y: max_y, idx_x: max_x] = np.where(out_img[idx_y: max_y, idx_x: max_x] + patch[:max_y - idx_y, :max_x - idx_x] >= 1, 1, 0)\n                    idx += 1\n                del out_array2\n    return out_img\n\n# Generate ensemble model output from image\ndef test_stride_dataloader_v5(\n        model1,\n        model2,\n        test_image,\n        image_value_lb = 100,\n        image_value_ub = 205, \n        stride = 100,\n        windows = False,\n        batch_size = 16,\n        num_workers = 8,\n        prefetch_factor = 1,\n        size_lowerbound = 10000,\n    ):\n\n    img_height = test_image.shape[1]\n    img_width = test_image.shape[2]\n    \n    # Initialize array for output image\n    out_img = np.zeros((img_height,img_width), dtype=np.uint8)\n    \n    \n    patches = []\n    patch_coordinates = []\n\n    os.makedirs('../temp', exist_ok=True)\n\n    num_chunk = 0\n    # Segment input image into patches and storing into list\n    for idx_y in tqdm(range(0, img_height, stride), desc='Segmenting Image'):\n        for idx_x in range(0, img_width, stride):\n            \n            # Generate patch object\n            center_x = idx_x + 512 // 2\n            center_y = idx_y + 512 // 2\n            test_patch = Patch(\n                center_x = center_x,\n                center_y = center_y,\n                theta = 0,\n                patch_size = 512,\n                glomeruli = None,\n                image = test_image\n            )\n            \n            # Render patch image and test if kidney sample is present through thresholding\n            # Too dark / light means the patch is empty\n            image = test_patch.render_image()\n            mean = np.mean(image[0])\n            if mean >image_value_ub or mean <image_value_lb:\n                continue\n            \n            # Add patch to list\n            patches.append(test_patch)\n            patch_coordinates.append((idx_x, idx_y))\n            \n            del image\n\n            if len(patches) >= 64:\n                patches_dataset = KidneySampleDataset(patches)\n                patches_dataset.save(f'../temp/chunk_{num_chunk}.npy')\n                np.save(f'../temp/coor_{num_chunk}.npy', np.array(patch_coordinates))\n                num_chunk += 1\n\n                del patches_dataset\n\n                patches = []\n                patch_coordinates = []\n    if len(patches) > 0:\n        patches_dataset = KidneySampleDataset(patches)\n        patches_dataset.save(f'../temp/chunk_{num_chunk}.npy')\n        np.save(f'../temp/coor_{num_chunk}.npy', np.array(patch_coordinates))\n        num_chunk += 1\n\n        del patches_dataset\n        del patches\n        del patch_coordinates\n\n    del test_image\n\n    for idx_chunk in tqdm(range(num_chunk), desc='Processing Chunks'):\n        patches_dataset = KidneySampleDataset()\n        patches_dataset.load(f'../temp/chunk_{idx_chunk}.npy')\n        os.remove(f'../temp/chunk_{idx_chunk}.npy')\n\n        patch_coordinates = np.load(f'../temp/coor_{idx_chunk}.npy')\n        os.remove(f'../temp/coor_{idx_chunk}.npy')\n\n        if windows:\n            patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False)\n        else:\n            patches_dataloader = DataLoader(patches_dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers, prefetch_factor=prefetch_factor)\n\n        model1.eval()\n        model2.eval()\n        idx = 0\n        with torch.no_grad():\n            for inputs, labels in patches_dataloader:\n                # Clear gpu cache\n                gc.collect()\n                torch.cuda.empty_cache()\n                # Move data to GPU\n                inputs = torch.unsqueeze(torch.tensor(inputs.type(torch.cuda.FloatTensor)), axis=1)\n                \n                # Run and get outputs from both models\n                outputs1 = model1.forward(inputs.cuda(device=0))\n                outputs2 = model2.forward(inputs.cuda(device=0))\n                del inputs\n                \n                # Transfer output tensors from gpus and convert to numpy\n                out_array1 = torch.squeeze(outputs1, axis=1).cpu().detach().numpy()\n                out_array2 = torch.squeeze(outputs2, axis=1).cpu().detach().numpy()\n                del outputs1\n                del outputs2\n                \n                # === Post processing model1 output ===\n                \n                prev_idx = idx\n                # Loops through model output and transfer onto output image array\n                for patch in out_array1:\n                    # Convert to binary\n                    patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                    # Find connected components and get area\n                    nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                    areas = stats[1:,cv2.CC_STAT_AREA]\n\n                    del stats\n                    del centroids\n\n                    patch = np.zeros((labels.shape), np.uint8)\n\n                    # Copy over only components with areas above threshold to remove small noise\n                    for i in range(0, nlabels - 1):\n                        if areas[i] >= size_lowerbound:\n                            patch[labels == i + 1] = 1\n\n                    del nlabels\n                    del labels\n                    \n                    # Transfer postprocessed output to output image\n                    idx_x = patch_coordinates[idx][0]\n                    idx_y = patch_coordinates[idx][1]\n\n                    max_y = min(idx_y+512, img_height)\n                    max_x = min(idx_x+512, img_width)\n                    \n                    out_img[idx_y: max_y, idx_x: max_x] += patch[:max_y - idx_y, :max_x - idx_x]\n                    idx += 1\n                del out_array1\n                \n                # === Post processing model2 output ===\n                \n                idx = prev_idx\n                # Loops through model output and transfer onto output image array\n                for patch in out_array2:\n                    # Converty to binary\n                    patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                    # Find connected components and get area\n                    nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                    areas = stats[1:,cv2.CC_STAT_AREA]\n\n                    del stats\n                    del centroids\n\n                    patch = np.zeros((labels.shape), np.uint8)\n\n                    # Copy over only components with areas above threshold to remove small noise\n                    for i in range(0, nlabels - 1):\n                        if areas[i] >= size_lowerbound:\n                            patch[labels == i + 1] = 1\n\n                    del nlabels\n                    del labels\n                    \n                    # Transfer postprocessed output to output image\n                    idx_x = patch_coordinates[idx][0]\n                    idx_y = patch_coordinates[idx][1]\n                    \n                    max_y = min(idx_y+512, img_height)\n                    max_x = min(idx_x+512, img_width)\n                    \n                    out_img[idx_y: max_y, idx_x: max_x] = np.where(out_img[idx_y: max_y, idx_x: max_x] + patch[:max_y - idx_y, :max_x - idx_x] >= 1, 1, 0)\n                    idx += 1\n                del out_array2\n    return out_img\n\ndef test_stride_dataloader_v6(\n        model1,\n        model2,\n        test_image,\n        image_value_lb = 100,\n        image_value_ub = 205, \n        stride = 100,\n        windows = False,\n        batch_size = 16,\n        num_workers = 8,\n        prefetch_factor = 1,\n        size_lowerbound = 10000,\n    ):\n    \n    # Initialize array for output image\n    out_img = np.zeros((test_image.shape[0],test_image.shape[1]), dtype=np.uint8)\n    \n    \n    patches = []\n    patch_coordinates = []\n    last_y = False\n    # Segment input image into patches and storing into list\n    for idx_y in tqdm(range(0, test_image.shape[0], stride), desc='Segmenting Image'):\n        if idx_y + 512 > test_image.shape[0]:\n            last_y = True\n            idx_y = test_image.shape[0] - 512\n        last_x = False\n        for idx_x in range(0, test_image.shape[1], stride):\n            if idx_x + 512 > test_image.shape[1]:\n                last_x = True\n                idx_x = test_image.shape[1] - 512\n                \n            patch = test_image[idx_y:idx_y+512, idx_x:idx_x+512]\n            \n            # Render patch image and test if kidney sample is present through thresholding\n            # Too dark / light means the patch is empty\n            mean = np.mean(patch)\n            if mean >image_value_ub or mean <image_value_lb:\n                continue\n            \n            # Add patch to list\n            patches.append(patch)\n            patch_coordinates.append((idx_x, idx_y))\n            \n            # Process patches in batch\n            if len(patches) >= 16:\n                input_list = [torch.unsqueeze(torch.from_numpy(arr), 0) for arr in patches]\n                inputs = torch.stack(input_list, dim=0)\n                \n                \n                # Run model\n                model1.eval()\n                model2.eval()\n                idx = 0\n                with torch.no_grad():\n                    # Clear gpu cache\n                    gc.collect()\n                    torch.cuda.empty_cache()\n                    # Move data to GPU\n                    inputs = inputs.type(torch.cuda.FloatTensor)\n\n                    # Run and get outputs from both models\n                    outputs1 = model1.forward(inputs.cuda(device=0))\n                    outputs2 = model2.forward(inputs.cuda(device=0))\n\n                    # Transfer output tensors from gpus and convert to numpy\n                    out_array1 = torch.squeeze(outputs1, axis=1).cpu().detach().numpy()\n                    out_array2 = torch.squeeze(outputs2, axis=1).cpu().detach().numpy()\n                    del outputs1\n                    del outputs2\n\n                    # === Post processing model1 output ===\n\n                    prev_idx = idx\n                    # Loops through model output and transfer onto output image array\n                    for patch in out_array1:\n                        # Convert to binary\n                        patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                        # Find connected components and get area\n                        nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                        areas = stats[1:,cv2.CC_STAT_AREA]\n\n                        del stats\n                        del centroids\n\n                        patch = np.zeros((labels.shape), np.uint8)\n\n                        # Copy over only components with areas above threshold to remove small noise\n                        for i in range(0, nlabels - 1):\n                            if areas[i] >= size_lowerbound:\n                                patch[labels == i + 1] = 1\n\n                        del nlabels\n                        del labels\n\n                        # Transfer postprocessed output to output image\n                        idx_x = patch_coordinates[idx][0]\n                        idx_y = patch_coordinates[idx][1]\n\n                        out_img[idx_y: idx_y + 512, idx_x: idx_x + 512] += patch\n                        idx += 1\n                    del out_array1\n\n                    # === Post processing model2 output ===\n\n                    idx = prev_idx\n                    # Loops through model output and transfer onto output image array\n                    for patch in out_array2:\n                        # Converty to binary\n                        patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                        # Find connected components and get area\n                        nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                        areas = stats[1:,cv2.CC_STAT_AREA]\n\n                        del stats\n                        del centroids\n\n                        patch = np.zeros((labels.shape), np.uint8)\n\n                        # Copy over only components with areas above threshold to remove small noise\n                        for i in range(0, nlabels - 1):\n                            if areas[i] >= size_lowerbound:\n                                patch[labels == i + 1] = 1\n\n                        del nlabels\n                        del labels\n\n                        # Transfer postprocessed output to output image\n                        idx_x = patch_coordinates[idx][0]\n                        idx_y = patch_coordinates[idx][1]\n\n                        out_img[idx_y: idx_y + 512, idx_x: idx_x + 512] = np.where(out_img[idx_y: idx_y + 512, idx_x: idx_x + 512] + patch >= 1, 1, 0)\n                        idx += 1\n                    del out_array2\n                del patches\n                del patch_coordinates\n                \n                patches = []\n                patch_coordinates = []\n            if last_x:\n                break\n        if last_y:\n            break\n    # Process last patches if number of patches isn't divisible by 16\n    if len(patches) > 0:\n        input_list = [torch.unsqueeze(torch.from_numpy(arr), 0) for arr in patches]\n        inputs = torch.stack(input_list, dim=0)\n\n        # Run model\n        model1.eval()\n        model2.eval()\n        idx = 0\n        with torch.no_grad():\n            # Clear gpu cache\n            gc.collect()\n            torch.cuda.empty_cache()\n            # Move data to GPU\n            inputs = inputs.type(torch.cuda.FloatTensor)\n\n            # Run and get outputs from both models\n            outputs1 = model1.forward(inputs.cuda(device=0))\n            outputs2 = model2.forward(inputs.cuda(device=0))\n\n            # Transfer output tensors from gpus and convert to numpy\n            out_array1 = torch.squeeze(outputs1, axis=1).cpu().detach().numpy()\n            out_array2 = torch.squeeze(outputs2, axis=1).cpu().detach().numpy()\n            del outputs1\n            del outputs2\n\n            # === Post processing model1 output ===\n\n            prev_idx = idx\n            # Loops through model output and transfer onto output image array\n            for patch in out_array1:\n                # Convert to binary\n                patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                # Find connected components and get area\n                nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                areas = stats[1:,cv2.CC_STAT_AREA]\n\n                del stats\n                del centroids\n\n                patch = np.zeros((labels.shape), np.uint8)\n\n                # Copy over only components with areas above threshold to remove small noise\n                for i in range(0, nlabels - 1):\n                    if areas[i] >= size_lowerbound:\n                        patch[labels == i + 1] = 1\n\n                del nlabels\n                del labels\n\n                # Transfer postprocessed output to output image\n                idx_x = patch_coordinates[idx][0]\n                idx_y = patch_coordinates[idx][1]\n\n                out_img[idx_y: idx_y + 512, idx_x: idx_x + 512] += patch\n                idx += 1\n            del out_array1\n\n            # === Post processing model2 output ===\n\n            idx = prev_idx\n            # Loops through model output and transfer onto output image array\n            for patch in out_array2:\n                # Converty to binary\n                patch = np.where(patch >= 0.5, 1, 0).astype(np.uint8)\n\n                # Find connected components and get area\n                nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(patch, 8, cv2.CV_32S)\n                areas = stats[1:,cv2.CC_STAT_AREA]\n\n                del stats\n                del centroids\n\n                patch = np.zeros((labels.shape), np.uint8)\n\n                # Copy over only components with areas above threshold to remove small noise\n                for i in range(0, nlabels - 1):\n                    if areas[i] >= size_lowerbound:\n                        patch[labels == i + 1] = 1\n\n                del nlabels\n                del labels\n\n                # Transfer postprocessed output to output image\n                idx_x = patch_coordinates[idx][0]\n                idx_y = patch_coordinates[idx][1]\n\n                out_img[idx_y: idx_y + 512, idx_x: idx_x + 512] = np.where(out_img[idx_y: idx_y + 512, idx_x: idx_x + 512] + patch >= 1, 1, 0)\n                idx += 1\n            del out_array2\n    return out_img","metadata":{"papermill":{"duration":0.187491,"end_time":"2023-11-24T00:08:17.099436","exception":false,"start_time":"2023-11-24T00:08:16.911945","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:32:23.871993Z","iopub.execute_input":"2023-11-24T14:32:23.872258Z","iopub.status.idle":"2023-11-24T14:32:24.121107Z","shell.execute_reply.started":"2023-11-24T14:32:23.872235Z","shell.execute_reply":"2023-11-24T14:32:24.120136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def save_image_chunks(image, image_value_lb=100, image_value_ub=205):\n    patches = []\n    patch_coordinates = []\n\n    os.mkdirs('./image_chunks')\n    \n    # Segment input image into patches and storing into list\n    for idx_y in tqdm(range(0, image.shape[1], stride), desc='Segmenting Image'):\n        for idx_x in range(0, image.shape[2], stride):\n            # Generate patch object\n            center_x = idx_x + 512 // 2\n            center_y = idx_y + 512 // 2\n            patch = Patch(\n                center_x = center_x,\n                center_y = center_y,\n                theta = 0,\n                patch_size = 512,\n                glomeruli = None,\n                image = image\n            )\n            \n            # Render patch image and test if kidney sample is present through thresholding\n            # Too dark / light means the patch is empty\n            patch_image = patch.render_image()\n            mean = np.mean(image[0])\n            if mean >image_value_ub or mean <image_value_lb:\n                continue\n            \n            # Add patch to list\n            patches.append(test_patch)\n            patch_coordinates.append((idx_x, idx_y))\n            \n            del patch_image\n\n            if len(patches >= 16):\n                patches_dataset = KidneySampleDataset(patches)\n                \n            ","metadata":{"execution":{"iopub.status.busy":"2023-11-24T14:32:24.122176Z","iopub.execute_input":"2023-11-24T14:32:24.122461Z","iopub.status.idle":"2023-11-24T14:32:24.137244Z","shell.execute_reply.started":"2023-11-24T14:32:24.122435Z","shell.execute_reply":"2023-11-24T14:32:24.136478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ndf_sample = pd.read_csv('../input/hubmap-kidney-segmentation/sample_submission.csv')\ndisplay(df_sample)\n\nimport numba\n@numba.njit()\ndef rle_encode(pixels):\n    rle_list = []\n    index_pixel = 0\n    count = 0\n    \n    for pixel in pixels:\n        index_pixel += 1\n        \n        # Records the starting position where pixel is included\n        if pixel == 1:\n            if count == 0:\n                start_position = index_pixel\n            count += 1\n            \n        # Count acts as both counter of run-length and flag. \n        elif count > 0:\n            # records the starting position and the run-length\n            rle_list.extend([start_position, count])\n            # count = 0 indicates no need to run anything if current pixel = 0\n            count = 0\n\n    # If last pixel is still 1 --> not yet included in rle_list --> record them.\n    if count > 0:\n        rle_list.extend([start_position, count])\n\n    return rle_list\n\ndef rle_string(binary_image):\n    pixels = binary_image.flatten(order = 'F') # Top to bottom, then Left to right\n    rle_list = rle_encode(pixels)\n    rle_string = ' '.join(map(str, rle_list))\n    return rle_string","metadata":{"papermill":{"duration":0.810295,"end_time":"2023-11-24T00:08:17.914700","exception":false,"start_time":"2023-11-24T00:08:17.104405","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:32:24.138347Z","iopub.execute_input":"2023-11-24T14:32:24.138632Z","iopub.status.idle":"2023-11-24T14:32:24.351954Z","shell.execute_reply.started":"2023-11-24T14:32:24.138607Z","shell.execute_reply":"2023-11-24T14:32:24.350967Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import time\nimport rasterio\nstart_time = time.time()\nstride = 512\ntest_images_dir = os.path.join(base_dir, 'hubmap-kidney-segmentation/test')\ntest_image_names = df_sample['id'].tolist()\n\nsubmission = {}\n\nmodel1 = UNet_Large((256, 256), (512, 512)).cuda()\nmodel1.load_state_dict(torch.load(unet_path,map_location='cuda:0'))\nmodel2 = CBAM_R2UNet_v2_Large((256, 256), (512, 512)).cuda()\nmodel2.load_state_dict(torch.load(cbam_r2unet_path,map_location='cuda:0'))\n\nfor img_id, image_name in tqdm(enumerate(test_image_names), total=len(test_image_names)):\n    print(f'Processing {image_name}')\n    test_image_path = os.path.join(test_images_dir, f'{image_name}.tiff')\n    test_image = read_tiff(test_image_path)\n    print(test_image.shape)\n    # Run Models\n    print('Running Model')\n    out = test_stride_dataloader_v6(model1, model2, test_image, stride=stride, windows=True)\n    del test_image\n    gc.collect()\n\n    # Plot Result\n#     plt.figure(figsize=(15, 15))\n#     plt.title(f'{image_name} Output (Ensemble, stride = {stride})')\n#     plt.imshow(out)\n#     plt.savefig(f'./test_runs/{image_name}_ensemble.png')\n    \n    # Encode binary image to RLE format and append to result\n    print('Converting Output')\n    submission[img_id] = {'id':image_name, 'predicted': rle_string(out)}\n    del out\n    gc.collect()\n    \ndel model1\ndel model2\ngc.collect()\n    \nruntime = np.round(time.time() - start_time, 2)","metadata":{"papermill":{"duration":1765.740986,"end_time":"2023-11-24T00:37:43.660661","exception":false,"start_time":"2023-11-24T00:08:17.919675","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:32:24.353371Z","iopub.execute_input":"2023-11-24T14:32:24.353695Z","iopub.status.idle":"2023-11-24T14:34:29.106176Z","shell.execute_reply.started":"2023-11-24T14:32:24.353668Z","shell.execute_reply":"2023-11-24T14:34:29.105175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'Runtime = {runtime}')","metadata":{"papermill":{"duration":0.015456,"end_time":"2023-11-24T00:37:43.683710","exception":false,"start_time":"2023-11-24T00:37:43.668254","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:34:29.108933Z","iopub.execute_input":"2023-11-24T14:34:29.109230Z","iopub.status.idle":"2023-11-24T14:34:29.114372Z","shell.execute_reply.started":"2023-11-24T14:34:29.109205Z","shell.execute_reply":"2023-11-24T14:34:29.113378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame.from_dict(submission, orient='index')\nsubmission.to_csv(f'submission.csv', index=False)\nsubmission","metadata":{"papermill":{"duration":0.501335,"end_time":"2023-11-24T00:37:44.192135","exception":false,"start_time":"2023-11-24T00:37:43.690800","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:34:29.115587Z","iopub.execute_input":"2023-11-24T14:34:29.115871Z","iopub.status.idle":"2023-11-24T14:34:29.132223Z","shell.execute_reply.started":"2023-11-24T14:34:29.115846Z","shell.execute_reply":"2023-11-24T14:34:29.131083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%reset -f out","metadata":{"papermill":{"duration":0.258396,"end_time":"2023-11-24T00:37:44.457897","exception":false,"start_time":"2023-11-24T00:37:44.199501","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2023-11-24T14:34:29.133396Z","iopub.execute_input":"2023-11-24T14:34:29.133667Z","iopub.status.idle":"2023-11-24T14:34:29.340489Z","shell.execute_reply.started":"2023-11-24T14:34:29.133644Z","shell.execute_reply":"2023-11-24T14:34:29.339340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_sample = pd.read_csv('submission.csv')\n# display(df_sample)","metadata":{"execution":{"iopub.status.busy":"2023-11-24T14:34:29.341865Z","iopub.execute_input":"2023-11-24T14:34:29.342789Z","iopub.status.idle":"2023-11-24T14:34:29.350184Z","shell.execute_reply.started":"2023-11-24T14:34:29.342751Z","shell.execute_reply":"2023-11-24T14:34:29.349288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def rle_decode(mask_rle, shape=(256, 256)):\n#     '''\n#     mask_rle: run-length as string formated (start length)\n#     shape: (height,width) of array to return \n#     Returns numpy array, 1 - mask, 0 - background\n\n#     '''\n#     s = mask_rle.split()\n#     starts, lengths = [np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])]\n#     starts -= 1\n#     ends = starts + lengths\n#     img = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n#     for lo, hi in zip(starts, ends):\n#         img[lo:hi] = 1\n#     return img.reshape(shape, order='F')","metadata":{"execution":{"iopub.status.busy":"2023-11-24T14:34:29.351296Z","iopub.execute_input":"2023-11-24T14:34:29.352097Z","iopub.status.idle":"2023-11-24T14:34:29.362237Z","shell.execute_reply.started":"2023-11-24T14:34:29.352064Z","shell.execute_reply":"2023-11-24T14:34:29.361482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# plt.imshow(rle_decode(df_sample['predicted'][0], (33240, 43160)))","metadata":{"execution":{"iopub.status.busy":"2023-11-24T14:34:29.363387Z","iopub.execute_input":"2023-11-24T14:34:29.363724Z","iopub.status.idle":"2023-11-24T14:34:29.377765Z","shell.execute_reply.started":"2023-11-24T14:34:29.363698Z","shell.execute_reply":"2023-11-24T14:34:29.376647Z"},"trusted":true},"execution_count":null,"outputs":[]}]}