{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.12"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":92860,"databundleVersionId":11074257,"sourceType":"competition"}],"dockerImageVersionId":30919,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true},"papermill":{"default_parameters":{},"duration":7123.280269,"end_time":"2025-02-25T23:17:11.796638","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2025-02-25T21:18:28.516369","version":"2.6.0"},"widgets":{"application/vnd.jupyter.widget-state+json":{"state":{"003dfdc40926413f8b555a4eb759c2a1":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"12c9ceec3db64b149cf553d96805739d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"1555745dda784271880b3e869a8c241a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"16b7c48061414f7e876a71c7599bd8e5":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"170a4f1c38524177a75662cf08b20bad":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"1e8f4857a61a4b20aa97f02ebd04c4fe":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_ea52bf56abea40e1aca344660e14098f","max":256802365,"min":0,"orientation":"horizontal","style":"IPY_MODEL_7d1398562d984dc0a72dd4f051eb6ae7","tabbable":null,"tooltip":null,"value":256802365}},"22ba1d061e0b4211a9fe1240626d6287":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_86e7acb03c7b45f690a23e5e2a61d3d9","IPY_MODEL_1e8f4857a61a4b20aa97f02ebd04c4fe","IPY_MODEL_bc0ebc176a2e450f9776b577bce3a15f"],"layout":"IPY_MODEL_a00b454af6274e7c819dca12e7e5851e","tabbable":null,"tooltip":null}},"28141aaaae144dd181ed24f0057a1215":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"3aea3a97cfb44bb0969144356c78e70d":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"480b81a4cd5345ae8761d1dc1093d47d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"5f06a865614f4622a7d5ee3540d4a866":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_c8b51973837f4ab1bc6c1a6eaec5c098","max":271,"min":0,"orientation":"horizontal","style":"IPY_MODEL_12c9ceec3db64b149cf553d96805739d","tabbable":null,"tooltip":null,"value":271}},"66cc3092f8a6401f8896c7d52d979b25":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"7919e9951b444eefb1f898acfe72f481":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_bc8fb6dc18d0408b8293470f8333f771","IPY_MODEL_b89da1ae67134026b48aea08bd9d8206","IPY_MODEL_7e03c8eb6261471e865ceca79b9886cb"],"layout":"IPY_MODEL_28141aaaae144dd181ed24f0057a1215","tabbable":null,"tooltip":null}},"7d1398562d984dc0a72dd4f051eb6ae7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"7e03c8eb6261471e865ceca79b9886cb":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_ad30bcb1f47c4ebe9eff49728f4c559d","placeholder":"​","style":"IPY_MODEL_003dfdc40926413f8b555a4eb759c2a1","tabbable":null,"tooltip":null,"value":" 6.89k/6.89k [00:00&lt;00:00, 700kB/s]"}},"8265633cc2c94726abf4bb0607ced1a7":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"84a9f76413fe4eb1a63d1636b4f32edd":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"86e7acb03c7b45f690a23e5e2a61d3d9":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_c60ce31c4c554224b910beb427461b0a","placeholder":"​","style":"IPY_MODEL_16b7c48061414f7e876a71c7599bd8e5","tabbable":null,"tooltip":null,"value":"pytorch_model.bin: 100%"}},"8d60417c4fc3452892765f4f4bd6e057":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_66cc3092f8a6401f8896c7d52d979b25","placeholder":"​","style":"IPY_MODEL_480b81a4cd5345ae8761d1dc1093d47d","tabbable":null,"tooltip":null,"value":"preprocessor_config.json: 100%"}},"9f4cf2a34b5243ea87e69aa766dee9af":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_3aea3a97cfb44bb0969144356c78e70d","placeholder":"​","style":"IPY_MODEL_84a9f76413fe4eb1a63d1636b4f32edd","tabbable":null,"tooltip":null,"value":" 271/271 [00:00&lt;00:00, 27.4kB/s]"}},"a00b454af6274e7c819dca12e7e5851e":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"ad30bcb1f47c4ebe9eff49728f4c559d":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"b25d6a5f754a4f33bbbf5c87dc10ae40":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_8d60417c4fc3452892765f4f4bd6e057","IPY_MODEL_5f06a865614f4622a7d5ee3540d4a866","IPY_MODEL_9f4cf2a34b5243ea87e69aa766dee9af"],"layout":"IPY_MODEL_f0dda389580047ddaf87b4c6ee11c34e","tabbable":null,"tooltip":null}},"b89da1ae67134026b48aea08bd9d8206":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_d8b83b7f07824cc5b1ebe36224028098","max":6886,"min":0,"orientation":"horizontal","style":"IPY_MODEL_170a4f1c38524177a75662cf08b20bad","tabbable":null,"tooltip":null,"value":6886}},"bc0ebc176a2e450f9776b577bce3a15f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_1555745dda784271880b3e869a8c241a","placeholder":"​","style":"IPY_MODEL_8265633cc2c94726abf4bb0607ced1a7","tabbable":null,"tooltip":null,"value":" 257M/257M [00:01&lt;00:00, 230MB/s]"}},"bc8fb6dc18d0408b8293470f8333f771":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_ddcda298078b4ab49f1247d7a83a4608","placeholder":"​","style":"IPY_MODEL_eb5e8db296eb455aa202798315db1439","tabbable":null,"tooltip":null,"value":"config.json: 100%"}},"c60ce31c4c554224b910beb427461b0a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"c8b51973837f4ab1bc6c1a6eaec5c098":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"d8b83b7f07824cc5b1ebe36224028098":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"ddcda298078b4ab49f1247d7a83a4608":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"ea52bf56abea40e1aca344660e14098f":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"eb5e8db296eb455aa202798315db1439":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"f0dda389580047ddaf87b4c6ee11c34e":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":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,"padding":null,"right":null,"top":null,"visibility":null,"width":null}}},"version_major":2,"version_minor":0}}},"nbformat_minor":4,"nbformat":4,"cells":[{"id":"01ac2f02","cell_type":"code","source":"import os\nimport torch\nimport cv2\nfrom torch.utils.data import Dataset, DataLoader, default_collate\nfrom torchvision import transforms\nfrom transformers import SegformerFeatureExtractor, SegformerForSemanticSegmentation\nfrom torch.amp import GradScaler, autocast\nimport torch.nn as nn\nimport torch.optim as optim\nfrom tqdm import tqdm\nimport albumentations as A\nfrom albumentations.pytorch import ToTensorV2\nimport numpy as np\nfrom IPython.display import FileLink\nimport pandas as pd","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:31.062949Z","iopub.status.busy":"2025-02-25T21:18:31.062679Z","iopub.status.idle":"2025-02-25T21:18:54.511982Z","shell.execute_reply":"2025-02-25T21:18:54.511082Z"},"papermill":{"duration":23.455478,"end_time":"2025-02-25T21:18:54.513391","exception":false,"start_time":"2025-02-25T21:18:31.057913","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"cc5579b6","cell_type":"markdown","source":"# *Constants and Parameters*","metadata":{"papermill":{"duration":0.002817,"end_time":"2025-02-25T21:18:54.519612","exception":false,"start_time":"2025-02-25T21:18:54.516795","status":"completed"},"tags":[]}},{"id":"4a733ad9","cell_type":"code","source":"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:54.526309Z","iopub.status.busy":"2025-02-25T21:18:54.525804Z","iopub.status.idle":"2025-02-25T21:18:54.576319Z","shell.execute_reply":"2025-02-25T21:18:54.575507Z"},"papermill":{"duration":0.055251,"end_time":"2025-02-25T21:18:54.577681","exception":false,"start_time":"2025-02-25T21:18:54.522430","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"b74e6009","cell_type":"code","source":"submission = []\ndice_scores = []\npredictions = []","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:54.584378Z","iopub.status.busy":"2025-02-25T21:18:54.584160Z","iopub.status.idle":"2025-02-25T21:18:54.587297Z","shell.execute_reply":"2025-02-25T21:18:54.586631Z"},"papermill":{"duration":0.00777,"end_time":"2025-02-25T21:18:54.588480","exception":false,"start_time":"2025-02-25T21:18:54.580710","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"09ece25c","cell_type":"code","source":"#SegFormer's Defination\nfeature_extractor = SegformerFeatureExtractor.from_pretrained(\"nvidia/segformer-b4-finetuned-ade-512-512\")\nmodel = SegformerForSemanticSegmentation.from_pretrained(\"nvidia/segformer-b4-finetuned-ade-512-512\").to(device)","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:54.594872Z","iopub.status.busy":"2025-02-25T21:18:54.594665Z","iopub.status.idle":"2025-02-25T21:18:58.191880Z","shell.execute_reply":"2025-02-25T21:18:58.190593Z"},"papermill":{"duration":3.602248,"end_time":"2025-02-25T21:18:58.193642","exception":false,"start_time":"2025-02-25T21:18:54.591394","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"0db0a8b6","cell_type":"code","source":"#Parameters which control training \nnum_epochs = 5\ncriterion = nn.CrossEntropyLoss()\noptimizer = optim.AdamW(model.parameters(), lr=1e-4, weight_decay=1e-4)\nscheduler = optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=5)\naccumulation_steps = 4\nscaler = GradScaler('cuda')","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:58.202153Z","iopub.status.busy":"2025-02-25T21:18:58.201847Z","iopub.status.idle":"2025-02-25T21:18:58.210507Z","shell.execute_reply":"2025-02-25T21:18:58.209699Z"},"papermill":{"duration":0.014224,"end_time":"2025-02-25T21:18:58.211817","exception":false,"start_time":"2025-02-25T21:18:58.197593","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"f30769b5","cell_type":"markdown","source":"# *Dataset Class,Transformations and Dataloaders*","metadata":{"papermill":{"duration":0.003146,"end_time":"2025-02-25T21:18:58.218465","exception":false,"start_time":"2025-02-25T21:18:58.215319","status":"completed"},"tags":[]}},{"id":"a28fdf63","cell_type":"code","source":"class FaceSegmentationDataset(Dataset):\n    def __init__(self, image_dir, mask_dir, feature_extractor, transform=None, is_test=False):\n        self.image_dir = image_dir\n        self.mask_dir = mask_dir\n        self.image_filenames = os.listdir(image_dir)\n        self.transform = transform\n        self.feature_extractor = feature_extractor\n        self.is_test = is_test\n    \n    def __len__(self):\n        return len(self.image_filenames)\n    \n    def __getitem__(self, idx):\n        img_path = os.path.join(self.image_dir, self.image_filenames[idx])\n        image = cv2.imread(img_path)\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n        \n        if self.is_test:\n            encoded_inputs = self.feature_extractor(images=image, return_tensors=\"pt\", do_rescale=False)\n            return encoded_inputs, self.image_filenames[idx]\n        \n        mask_path = os.path.join(self.mask_dir, self.image_filenames[idx].replace('.jpg', '.png'))\n        mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE)\n        \n        if self.transform:\n            augmented = self.transform(image=image, mask=mask)\n            image = augmented['image']\n            mask = augmented['mask']\n        \n        encoded_inputs = self.feature_extractor(images=image, return_tensors=\"pt\", do_rescale=False)\n        encoded_inputs['labels'] = torch.tensor(mask, dtype=torch.long)\n        return encoded_inputs\n\n\ntrain_transform = A.Compose([\n    A.Resize(1024,1024),\n    A.HorizontalFlip(p=0.5),\n    A.Rotate(limit=20, p=0.5),\n    A.RandomBrightnessContrast(p=0.2),\n    A.ElasticTransform(p=0.2, alpha=120, sigma=120 * 0.05, alpha_affine=120 * 0.03),\n    A.GaussianBlur(p=0.1),\n    ToTensorV2()\n])\n\ndataset = FaceSegmentationDataset(\"/kaggle/input/slicee-my-face/images/train\", \"/kaggle/input/slicee-my-face/annotations/train\", feature_extractor, transform=train_transform)\ndataloader = DataLoader(dataset, batch_size=2, shuffle=True)\ntest_dataset = FaceSegmentationDataset(\"/kaggle/input/slicee-my-face/images/test\", None, feature_extractor, is_test=True)\ntest_dataloader = DataLoader(test_dataset, batch_size=1, shuffle=False)","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:58.225886Z","iopub.status.busy":"2025-02-25T21:18:58.225672Z","iopub.status.idle":"2025-02-25T21:18:58.393230Z","shell.execute_reply":"2025-02-25T21:18:58.392322Z"},"papermill":{"duration":0.172885,"end_time":"2025-02-25T21:18:58.394706","exception":false,"start_time":"2025-02-25T21:18:58.221821","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"5bee3521","cell_type":"markdown","source":"# *Definations of all the classes in my code*","metadata":{"papermill":{"duration":0.003355,"end_time":"2025-02-25T21:18:58.401798","exception":false,"start_time":"2025-02-25T21:18:58.398443","status":"completed"},"tags":[]}},{"id":"e8215fb6","cell_type":"code","source":"def train_class(model, dataloader, criterion, optimizer, accumulation_steps):\n    model.train()\n    total_loss = 0\n    optimizer.zero_grad()\n\n    for i, batch in enumerate(tqdm(dataloader, desc=\"Training\")):\n        if batch is None:\n            continue\n        \n        with autocast('cuda'):\n            inputs = {k: v.squeeze(0).to(device) if k != 'pixel_values' else v.squeeze(1).to(device) for k, v in batch.items()}\n            outputs = model(**inputs)\n            loss = outputs.loss\n            loss = loss / accumulation_steps\n            scaler.scale(loss).backward()\n\n        if (i + 1) % accumulation_steps == 0:\n            scaler.step(optimizer)\n            scaler.update()\n            optimizer.zero_grad()\n            \n        total_loss += loss.item() * accumulation_steps\n    return total_loss / len(dataloader)","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:58.409509Z","iopub.status.busy":"2025-02-25T21:18:58.409275Z","iopub.status.idle":"2025-02-25T21:18:58.414684Z","shell.execute_reply":"2025-02-25T21:18:58.414032Z"},"papermill":{"duration":0.010669,"end_time":"2025-02-25T21:18:58.415897","exception":false,"start_time":"2025-02-25T21:18:58.405228","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"03c49238","cell_type":"code","source":"def rle_encode(mask):\n    pixels = mask.flatten()\n    pixels = np.concatenate([[0], pixels, [0]])\n    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1\n    if len(runs) % 2 != 0:\n        runs = np.append(runs, len(pixels) - 1)\n    runs[1::2] -= runs[::2]\n    return \" \".join(str(x) for x in runs)","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:58.423717Z","iopub.status.busy":"2025-02-25T21:18:58.423496Z","iopub.status.idle":"2025-02-25T21:18:58.427460Z","shell.execute_reply":"2025-02-25T21:18:58.426835Z"},"papermill":{"duration":0.009018,"end_time":"2025-02-25T21:18:58.428545","exception":false,"start_time":"2025-02-25T21:18:58.419527","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"dae6a400","cell_type":"code","source":"def dice_coefficient(pred_mask, true_mask):\n    intersection = np.sum(pred_mask * true_mask)\n    union = np.sum(pred_mask) + np.sum(true_mask)\n    if union == 0:\n        return 1.0\n    return 2 * intersection / union","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:58.436413Z","iopub.status.busy":"2025-02-25T21:18:58.436185Z","iopub.status.idle":"2025-02-25T21:18:58.439784Z","shell.execute_reply":"2025-02-25T21:18:58.439001Z"},"papermill":{"duration":0.008912,"end_time":"2025-02-25T21:18:58.441081","exception":false,"start_time":"2025-02-25T21:18:58.432169","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"00e0fc0d","cell_type":"code","source":"def tta_inference(model, image):\n    augments = [\n        lambda x: x,\n        lambda x: cv2.flip(x, 1),\n        lambda x: cv2.GaussianBlur(x, (5, 5), 0),\n    ]\n    \n    for augment in augments:\n            augmented_img = augment(image)\n            inputs = feature_extractor(images=augmented_img, return_tensors=\"pt\").to(device)\n            outputs = model(**inputs)\n            pred_mask = torch.argmax(outputs.logits, dim=1).cpu().numpy()\n            predictions.append(pred_mask)\n    \n    return np.mean(predictions, axis=0) > 0.5 ","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:58.448874Z","iopub.status.busy":"2025-02-25T21:18:58.448666Z","iopub.status.idle":"2025-02-25T21:18:58.452779Z","shell.execute_reply":"2025-02-25T21:18:58.452239Z"},"papermill":{"duration":0.009431,"end_time":"2025-02-25T21:18:58.454011","exception":false,"start_time":"2025-02-25T21:18:58.444580","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"c877310c","cell_type":"markdown","source":"# *Training and Evaluating*","metadata":{"papermill":{"duration":0.003374,"end_time":"2025-02-25T21:18:58.460920","exception":false,"start_time":"2025-02-25T21:18:58.457546","status":"completed"},"tags":[]}},{"id":"39808d5f","cell_type":"code","source":"model.train()","metadata":{"papermill":{"duration":0.02805,"end_time":"2025-02-25T21:18:58.492552","exception":false,"start_time":"2025-02-25T21:18:58.464502","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"09edd82b","cell_type":"code","source":"for epoch in range(num_epochs):\n    loss = train_class(model, dataloader, criterion, optimizer, accumulation_steps)\n    print(f\"Epoch {epoch+1}/{num_epochs}, Loss: {loss:.4f}\")\n    scheduler.step()","metadata":{"execution":{"iopub.execute_input":"2025-02-25T21:18:58.502888Z","iopub.status.busy":"2025-02-25T21:18:58.502680Z","iopub.status.idle":"2025-02-25T23:14:20.458916Z","shell.execute_reply":"2025-02-25T23:14:20.457829Z"},"papermill":{"duration":6921.962978,"end_time":"2025-02-25T23:14:20.460440","exception":false,"start_time":"2025-02-25T21:18:58.497462","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"77391670","cell_type":"code","source":"model.eval()","metadata":{"papermill":{"duration":0.405052,"end_time":"2025-02-25T23:14:21.306362","exception":false,"start_time":"2025-02-25T23:14:20.901310","status":"completed"},"tags":[],"trusted":true},"outputs":[],"execution_count":null},{"id":"28665a60","cell_type":"code","source":"with torch.no_grad():\n    for batch, image_name in tqdm(test_dataloader, desc=\"Inference\"):\n        inputs = {k: v.squeeze(0).to(device) for k, v in batch.items()}\n        outputs = model(**inputs)\n        pred_mask = torch.argmax(outputs.logits, dim=1).cpu().numpy().squeeze()\n        \n        true_mask_path = f\"/kaggle/input/slicee-my-face/annotations/test/{image_name[0].replace('.jpg', '.png')}\"\n        true_mask = cv2.imread(true_mask_path, cv2.IMREAD_GRAYSCALE)\n        \n        binary_pred_mask = cv2.resize((pred_mask > 0).astype(np.uint8), (true_mask.shape[1], true_mask.shape[0]))\n        binary_true_mask = (true_mask > 0).astype(np.uint8)\n\n        dice_score = dice_coefficient(binary_pred_mask, binary_true_mask)\n        dice_scores.append(dice_score)\n        \n        kernel = np.ones((3,3), np.uint8)\n        clean_mask = cv2.morphologyEx(binary_pred_mask, cv2.MORPH_CLOSE, kernel)\n        clean_mask = cv2.morphologyEx(clean_mask, cv2.MORPH_OPEN, kernel)\n        clean_mask[clean_mask > 0] = 1\n\n        rle_mask = rle_encode(clean_mask)\n        submission.append([image_name[0].replace(\".jpg\", \"\"), rle_mask])","metadata":{"execution":{"iopub.execute_input":"2025-02-25T23:14:22.075041Z","iopub.status.busy":"2025-02-25T23:14:22.074678Z","iopub.status.idle":"2025-02-25T23:17:06.065359Z","shell.execute_reply":"2025-02-25T23:17:06.064417Z"},"papermill":{"duration":164.37559,"end_time":"2025-02-25T23:17:06.066941","exception":false,"start_time":"2025-02-25T23:14:21.691351","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"id":"dd4558f0","cell_type":"markdown","source":"# *Managing CSV file*","metadata":{"papermill":{"duration":0.426363,"end_time":"2025-02-25T23:17:06.925883","exception":false,"start_time":"2025-02-25T23:17:06.499520","status":"completed"},"tags":[]}},{"id":"777e5fd8","cell_type":"code","source":"submission_df = pd.DataFrame(submission, columns=[\"id\", \"predicted\"])\nsubmission_df = submission_df.sort_values(by=\"id\")\nsubmission_df.to_csv(\"submission.csv\", index=False)\nprint(f\"Average Dice Coefficient: {np.mean(dice_scores):.4f}\")\ndisplay(FileLink('submission.csv'))","metadata":{"execution":{"iopub.execute_input":"2025-02-25T23:17:07.829074Z","iopub.status.busy":"2025-02-25T23:17:07.828719Z","iopub.status.idle":"2025-02-25T23:17:08.099738Z","shell.execute_reply":"2025-02-25T23:17:08.098996Z"},"papermill":{"duration":0.697336,"end_time":"2025-02-25T23:17:08.100914","exception":false,"start_time":"2025-02-25T23:17:07.403578","status":"completed"},"tags":[]},"outputs":[],"execution_count":null}]}