{"metadata":{"colab":{"provenance":[]},"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"widgets":{"application/vnd.jupyter.widget-state+json":{"f9f990310b124fb58c460653f923b478":{"model_module":"@jupyter-widgets/controls","model_name":"HBoxModel","model_module_version":"1.5.0","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_2b4c8c1e98bb404bbcc26792f36ea580","IPY_MODEL_b8d16616402c45069c46e3085c52e280","IPY_MODEL_90bc5e68a45946e58f001d6110f02aef"],"layout":"IPY_MODEL_951b39c56a0b4ccd9eebc3689afe4e87"}},"2b4c8c1e98bb404bbcc26792f36ea580":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","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_f4b11bbd15fe4ddc997454950417767f","placeholder":"​","style":"IPY_MODEL_3e6d76f9c1bb4525a252755092b8c57e","value":"preprocessor_config.json: 100%"}},"b8d16616402c45069c46e3085c52e280":{"model_module":"@jupyter-widgets/controls","model_name":"FloatProgressModel","model_module_version":"1.5.0","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_320042c467644681bec3f507d3bebb19","max":538,"min":0,"orientation":"horizontal","style":"IPY_MODEL_3c7aae3b84e84c1b9e989ac0a133544f","value":538}},"90bc5e68a45946e58f001d6110f02aef":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","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_8f38d6d2890044fba381cf221faa647c","placeholder":"​","style":"IPY_MODEL_74272e7feba94e2885fa31a420e5547f","value":" 538/538 [00:00&lt;00:00, 11.0kB/s]"}},"951b39c56a0b4ccd9eebc3689afe4e87":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"f4b11bbd15fe4ddc997454950417767f":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"3e6d76f9c1bb4525a252755092b8c57e":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","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":""}},"320042c467644681bec3f507d3bebb19":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"3c7aae3b84e84c1b9e989ac0a133544f":{"model_module":"@jupyter-widgets/controls","model_name":"ProgressStyleModel","model_module_version":"1.5.0","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":""}},"8f38d6d2890044fba381cf221faa647c":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"74272e7feba94e2885fa31a420e5547f":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","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":""}},"d0417ff41db2462e8cdb7df4b98bcfed":{"model_module":"@jupyter-widgets/controls","model_name":"HBoxModel","model_module_version":"1.5.0","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_f558ea8c8ba442d2ae3f4dd2688aa79b","IPY_MODEL_4ce2f9fb3fb14986a7033a33fb8ef91e","IPY_MODEL_8bb6a9f14f6e4f8792c366ca6dd0d5ed"],"layout":"IPY_MODEL_eff7293842bb4cb0a24c567790f0b424"}},"f558ea8c8ba442d2ae3f4dd2688aa79b":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","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_6a22ecb94fb34d569c9823a5226991c2","placeholder":"​","style":"IPY_MODEL_0d4c319249324793b9e7ccdcf141c329","value":"config.json: 100%"}},"4ce2f9fb3fb14986a7033a33fb8ef91e":{"model_module":"@jupyter-widgets/controls","model_name":"FloatProgressModel","model_module_version":"1.5.0","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_dddff6405aca4175aaf77d869e560003","max":82540,"min":0,"orientation":"horizontal","style":"IPY_MODEL_0dab7134797146ffa9d314d7d31cc5f6","value":82540}},"8bb6a9f14f6e4f8792c366ca6dd0d5ed":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","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_2be723d7127d4ab387b100dd8c905b67","placeholder":"​","style":"IPY_MODEL_4279a5fec34c41fe98987e2bdcae02db","value":" 82.5k/82.5k [00:00&lt;00:00, 1.29MB/s]"}},"eff7293842bb4cb0a24c567790f0b424":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"6a22ecb94fb34d569c9823a5226991c2":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"0d4c319249324793b9e7ccdcf141c329":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","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":""}},"dddff6405aca4175aaf77d869e560003":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"0dab7134797146ffa9d314d7d31cc5f6":{"model_module":"@jupyter-widgets/controls","model_name":"ProgressStyleModel","model_module_version":"1.5.0","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":""}},"2be723d7127d4ab387b100dd8c905b67":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"4279a5fec34c41fe98987e2bdcae02db":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","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":""}},"2d7d5fd88b514644a796313081162f63":{"model_module":"@jupyter-widgets/controls","model_name":"HBoxModel","model_module_version":"1.5.0","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_3ea2691bc13044d796579717967105b5","IPY_MODEL_617710233c0d4b1e9bb47a0222f7fd94","IPY_MODEL_68e31cc3131b44868208fcf3ccbc91f1"],"layout":"IPY_MODEL_ca452027ae9d4c29b2f4f36c1500e708"}},"3ea2691bc13044d796579717967105b5":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","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_19b0e1bfeefa4a8882c402f044be11c9","placeholder":"​","style":"IPY_MODEL_e5ed8e6a92dc4616a9923d7c5fb0e6cc","value":"model.safetensors: 100%"}},"617710233c0d4b1e9bb47a0222f7fd94":{"model_module":"@jupyter-widgets/controls","model_name":"FloatProgressModel","model_module_version":"1.5.0","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_38dd3a5c37d94b588bf5c20bce78ec40","max":866052064,"min":0,"orientation":"horizontal","style":"IPY_MODEL_6731a35d8cfe4f5ebc4b94ff26d78dde","value":866052064}},"68e31cc3131b44868208fcf3ccbc91f1":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","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_f356bbf3c5834e1191e9a984cf60582c","placeholder":"​","style":"IPY_MODEL_e64ee29bb16d45be86fdc690c19d4f94","value":" 866M/866M [00:12&lt;00:00, 71.6MB/s]"}},"ca452027ae9d4c29b2f4f36c1500e708":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"19b0e1bfeefa4a8882c402f044be11c9":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"e5ed8e6a92dc4616a9923d7c5fb0e6cc":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","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":""}},"38dd3a5c37d94b588bf5c20bce78ec40":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"6731a35d8cfe4f5ebc4b94ff26d78dde":{"model_module":"@jupyter-widgets/controls","model_name":"ProgressStyleModel","model_module_version":"1.5.0","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":""}},"f356bbf3c5834e1191e9a984cf60582c":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"e64ee29bb16d45be86fdc690c19d4f94":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","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":""}},"c7dcd70a6572439098fc8c63313a8b37":{"model_module":"@jupyter-widgets/controls","model_name":"HBoxModel","model_module_version":"1.5.0","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_77598a53d168401c820e0f9aaeedf31d","IPY_MODEL_52cf5616aa2148a7b7512a243731f8f6","IPY_MODEL_a7045ec35b934020a792caafefa08522"],"layout":"IPY_MODEL_e11539e2516242378a722d513dd4dcf5"}},"77598a53d168401c820e0f9aaeedf31d":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","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_c69b36d90b4e42b1abc2915dea91b44d","placeholder":"​","style":"IPY_MODEL_30ddae8d0922403e8c6c0cf737f491fd","value":"  2%"}},"52cf5616aa2148a7b7512a243731f8f6":{"model_module":"@jupyter-widgets/controls","model_name":"FloatProgressModel","model_module_version":"1.5.0","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":"danger","description":"","description_tooltip":null,"layout":"IPY_MODEL_fba4ffa0f237459497993e01b46e4ae2","max":958,"min":0,"orientation":"horizontal","style":"IPY_MODEL_847bc5f4340d4053a5ece6fffc519f64","value":16}},"a7045ec35b934020a792caafefa08522":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","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_4190cc29c2cd460c9e94113c9844ea78","placeholder":"​","style":"IPY_MODEL_a22293b721ef4d788bd6c1ad7cbe45a2","value":" 16/958 [10:10&lt;9:33:38, 36.54s/it]"}},"e11539e2516242378a722d513dd4dcf5":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"c69b36d90b4e42b1abc2915dea91b44d":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"30ddae8d0922403e8c6c0cf737f491fd":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","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":""}},"fba4ffa0f237459497993e01b46e4ae2":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"847bc5f4340d4053a5ece6fffc519f64":{"model_module":"@jupyter-widgets/controls","model_name":"ProgressStyleModel","model_module_version":"1.5.0","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":""}},"4190cc29c2cd460c9e94113c9844ea78":{"model_module":"@jupyter-widgets/base","model_name":"LayoutModel","model_module_version":"1.2.0","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}},"a22293b721ef4d788bd6c1ad7cbe45a2":{"model_module":"@jupyter-widgets/controls","model_name":"DescriptionStyleModel","model_module_version":"1.5.0","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":""}}}},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":86142,"databundleVersionId":9786425,"sourceType":"competition"}],"dockerImageVersionId":30787,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install evaluate","metadata":{"id":"g9hXf4Hz51ig","outputId":"8ac45382-fe30-43c3-a637-4cabd1b0e25b","execution":{"iopub.status.busy":"2024-10-10T17:40:23.614853Z","iopub.execute_input":"2024-10-10T17:40:23.615557Z","iopub.status.idle":"2024-10-10T17:40:36.608581Z","shell.execute_reply.started":"2024-10-10T17:40:23.615515Z","shell.execute_reply":"2024-10-10T17:40:36.607392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nimport torch\nimport datasets\nimport requests\nimport evaluate\nimport numpy as np\nimport huggingface_hub\nfrom PIL import Image\nimport albumentations as A\nfrom tqdm.auto import tqdm\nimport matplotlib.pyplot as plt\nfrom typing import Tuple, Any\nfrom dataclasses import dataclass\nfrom datasets import load_dataset\nimport matplotlib.patches as mpatches\nfrom huggingface_hub import hf_hub_download\nfrom torch.utils.data import Dataset, DataLoader\nfrom transformers import (\n    Mask2FormerImageProcessor,\n    AutoImageProcessor,\n    Mask2FormerForUniversalSegmentation,\n)\n\ntorch.manual_seed(42)","metadata":{"id":"F2Oi8CF655JL","outputId":"6d1c434f-e432-4890-8154-1bb390709c3b"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os","metadata":{"execution":{"iopub.status.busy":"2024-10-10T17:41:03.349098Z","iopub.execute_input":"2024-10-10T17:41:03.349779Z","iopub.status.idle":"2024-10-10T17:41:03.354241Z","shell.execute_reply.started":"2024-10-10T17:41:03.349731Z","shell.execute_reply":"2024-10-10T17:41:03.353279Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_folder=\"/kaggle/input/iitg-ai-overnight-hackathon-2024/dataset/dataset/train\"\ntrain_path = []\n\nfor root, dirs, files in os.walk(train_folder):\n    for file in files:\n            train_path.append(os.path.join(root, file))","metadata":{"execution":{"iopub.status.busy":"2024-10-10T17:41:03.517186Z","iopub.execute_input":"2024-10-10T17:41:03.517804Z","iopub.status.idle":"2024-10-10T17:41:05.286009Z","shell.execute_reply.started":"2024-10-10T17:41:03.517769Z","shell.execute_reply":"2024-10-10T17:41:05.285235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mask_path = []\nfor image_path in train_path:\n    mask_file = image_path.replace('leftImg8bit.jpg', 'gtFine_labellevel3Ids.png')  \n    mask_file =mask_file.replace('train', 'labels') \n    mask_path.append(mask_file)","metadata":{"execution":{"iopub.status.busy":"2024-10-10T17:41:09.023990Z","iopub.execute_input":"2024-10-10T17:41:09.024804Z","iopub.status.idle":"2024-10-10T17:41:09.036213Z","shell.execute_reply.started":"2024-10-10T17:41:09.024763Z","shell.execute_reply":"2024-10-10T17:41:09.035344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"combined_tuples = [(train_path[i], mask_path[i]) for i in range(len(train_path))]\nimport pandas as pd\ndf= pd.DataFrame(combined_tuples)","metadata":{"execution":{"iopub.status.busy":"2024-10-10T17:41:32.712051Z","iopub.execute_input":"2024-10-10T17:41:32.713144Z","iopub.status.idle":"2024-10-10T17:41:33.641147Z","shell.execute_reply.started":"2024-10-10T17:41:32.713099Z","shell.execute_reply":"2024-10-10T17:41:33.640363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df.rename(columns={0:\"image\", 1:\"mask\"})","metadata":{"execution":{"iopub.status.busy":"2024-10-10T17:54:12.244756Z","iopub.execute_input":"2024-10-10T17:54:12.245127Z","iopub.status.idle":"2024-10-10T17:54:12.251001Z","shell.execute_reply.started":"2024-10-10T17:54:12.245089Z","shell.execute_reply":"2024-10-10T17:54:12.249918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class Label:\n    def __init__(self, name, id, csId, csTrainId, level4id, level3Id, category, level2Id, level1Id, hasInstances, ignoreInEval, color):\n        self.name = name\n        self.id = id\n        self.csId = csId\n        self.csTrainId = csTrainId\n        self.level4id = level4id\n        self.level3Id = level3Id\n        self.category = category\n        self.level2Id = level2Id\n        self.level1Id = level1Id\n        self.hasInstances = hasInstances\n        self.ignoreInEval = ignoreInEval\n        self.color = color\n\n# Your label definitions here (from your provided list)\n\nlabels_details = [\n    #       name                     id    csId     csTrainId level4id        level3Id  category           level2Id      level1Id  hasInstances   ignoreInEval   color\n    Label(  'road'                 ,  0   ,  7 ,     0 ,       0   ,     0  ,   'drivable'            , 0           , 0      , False        , False        , (128, 64,128)  ),\n    Label(  'parking'              ,  1   ,  9 ,   255 ,       1   ,     1  ,   'drivable'            , 1           , 0      , False        , False         , (250,170,160)  ),\n    Label(  'drivable fallback'    ,  2   ,  255 ,   255 ,     2   ,       1  ,   'drivable'            , 1           , 0      , False        , False         , ( 81,  0, 81)  ),\n    Label(  'sidewalk'             ,  3   ,  8 ,     1 ,       3   ,     2  ,   'non-drivable'        , 2           , 1      , False        , False        , (244, 35,232)  ),\n    Label(  'rail track'           ,  4   , 10 ,   255 ,       3   ,     3  ,   'non-drivable'        , 3           , 1      , False        , False         , (230,150,140)  ),\n    Label(  'non-drivable fallback',  5   , 255 ,     9 ,      4   ,      3  ,   'non-drivable'        , 3           , 1      , False        , False        , (152,251,152)  ),\n    Label(  'person'               ,  6   , 24 ,    11 ,       5   ,     4  ,   'living-thing'        , 4           , 2      , True         , False        , (220, 20, 60)  ),\n    Label(  'animal'               ,  7   , 255 ,   255 ,      6   ,      4  ,   'living-thing'        , 4           , 2      , True         , True        , (246, 198, 145)),\n    Label(  'rider'                ,  8   , 25 ,    12 ,       7   ,     5  ,   'living-thing'        , 5           , 2      , True         , False        , (255,  0,  0)  ),\n    Label(  'motorcycle'           ,  9   , 32 ,    17 ,       8   ,     6  ,   '2-wheeler'           , 6           , 3      , True         , False        , (  0,  0,230)  ),\n    Label(  'bicycle'              , 10   , 33 ,    18 ,       9   ,     7  ,   '2-wheeler'           , 6           , 3      , True         , False        , (119, 11, 32)  ),\n    Label(  'autorickshaw'         , 11   , 255 ,   255 ,     10   ,      8  ,   'autorickshaw'        , 7           , 3      , True         , False        , (255, 204, 54) ),\n    Label(  'car'                  , 12   , 26 ,    13 ,      11   ,     9  ,   'car'                 , 7           , 3      , True         , False        , (  0,  0,142)  ),\n    Label(  'truck'                , 13   , 27 ,    14 ,      12   ,     10 ,   'large-vehicle'       , 8           , 3      , True         , False        , (  0,  0, 70)  ),\n    Label(  'bus'                  , 14   , 28 ,    15 ,      13   ,     11 ,   'large-vehicle'       , 8           , 3      , True         , False        , (  0, 60,100)  ),\n    Label(  'caravan'              , 15   , 29 ,   255 ,      14   ,     12 ,   'large-vehicle'       , 8           , 3      , True         , True         , (  0,  0, 90)  ),\n    Label(  'trailer'              , 16   , 30 ,   255 ,      15   ,     12 ,   'large-vehicle'       , 8           , 3      , True         , True         , (  0,  0,110)  ),\n    Label(  'train'                , 17   , 31 ,    16 ,      15   ,     12 ,   'large-vehicle'       , 8           , 3      , True         , True        , (  0, 80,100)  ),\n    Label(  'vehicle fallback'     , 18   , 355 ,   255 ,     15   ,      12 ,   'large-vehicle'       , 8           , 3      , True         , False        , (136, 143, 153)),\n    Label(  'curb'                 , 19   ,255 ,   255 ,      16   ,     13 ,   'barrier'             , 9           , 4      , False        , False        , (220, 190, 40)),\n    Label(  'wall'                 , 20   , 12 ,     3 ,      17   ,     14 ,   'barrier'             , 9           , 4      , False        , False        , (102,102,156)  ),\n    Label(  'fence'                , 21   , 13 ,     4 ,      18   ,     15 ,   'barrier'             , 10           , 4      , False        , False        , (190,153,153)  ),\n    Label(  'guard rail'           , 22   , 14 ,   255 ,      19   ,     16 ,   'barrier'             , 10          , 4      , False        , False         , (180,165,180)  ),\n    Label(  'billboard'            , 23   , 255 ,   255 ,     20   ,      17 ,   'structures'          , 11           , 4      , False        , False        , (174, 64, 67) ),\n    Label(  'traffic sign'         , 24   , 20 ,     7 ,      21   ,     18 ,   'structures'          , 11          , 4      , False        , False        , (220,220,  0)  ),\n    Label(  'traffic light'        , 25   , 19 ,     6 ,      22   ,     19 ,   'structures'          , 11          , 4      , False        , False        , (250,170, 30)  ),\n    Label(  'pole'                 , 26   , 17 ,     5 ,      23   ,     20 ,   'structures'          , 12          , 4      , False        , False        , (153,153,153)  ),\n    Label(  'polegroup'            , 27   , 18 ,   255 ,      23   ,     20 ,   'structures'          , 12          , 4      , False        , False         , (153,153,153)  ),\n    Label(  'obs-str-bar-fallback' , 28   , 255 ,   255 ,     24   ,      21 ,   'structures'          , 12          , 4      , False        , False        , (169, 187, 214) ),\n    Label(  'building'             , 29   , 11 ,     2 ,      25   ,     22 ,   'construction'        , 13          , 5      , False        , False        , ( 70, 70, 70)  ),\n    Label(  'bridge'               , 30   , 15 ,   255 ,      26   ,     23 ,   'construction'        , 13          , 5      , False        , False         , (150,100,100)  ),\n    Label(  'tunnel'               , 31   , 16 ,   255 ,      26   ,     23 ,   'construction'        , 13          , 5      , False        , False         , (150,120, 90)  ),\n    Label(  'vegetation'           , 32   , 21 ,     8 ,      27   ,     24 ,   'vegetation'          , 14          , 5      , False        , False        , (107,142, 35)  ),\n    Label(  'sky'                  , 33   , 23 ,    10 ,      28   ,     25 ,   'sky'                 , 15          , 6      , False        , False        , ( 70,130,180)  ),\n    Label(  'fallback background'  , 34   , 255 ,   255 ,     29   ,      25 ,   'object fallback'     , 15          , 6      , False        , False        , (169, 187, 214)),\n    Label(  'unlabeled'            , 35   ,  0  ,     255 ,   255   ,      255 ,   'void'                , 255         , 255    , False        , True         , (  0,  0,  0)  ),\n    Label(  'ego vehicle'          , 36   ,  1  ,     255 ,   255   ,      255 ,   'void'                , 255         , 255    , False        , True         , (  0,  0,  0)  ),\n    Label(  'rectification border' , 37   ,  2  ,     255 ,   255   ,      255 ,   'void'                , 255         , 255    , False        , True         , (  0,  0,  0)  ),\n    Label(  'out of roi'           , 38   ,  3  ,     255 ,   255   ,      255 ,   'void'                , 255         , 255    , False        , True         , (  0,  0,  0)  ),\n    Label(  'license plate'        , 39   , 255 ,     255 ,   255   ,      255 ,   'vehicle'             , 255         , 255    , False        , True         , (  0,  0,142)  ),\n\n]","metadata":{"id":"y-y6VKPT_Gf7","execution":{"iopub.status.busy":"2024-10-10T17:44:12.181606Z","iopub.execute_input":"2024-10-10T17:44:12.182005Z","iopub.status.idle":"2024-10-10T17:44:12.215161Z","shell.execute_reply.started":"2024-10-10T17:44:12.181961Z","shell.execute_reply":"2024-10-10T17:44:12.214083Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-10T17:54:22.508586Z","iopub.execute_input":"2024-10-10T17:54:22.508978Z","iopub.status.idle":"2024-10-10T17:54:22.519125Z","shell.execute_reply.started":"2024-10-10T17:54:22.508940Z","shell.execute_reply":"2024-10-10T17:54:22.518155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport random\nfrom typing import Any, Tuple\nfrom torchvision import transforms\nfrom PIL import Image\nfrom torch.utils.data import Dataset\nfrom dataclasses import dataclass\nimport albumentations as A\nfrom transformers import Mask2FormerImageProcessor\n\n# Assuming df is your DataFrame containing the image and mask paths\n# Example: df = pd.read_csv('path_to_your_csv_file.csv')\n\n# Step 1: Prepare your dataset by extracting paths from the DataFrame\nimage_paths = df['image'].values # Extract image paths\nmask_paths = df['mask'].values # Extract mask paths\n\n# Function to split data\ndef split_data_randomly(image_list, mask_list, train_ratio=0.8, val_ratio=0.1, test_ratio=0.1):\n    # Ensure the lengths of image_list and mask_list are the same\n    assert len(image_list) == len(mask_list), \"Image list and Mask list must have the same length\"\n\n    # Combine image and mask paths into pairs to ensure they are shuffled together\n    paired_data = list(zip(image_list, mask_list))\n\n    # Shuffle the data\n    random.shuffle(paired_data)\n\n    # Split the data\n    total_size = len(paired_data)\n    train_size = int(total_size * train_ratio)\n    val_size = int(total_size * val_ratio)\n    test_size = total_size - train_size - val_size  # Remaining for test set\n\n    train_data = paired_data[:train_size]\n    val_data = paired_data[train_size:train_size + val_size]\n    test_data = paired_data[train_size + val_size:]\n\n    # Unzip the paired data back into image and mask lists\n    train_images, train_masks = zip(*train_data)\n    val_images, val_masks = zip(*val_data)\n    test_images, test_masks = zip(*test_data)\n\n    return (train_images, val_images, test_images), (train_masks, val_masks, test_masks)\n\n# Split the data\n(image_splits, mask_splits) = split_data_randomly(image_paths, mask_paths)\n\n(train_images, val_images, test_images) = image_splits\n(train_masks, val_masks, test_masks) = mask_splits\n\n# Print the lengths of the splits\nprint(\"Train Images:\", len(train_images))\nprint(\"Validation Images:\", len(val_images))\nprint(\"Test Images:\", len(test_images))\n\n\n# Step 2: Define the preprocessing pipeline\npreprocessor = Mask2FormerImageProcessor(\n    ignore_index=0,\n    do_reduce_labels=False,\n    do_resize=False,\n    do_rescale=False,\n    do_normalize=False,\n)\n\nade_mean = [123.675 / 255, 116.280 / 255, 103.530 / 255]\nade_std = [58.395 / 255, 57.120 / 255, 57.375 / 255]\n\ntrain_transform = A.Compose(\n    [\n        A.RandomCrop(width=512, height=512),\n        A.HorizontalFlip(p=0.5),\n        A.Normalize(mean=ade_mean, std=ade_std),\n    ]\n)\n\ntest_transform = A.Compose(\n    [\n        A.Resize(width=512, height=512),\n        A.Normalize(mean=ade_mean, std=ade_std),\n    ]\n)\n\n@dataclass\nclass SegmentationDataInput:\n    original_image: np.ndarray\n    transformed_image: np.ndarray\n    original_segmentation_map: np.ndarray\n    transformed_segmentation_map: np.ndarray\n\nclass SemanticSegmentationDataset(Dataset):\n    def __init__(self, image_paths, mask_paths, transform: Any) -> None:\n        self.image_paths = image_paths\n        self.mask_paths = mask_paths  # Store mask paths\n        self.transform = transform\n\n    def __len__(self) -> int:\n        return len(self.image_paths)\n\n    def __getitem__(self, idx: int) -> SegmentationDataInput:\n        # Load the image and mask from the file paths\n        image_path = self.image_paths[idx]\n        mask_path = self.mask_paths[idx]  # Get the corresponding mask path\n\n        original_image = np.array(Image.open(image_path).convert(\"RGB\"))\n        original_segmentation_map = np.array(Image.open(mask_path).convert(\"L\"))  # Assuming masks are grayscale\n\n        # Rescale the mask from 0-255 to 0-39\n        original_segmentation_map = np.floor(original_segmentation_map / (255 / 39)).astype(np.uint8)\n\n        # Apply the transformation to both image and mask\n        transformed = self.transform(\n            image=original_image, mask=original_segmentation_map\n        )\n        transformed_image = transformed[\"image\"].transpose(2, 0, 1)  # Transpose to channel-first format\n        transformed_segmentation_map = transformed[\"mask\"]\n\n        return SegmentationDataInput(\n            original_image=original_image,\n            transformed_image=transformed_image,\n            original_segmentation_map=original_segmentation_map,\n            transformed_segmentation_map=transformed_segmentation_map,\n        )\n\ndef collate_fn(batch: SegmentationDataInput) -> dict:\n    original_images = [sample.original_image for sample in batch]\n    transformed_images = [sample.transformed_image for sample in batch]\n    original_segmentation_maps = [sample.original_segmentation_map for sample in batch]\n    transformed_segmentation_maps = [sample.transformed_segmentation_map for sample in batch]\n\n    preprocessed_batch = preprocessor(\n        transformed_images,\n        segmentation_maps=transformed_segmentation_maps,\n        return_tensors=\"pt\",\n    )\n\n    preprocessed_batch[\"original_images\"] = original_images\n    preprocessed_batch[\"original_segmentation_maps\"] = original_segmentation_maps\n\n    return preprocessed_batch\n","metadata":{"execution":{"iopub.status.busy":"2024-10-10T17:54:36.284288Z","iopub.execute_input":"2024-10-10T17:54:36.284667Z","iopub.status.idle":"2024-10-10T17:54:36.319981Z","shell.execute_reply.started":"2024-10-10T17:54:36.284631Z","shell.execute_reply":"2024-10-10T17:54:36.318990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def id_to_label_map():\n    new_dict = {}\n    for label in labels_details:\n        new_dict[int(label.level3Id)] = label.name\n    return new_dict","metadata":{"id":"-8_qGGuz_VIQ","execution":{"iopub.status.busy":"2024-10-10T17:54:41.990053Z","iopub.execute_input":"2024-10-10T17:54:41.990973Z","iopub.status.idle":"2024-10-10T17:54:41.995791Z","shell.execute_reply.started":"2024-10-10T17:54:41.990928Z","shell.execute_reply":"2024-10-10T17:54:41.994827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"id2label = id_to_label_map()\nprint(id2label)","metadata":{"id":"QsR0EGK7_kD9","outputId":"8762a7a6-df39-4f65-95ea-6abc77494fff","execution":{"iopub.status.busy":"2024-10-10T17:54:52.511305Z","iopub.execute_input":"2024-10-10T17:54:52.512253Z","iopub.status.idle":"2024-10-10T17:54:52.517052Z","shell.execute_reply.started":"2024-10-10T17:54:52.512211Z","shell.execute_reply":"2024-10-10T17:54:52.516095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfrom torch.utils.data import Dataset, DataLoader\n\ntrain_dataset = SemanticSegmentationDataset(train_images,train_masks, transform=train_transform)\nval_dataset = SemanticSegmentationDataset(val_images,val_masks, transform=train_transform)\ntest_dataset = SemanticSegmentationDataset(test_images,test_masks, transform=test_transform)\n\n# Prepare Dataloaders\ntrain_dataloader = DataLoader(\n    train_dataset, batch_size=2, shuffle=True, collate_fn=collate_fn\n)\nval_dataloader = DataLoader(\n    val_dataset, batch_size=2, shuffle=True, collate_fn=collate_fn\n)\ntest_dataloader = DataLoader(\n    test_dataset, batch_size=2, shuffle=False, collate_fn=collate_fn\n)","metadata":{"id":"9WJEc4jx8FrW","execution":{"iopub.status.busy":"2024-10-10T17:56:05.815027Z","iopub.execute_input":"2024-10-10T17:56:05.815460Z","iopub.status.idle":"2024-10-10T17:56:05.822710Z","shell.execute_reply.started":"2024-10-10T17:56:05.815422Z","shell.execute_reply":"2024-10-10T17:56:05.821736Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample = next(iter(train_dataloader))\nprint(\n    {\n        key: value[0].shape if isinstance(value, list) else value.shape\n        for key, value in sample.items()\n    }\n)","metadata":{"id":"5_X5D6sb8v_6","outputId":"b30c563c-ba37-486d-cb05-497ced7a53f4","execution":{"iopub.status.busy":"2024-10-10T17:56:17.102599Z","iopub.execute_input":"2024-10-10T17:56:17.103293Z","iopub.status.idle":"2024-10-10T17:56:17.372062Z","shell.execute_reply.started":"2024-10-10T17:56:17.103254Z","shell.execute_reply":"2024-10-10T17:56:17.371049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfrom transformers import AutoImageProcessor, Mask2FormerForUniversalSegmentation\n\nprocessor = AutoImageProcessor.from_pretrained(\"facebook/mask2former-swin-large-ade-semantic\")\nmodel = Mask2FormerForUniversalSegmentation.from_pretrained(\n    \"facebook/mask2former-swin-large-ade-semantic\"\n)","metadata":{"id":"3skwcut484do","outputId":"77895417-9b2b-49ae-cf5e-268e994e1247","execution":{"iopub.status.busy":"2024-10-10T17:57:46.390430Z","iopub.execute_input":"2024-10-10T17:57:46.390918Z","iopub.status.idle":"2024-10-10T17:57:51.796848Z","shell.execute_reply.started":"2024-10-10T17:57:46.390873Z","shell.execute_reply":"2024-10-10T17:57:51.796071Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pixel level module contains both the backbone and the pixel decoder\nfor param in model.model.pixel_level_module.parameters():\n    param.requires_grad = False\n\n# Confirm that the parameters are correctly frozen\nfor name, param in model.model.pixel_level_module.named_parameters():\n    assert not param.requires_grad","metadata":{"id":"xDOqITHz-NFP","execution":{"iopub.status.busy":"2024-10-10T17:58:03.004475Z","iopub.execute_input":"2024-10-10T17:58:03.005600Z","iopub.status.idle":"2024-10-10T17:58:03.015876Z","shell.execute_reply.started":"2024-10-10T17:58:03.005553Z","shell.execute_reply":"2024-10-10T17:58:03.015050Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nfrom torch.utils.data import DataLoader\nfrom tqdm import tqdm\nimport evaluate\nfrom transformers import AutoImageProcessor\nfrom transformers import Mask2FormerForUniversalSegmentation\n\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\nmetric = evaluate.load(\"mean_iou\")\n\ndef evaluate_model(\n    model: Mask2FormerForUniversalSegmentation,\n    dataloader: DataLoader,\n    preprocessor: AutoImageProcessor,\n    metric: Any,\n    id2label: dict,\n    max_batches=None,\n):\n    \"\"\"\n    Evaluates the given model using the specified dataloader and computes the mean Intersection over Union (IoU).\n    ----\n    Args:\n      - model (MaskFormerForUniversalSegmentation): The trained model to be evaluated.\n      - dataloader (DataLoader): DataLoader containing the dataset for evaluation.\n      - preprocessor (AutoImageProcessor): The preprocessor used for post-processing the model outputs.\n      - metric (Any): Metric instance used for calculating IoU.\n      - id2label (dict): Dictionary mapping class ids to their corresponding labels.\n      - max_batches (int, optional): Maximum number of batches to evaluate. If None, evaluates on the entire validation dataset.\n\n    Returns:\n    float: The mean IoU calculated over the specified number of batches.\n    \"\"\"\n    model.eval()\n    running_iou = 0\n    num_batches = 0\n    with torch.no_grad():\n        for idx, batch in enumerate(tqdm(dataloader)):\n            if max_batches and idx >= max_batches:\n                break\n\n            pixel_values = batch[\"pixel_values\"].to(device)\n            outputs = model(pixel_values=pixel_values)\n\n            original_images = batch[\"original_images\"]\n            target_sizes = [(image.shape[0], image.shape[1]) for image in original_images]\n\n            predicted_segmentation_maps = preprocessor.post_process_semantic_segmentation(\n                outputs, target_sizes=target_sizes\n            )\n\n            ground_truth_segmentation_maps = batch[\"original_segmentation_maps\"]\n            metric.add_batch(\n                references=ground_truth_segmentation_maps,\n                predictions=predicted_segmentation_maps,\n            )\n\n            running_iou += metric.compute(num_labels=len(id2label), ignore_index=0)[\"mean_iou\"]\n            num_batches += 1\n\n    mean_iou = running_iou / num_batches if num_batches > 0 else 0.0\n    return mean_iou\n\ndef train_model(\n    model: Mask2FormerForUniversalSegmentation,\n    train_dataloader: DataLoader,\n    val_dataloader: DataLoader,\n    preprocessor: AutoImageProcessor,\n    metric: Any,\n    id2label: dict,\n    num_epochs=100,\n    learning_rate=5e-5,\n    log_interval=100,\n):\n    \"\"\"\n    Trains the MaskFormer model for semantic segmentation over a specified number of epochs and evaluates it on a validation set.\n    ----\n    Args:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 \n      - model (MaskFormerForUniversalSegmentation): The model to be trained.\n      - train_dataloader (DataLoader): DataLoader for the training data.\n      - val_dataloader (DataLoader): DataLoader for the validation data.\n      - preprocessor (AutoImageProcessor): The preprocessor used for preparing the data.\n      - metric (Any): Metric instance used for calculating performance metrics.\n      - id2label (dict): Dictionary mapping class IDs to their corresponding labels.\n      - num_epochs (int): Number of epochs to train the model.\n      - learning_rate (float): Learning rate for the optimizer.\n      - log_interval (int): Interval (in number of batches) at which to log training progress.\n\n    \"\"\"\n    model.to(device)\n    optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)\n\n    for epoch in range(num_epochs):\n        print(f\"Current epoch: {epoch + 1}/{num_epochs}\")\n        model.train()\n\n        running_loss = 0.0\n        num_samples = 0\n\n        for idx, batch in enumerate(tqdm(train_dataloader)):\n            optimizer.zero_grad()\n\n            outputs = model(\n                pixel_values=batch[\"pixel_values\"].to(device),\n                mask_labels=[labels.to(device) for labels in batch[\"mask_labels\"]],\n                class_labels=[labels.to(device) for labels in batch[\"class_labels\"]],\n            )\n\n            loss = outputs.loss\n            loss.backward()\n\n            batch_size = batch[\"pixel_values\"].size(0)\n            running_loss += loss.item()\n            num_samples += batch_size\n\n            if idx % log_interval == 0 and idx > 0:\n                print(f\"Iteration {idx} - loss: {running_loss / num_samples:.4f}\")\n\n            optimizer.step()\n\n        val_mean_iou = evaluate_model(\n            model, val_dataloader, preprocessor, metric, id2label, max_batches=6\n        )\n        print(f\"Validation Mean IoU: {val_mean_iou:.4f}\")\n","metadata":{"id":"k7Ozmgxo-kaT","execution":{"iopub.status.busy":"2024-10-10T17:59:22.354491Z","iopub.execute_input":"2024-10-10T17:59:22.354857Z","iopub.status.idle":"2024-10-10T17:59:23.847996Z","shell.execute_reply.started":"2024-10-10T17:59:22.354823Z","shell.execute_reply":"2024-10-10T17:59:23.847091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_model(\n    model,\n    train_dataloader,\n    val_dataloader,\n    preprocessor,\n    metric,\n    id2label,\n    num_epochs=2,\n    log_interval=100,\n)","metadata":{"id":"819iSGtf-wtu","outputId":"94a7a589-0495-4ea0-ab96-e1f0923d4654","execution":{"iopub.status.busy":"2024-10-10T17:59:51.072199Z","iopub.execute_input":"2024-10-10T17:59:51.073460Z","iopub.status.idle":"2024-10-10T19:03:57.814191Z","shell.execute_reply.started":"2024-10-10T17:59:51.073413Z","shell.execute_reply":"2024-10-10T19:03:57.813204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\n\n# Assuming your model is defined as 'model'\ntorch.save(model.state_dict(), 'model.pth')  # Save the model's parameters\n","metadata":{"id":"Ur5FWCadBcfg","execution":{"iopub.status.busy":"2024-10-10T19:27:39.804182Z","iopub.execute_input":"2024-10-10T19:27:39.805202Z","iopub.status.idle":"2024-10-10T19:27:41.033720Z","shell.execute_reply.started":"2024-10-10T19:27:39.805147Z","shell.execute_reply":"2024-10-10T19:27:41.032708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"torch.save(model, 'full_model.pth')  # Save the entire model\n","metadata":{"execution":{"iopub.status.busy":"2024-10-10T19:28:59.564720Z","iopub.execute_input":"2024-10-10T19:28:59.565554Z","iopub.status.idle":"2024-10-10T19:29:00.860873Z","shell.execute_reply.started":"2024-10-10T19:28:59.565480Z","shell.execute_reply":"2024-10-10T19:29:00.860051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}