{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.11"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":94689,"databundleVersionId":11605086,"sourceType":"competition"}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true},"papermill":{"default_parameters":{},"duration":640.110018,"end_time":"2025-05-01T07:40:28.81895","environment_variables":{},"exception":null,"input_path":"__notebook__.ipynb","output_path":"__notebook__.ipynb","parameters":{},"start_time":"2025-05-01T07:29:48.708932","version":"2.5.0"},"widgets":{"application/vnd.jupyter.widget-state+json":{"state":{"023414ebced74a43845ebb02ef34850d":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"02de625876424c81baeace5765af6754":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":"2","flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"04669661425c47c2b67266059c39ea4c":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"07385162ce024c2b84af1158128dcbde":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_f64fa3c3d26e4c5d9aeca1e5c6b6c0c3","IPY_MODEL_df1b1cbf69824580b5c7f5c659e89568","IPY_MODEL_c8987983b99a40b2afdfd18923651da6"],"layout":"IPY_MODEL_557b2eb97d1349b4a68940e23fa92b7c","tabbable":null,"tooltip":null}},"07913fbb69c94d699e33ba54984ba2bd":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_dc016e125ab44d83b31c56c9b8a05db6","IPY_MODEL_6089d81aa93a4195b6154492f41d0a14","IPY_MODEL_bc77e35d233d4945873dbeeb98b98dc6"],"layout":"IPY_MODEL_b801713c22c34236ae39b36710bcce4c","tabbable":null,"tooltip":null}},"1cb3b5b86ad345d0b6e68c4fbb280ad3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"20c07aedfe414bc9993988704e557a8b":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"21b2491e7882449cb606af852967cedc":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_8c346b2e656a4599886804e01224d89c","placeholder":"​","style":"IPY_MODEL_52d2fdc06cf04de29dc65a0426061a40","tabbable":null,"tooltip":null,"value":"Testing DataLoader 0: 100%"}},"29845b028c9d4de3b5be7dda49c0bf56":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_576e1b75c3634c3d8f3d90a2a16cecbd","IPY_MODEL_a29842bdb4ee40e0bca1ae5310c3cd3a","IPY_MODEL_cc2466ad4b1c4ebeb8ae79d2e0baa58c"],"layout":"IPY_MODEL_5610f9bca5c44a50a8e4d26a527b55df","tabbable":null,"tooltip":null}},"35d478df56604bdd910ec6d69f2a7974":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":"2","flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"363761e0911844729b4d1fd490b5146c":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"3c618cdbbff04264adbaf590c6de9b28":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_d7ea5bd4f38a4e71a15ca753f101752c","IPY_MODEL_47b5c924101d43c39875155d496e543b","IPY_MODEL_f99b00fb02024e6faa68cdd4b2a6cd75"],"layout":"IPY_MODEL_5ef13377f5ec4e388967c6e29dd0ad89","tabbable":null,"tooltip":null}},"3e7c1215a4974d448a74624faa631798":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"43068a20caa9451daacf4755ed33e209":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"47b5c924101d43c39875155d496e543b":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"","description":"","description_allow_html":false,"layout":"IPY_MODEL_9fad4a1a020745729497f52707ab2f5a","max":2,"min":0,"orientation":"horizontal","style":"IPY_MODEL_878ab2dab3c646f5ae9e2526a71e2261","tabbable":null,"tooltip":null,"value":2}},"4a77405c49ac49c48c0f1e64a43eb9e4":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_9af9686fe95440c3a599e8c7a37d18f4","max":39,"min":0,"orientation":"horizontal","style":"IPY_MODEL_f844a8f325c5479f85a8e8475bd7c63a","tabbable":null,"tooltip":null,"value":39}},"52d2fdc06cf04de29dc65a0426061a40":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"5528bb3aa9d2478ca7b273f14da74851":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":"inline-flex","flex":null,"flex_flow":"row wrap","grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":"100%"}},"557b2eb97d1349b4a68940e23fa92b7c":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":"inline-flex","flex":null,"flex_flow":"row wrap","grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":"hidden","width":"100%"}},"5610f9bca5c44a50a8e4d26a527b55df":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":"inline-flex","flex":null,"flex_flow":"row wrap","grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":"100%"}},"576e1b75c3634c3d8f3d90a2a16cecbd":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_94d45b02a3fd4e14a793a81996f5a426","placeholder":"​","style":"IPY_MODEL_e12ca6b909e14739a64fa0c3dd672f67","tabbable":null,"tooltip":null,"value":"Epoch 0: 100%"}},"5ef13377f5ec4e388967c6e29dd0ad89":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":"inline-flex","flex":null,"flex_flow":"row wrap","grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":"hidden","width":"100%"}},"6089d81aa93a4195b6154492f41d0a14":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_35d478df56604bdd910ec6d69f2a7974","max":255,"min":0,"orientation":"horizontal","style":"IPY_MODEL_9a0e5eb1c83240d095c50d81c5fd2440","tabbable":null,"tooltip":null,"value":255}},"68e74851e0dd4acc8d2a0f137ecd747a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"727bb77233094546928390d5c9c117f0":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"77877fe693ad4901b8d7ad7cab758679":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":"2","flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"7a4cdf3b36574522b3bb894dc9a91a64":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"827688b3bc394c48b923d61ed4328a69":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HBoxModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HBoxView","box_style":"","children":["IPY_MODEL_21b2491e7882449cb606af852967cedc","IPY_MODEL_4a77405c49ac49c48c0f1e64a43eb9e4","IPY_MODEL_9387a54192f747b89823ccf97b88a21f"],"layout":"IPY_MODEL_5528bb3aa9d2478ca7b273f14da74851","tabbable":null,"tooltip":null}},"878ab2dab3c646f5ae9e2526a71e2261":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"8c346b2e656a4599886804e01224d89c":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"8e3a0f2d70444464adbe869df5622729":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"9387a54192f747b89823ccf97b88a21f":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_04669661425c47c2b67266059c39ea4c","placeholder":"​","style":"IPY_MODEL_dd41fedfe6414a79b76fbf1e31fa6b63","tabbable":null,"tooltip":null,"value":" 39/39 [00:10&lt;00:00,  3.67it/s]"}},"94d45b02a3fd4e14a793a81996f5a426":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"98467816324b4e00aaa294776f810b17":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"9a0e5eb1c83240d095c50d81c5fd2440":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"9af9686fe95440c3a599e8c7a37d18f4":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":"2","flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"9fad4a1a020745729497f52707ab2f5a":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":"2","flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"a29842bdb4ee40e0bca1ae5310c3cd3a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"success","description":"","description_allow_html":false,"layout":"IPY_MODEL_02de625876424c81baeace5765af6754","max":179,"min":0,"orientation":"horizontal","style":"IPY_MODEL_7a4cdf3b36574522b3bb894dc9a91a64","tabbable":null,"tooltip":null,"value":179}},"ad3ad4b5d58146b9a87daeeff6ff50ee":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"b801713c22c34236ae39b36710bcce4c":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":"inline-flex","flex":null,"flex_flow":"row wrap","grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":"100%"}},"b9a9c3d3080a4183952d5ffeaf07a1ec":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"bc77e35d233d4945873dbeeb98b98dc6":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_68e74851e0dd4acc8d2a0f137ecd747a","placeholder":"​","style":"IPY_MODEL_8e3a0f2d70444464adbe869df5622729","tabbable":null,"tooltip":null,"value":" 255/255 [04:24&lt;00:00,  0.96it/s, v_num=0]"}},"c8987983b99a40b2afdfd18923651da6":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_edca07e16b304bb3b3948f53ee413f98","placeholder":"​","style":"IPY_MODEL_1cb3b5b86ad345d0b6e68c4fbb280ad3","tabbable":null,"tooltip":null,"value":" 39/39 [00:11&lt;00:00,  3.54it/s]"}},"cc2466ad4b1c4ebeb8ae79d2e0baa58c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_3e7c1215a4974d448a74624faa631798","placeholder":"​","style":"IPY_MODEL_b9a9c3d3080a4183952d5ffeaf07a1ec","tabbable":null,"tooltip":null,"value":" 179/179 [02:40&lt;00:00,  1.12it/s, v_num=1]"}},"d7ea5bd4f38a4e71a15ca753f101752c":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_98467816324b4e00aaa294776f810b17","placeholder":"​","style":"IPY_MODEL_ad3ad4b5d58146b9a87daeeff6ff50ee","tabbable":null,"tooltip":null,"value":"Sanity Checking DataLoader 0: 100%"}},"dc016e125ab44d83b31c56c9b8a05db6":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_e8685bc7a05541fdab450202ebbf22f4","placeholder":"​","style":"IPY_MODEL_727bb77233094546928390d5c9c117f0","tabbable":null,"tooltip":null,"value":"Epoch 0: 100%"}},"dd41fedfe6414a79b76fbf1e31fa6b63":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"df1b1cbf69824580b5c7f5c659e89568":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"FloatProgressModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"FloatProgressModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"ProgressView","bar_style":"","description":"","description_allow_html":false,"layout":"IPY_MODEL_77877fe693ad4901b8d7ad7cab758679","max":39,"min":0,"orientation":"horizontal","style":"IPY_MODEL_20c07aedfe414bc9993988704e557a8b","tabbable":null,"tooltip":null,"value":39}},"e12ca6b909e14739a64fa0c3dd672f67":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"e8685bc7a05541fdab450202ebbf22f4":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"edca07e16b304bb3b3948f53ee413f98":{"model_module":"@jupyter-widgets/base","model_module_version":"2.0.0","model_name":"LayoutModel","state":{"_model_module":"@jupyter-widgets/base","_model_module_version":"2.0.0","_model_name":"LayoutModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"LayoutView","align_content":null,"align_items":null,"align_self":null,"border_bottom":null,"border_left":null,"border_right":null,"border_top":null,"bottom":null,"display":null,"flex":null,"flex_flow":null,"grid_area":null,"grid_auto_columns":null,"grid_auto_flow":null,"grid_auto_rows":null,"grid_column":null,"grid_gap":null,"grid_row":null,"grid_template_areas":null,"grid_template_columns":null,"grid_template_rows":null,"height":null,"justify_content":null,"justify_items":null,"left":null,"margin":null,"max_height":null,"max_width":null,"min_height":null,"min_width":null,"object_fit":null,"object_position":null,"order":null,"overflow":null,"padding":null,"right":null,"top":null,"visibility":null,"width":null}},"ef4c2029e6084534bc28711c95cf48e4":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","background":null,"description_width":"","font_size":null,"text_color":null}},"f64fa3c3d26e4c5d9aeca1e5c6b6c0c3":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_43068a20caa9451daacf4755ed33e209","placeholder":"​","style":"IPY_MODEL_ef4c2029e6084534bc28711c95cf48e4","tabbable":null,"tooltip":null,"value":"Validation DataLoader 0: 100%"}},"f844a8f325c5479f85a8e8475bd7c63a":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"ProgressStyleModel","state":{"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"ProgressStyleModel","_view_count":null,"_view_module":"@jupyter-widgets/base","_view_module_version":"2.0.0","_view_name":"StyleView","bar_color":null,"description_width":""}},"f99b00fb02024e6faa68cdd4b2a6cd75":{"model_module":"@jupyter-widgets/controls","model_module_version":"2.0.0","model_name":"HTMLModel","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"2.0.0","_model_name":"HTMLModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"2.0.0","_view_name":"HTMLView","description":"","description_allow_html":false,"layout":"IPY_MODEL_363761e0911844729b4d1fd490b5146c","placeholder":"​","style":"IPY_MODEL_023414ebced74a43845ebb02ef34850d","tabbable":null,"tooltip":null,"value":" 2/2 [00:00&lt;00:00,  2.10it/s]"}}},"version_major":2,"version_minor":0}}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"### Forams Lightning EfficinentNetB3 +AutoEncoder","metadata":{"_cell_guid":"7a95fad8-3f22-42e4-8809-a219f494df8c","_uuid":"c3c46c4d-ae5d-4b5f-ad69-7c958b1be87c","collapsed":false,"jupyter":{"outputs_hidden":false},"papermill":{"duration":0.00943,"end_time":"2025-05-01T07:29:53.987264","exception":false,"start_time":"2025-05-01T07:29:53.977834","status":"completed"},"tags":[]}},{"cell_type":"code","source":"!pip install lightning","metadata":{"trusted":true,"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport lightning.pytorch as L\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch.utils.data import DataLoader, random_split, Dataset\nfrom torchvision import transforms\nfrom torchvision.utils import make_grid\nfrom torchvision.datasets import ImageFolder\nfrom torchvision.models import efficientnet_b1\nfrom lightning.pytorch.callbacks import ModelCheckpoint\nfrom lightning.pytorch import Trainer\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nfrom sklearn.metrics import classification_report\nimport lightning.pytorch as L\nfrom typing import List, Tuple, Optional\nfrom PIL import Image\nimport random","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"dir0='/kaggle/input/forams-classification-2025/visualizations/visualizations/labelled'\ndir2='/kaggle/input/forams-classification-2025/visualizations/visualizations/unlabelled'\n\ntrain=pd.read_csv('/kaggle/input/forams-classification-2025/labelled.csv')\nTEST=pd.read_csv('/kaggle/input/forams-classification-2025/sample_submission.csv')","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"TEST['path']=TEST['id'].apply(lambda x:os.path.join(dir2,'foram_'+str(x).zfill(5)+'.jpg'))\nTEST['label']=0 \ndisplay(TEST)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class_names = [str(i) for i in range(14)] ","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def create_path_label_list(df):\n    path_label_list = []\n    for _, row in df.iterrows():\n        idi = row['id'].split('_')[-1]\n        path=os.path.join(dir0,'labelled_foram_'+str(idi)+'.jpg')\n        label = row['label']\n        path_label_list.append((path, label))\n    return path_label_list\n\ntrain_path_label = create_path_label_list(train)\nrandom.shuffle(train_path_label)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def TEST_create_path_label_list(df):\n    path_label_list = []\n    for _, row in df.iterrows():\n        idi = row['id']\n        path=os.path.join(dir2,'foram_'+str(idi).zfill(5)+'.jpg')\n        label = row['label']\n        path_label_list.append((path, label))\n    return path_label_list\n\ntest_path_label = TEST_create_path_label_list(TEST)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"# EfficientNet Feature Extractor - Simple, reliable version\nclass EfficientNetFeatures(nn.Module):\n    def __init__(self):\n        super().__init__()\n        # Load pretrained EfficientNet without classifier\n        efficientnet = efficientnet_b1(pretrained=True)\n        # Remove the classifier\n        self.features = nn.Sequential(*list(efficientnet.children())[:-1])\n        \n    def forward(self, x):\n        return self.features(x)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# AutoEncoder with simpler architecture that uses interpolation\nclass SimpleAutoEncoder(L.LightningModule):\n    def __init__(self):\n        super().__init__()\n        \n        # Encoder\n        self.encoder = EfficientNetFeatures()\n        \n        # Simple decoder with 1 conv layer to change channels followed by upsampling\n        self.decoder = nn.Sequential(\n            nn.Conv2d(1280, 3, kernel_size=1),  # Simply convert channels from 1280 to 3\n            nn.Sigmoid()  # Ensure output is between 0 and 1\n        )\n    \n    def forward(self, x):\n        encoded = self.encoder(x)\n        # Get feature map with adjusted channels\n        features = self.decoder(encoded)\n        # Upsample to match the input size directly\n        return F.interpolate(features, size=(300,300), mode='bilinear', align_corners=False)\n    \n    def training_step(self, batch, batch_idx):\n        x, _ = batch  # Ignore labels for pretraining\n        reconstruction = self(x)\n        \n        if batch_idx == 0:\n            print(f\"Train - Input: {x.shape}, Output: {reconstruction.shape}\")\n            \n        loss = F.mse_loss(reconstruction, x)\n        self.log('train_loss', loss)\n        return loss\n    \n    def validation_step(self, batch, batch_idx):\n        x, _ = batch\n        reconstruction = self(x)\n        \n        if batch_idx == 0:\n            print(f\"Val - Input: {x.shape}, Output: {reconstruction.shape}\")\n            \n        loss = F.mse_loss(reconstruction, x)\n        self.log('val_loss', loss)\n    \n    def configure_optimizers(self):\n        return torch.optim.Adam(self.parameters(), lr=1e-3)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Classification model that uses the encoder\nclass FineTuneModel(L.LightningModule):\n    def __init__(self, pretrained_encoder, num_classes):\n        super().__init__()\n        \n        # Use the encoder module\n        self.encoder = pretrained_encoder\n        \n        # Freeze the encoder\n        for param in self.encoder.parameters():\n            param.requires_grad = False\n        \n        # Add a classifier head\n        self.classifier = nn.Sequential(\n            nn.AdaptiveAvgPool2d(1),\n            nn.Flatten(),\n            nn.Linear(1280, 512),\n            nn.ReLU(),\n            nn.Dropout(0.2),\n            nn.Linear(512, num_classes)\n        )\n        \n    def forward(self, x):\n        features = self.encoder(x)\n        return self.classifier(features)\n    \n    def training_step(self, batch, batch_idx):\n        x, y = batch\n        logits = self(x)\n        loss = F.cross_entropy(logits, y)\n        self.log('train_loss', loss)\n        return loss\n    \n    def validation_step(self, batch, batch_idx):\n        x, y = batch\n        logits = self(x)\n        loss = F.cross_entropy(logits, y)\n        preds = torch.argmax(logits, dim=1)\n        acc = (preds == y).float().mean()\n        self.log('val_loss', loss)\n        self.log('val_acc', acc)\n        \n    def test_step(self, batch, batch_idx):\n        x, y = batch\n        logits = self(x)\n        preds = torch.argmax(logits, dim=1)\n        acc = (preds == y).float().mean()\n        self.log('test_acc', acc)\n    \n    def configure_optimizers(self):\n        return torch.optim.Adam(self.parameters(), lr=1e-3)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Data Module\nclass CustomDataset(Dataset):\n    def __init__(self, path_label_list, transform=None):\n        self.path_label_list = path_label_list\n        self.transform = transform\n        self.classes = sorted(list(set([label for _, label in path_label_list])))\n        self.class_to_idx = {cls: idx for idx, cls in enumerate(self.classes)}\n    \n    def __len__(self):\n        return len(self.path_label_list)\n    \n    def __getitem__(self, idx):\n        img_path, label = self.path_label_list[idx]\n        img = Image.open(img_path).convert('RGB')\n        \n        if self.transform:\n            img = self.transform(img)\n\n        label_idx = self.class_to_idx[label]\n        return img, label_idx\n\nclass DataModule(L.LightningDataModule):\n    def __init__(\n        self, \n        train_path_label: List[Tuple[str, str]],  # [(path, label), ...] \n        test_path_label: List[Tuple[str, str]],    \n        batch_size: int = 32,\n        transform: Optional[transforms.Compose] = None,\n        val_ratio: float = 0.15\n    ):\n        super().__init__()\n        self.train_path_label = train_path_label\n        self.test_path_label = test_path_label\n        self.batch_size = batch_size\n        self.val_ratio = val_ratio\n\n        self.transform = transform if transform is not None else transforms.Compose([\n            transforms.Resize((300,300)),\n            transforms.ToTensor(),\n            transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])\n        ])\n    \n    def setup(self, stage: Optional[str] = None):\n\n        train_size = int((1 - self.val_ratio) * len(self.train_path_label))\n        val_size = len(self.train_path_label) - train_size\n\n        self.train_dataset = CustomDataset(\n            self.train_path_label[:train_size], \n            transform=self.transform\n        )\n        self.val_dataset = CustomDataset(\n            self.train_path_label[train_size:], \n            transform=self.transform\n        )\n        self.test_dataset = CustomDataset(\n            self.test_path_label,\n            transform=self.transform\n        )\n\n        self.classes = self.train_dataset.classes\n        self.num_classes = len(self.classes)\n    \n    def train_dataloader(self):\n        return DataLoader(\n            self.train_dataset, \n            batch_size=self.batch_size, \n            shuffle=True, \n            num_workers=4\n        )\n    \n    def val_dataloader(self):\n        return DataLoader(\n            self.val_dataset, \n            batch_size=self.batch_size, \n            num_workers=4\n        )\n    \n    def test_dataloader(self):\n        return DataLoader(\n            self.test_dataset, \n            batch_size=self.batch_size, \n            num_workers=4\n        )\n    \n    def pretrain_dataloader(self):\n        return self.train_dataloader()\n\n","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"dm = DataModule(\n    train_path_label=train_path_label,\n    test_path_label=test_path_label,\n    batch_size=64\n)\ndm.setup()\n\n\n# 1. Pretraining the AutoEncoder\nautoencoder = SimpleAutoEncoder()\n\n# Callback for pretraining\npretrain_checkpoint = ModelCheckpoint(\n    monitor='val_loss',\n    filename='autoencoder-{epoch:02d}-{val_loss:.2f}',\n    save_top_k=1,\n    mode='min'\n)\n\npretrainer = Trainer(\n    max_epochs=30,#fix\n    callbacks=[pretrain_checkpoint],\n    accelerator='auto',\n    devices=1\n)\n\nprint(\"Starting AutoEncoder pretraining...\")\npretrainer.fit(autoencoder, dm.pretrain_dataloader(), dm.val_dataloader())\n\nprint('----------------------'*3)\n\n\n# 2. Fine-tuning\nmodel = FineTuneModel(autoencoder.encoder, dm.num_classes)\n\nfinetune_checkpoint = ModelCheckpoint(\n    monitor='val_acc',\n    filename='finetune-{epoch:02d}-{val_acc:.2f}',\n    save_top_k=1,\n    mode='max'\n)\n\nfinetuner = Trainer(\n    max_epochs=600,\n    callbacks=[finetune_checkpoint],\n    accelerator='auto',\n    devices=1\n)\n\nprint(\"Starting Fine-tuning...\")\nfinetuner.fit(model, dm.train_dataloader(), dm.val_dataloader())\n\n# 3. Testing\nprint(\"Starting Testing...\")\nfinetuner.test(model, dm.test_dataloader())","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"---","metadata":{}},{"cell_type":"code","source":"for images, labels in dm.test_dataloader():\n    break\n\nim=make_grid(images,nrow=8)\nplt.figure(figsize=(12,12))\nplt.imshow(np.transpose(im.numpy(),(1,2,0)))\ninv_normalize=transforms.Normalize(mean=[-0.485/0.229,-0.456/0.224,-0.406/0.225],\n                                   std=[1/0.229,1/0.224,1/0.225])\nim=inv_normalize(im)\nplt.figure(figsize=(12,12))\nplt.imshow(np.transpose(im.numpy(),(1,2,0)))","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"device = torch.device(\"cpu\")   #\"cuda:0\"\n\nmodel.eval()\ny_pred=[]\nwith torch.no_grad():\n    for test_data in dm.test_dataloader():\n        test_images, test_labels = test_data[0].to(device), test_data[1].to(device)\n        pred = model(test_images).argmax(dim=1)\n        for i in range(len(pred)):\n            y_pred.append(pred[i].item())","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"TEST['label']=y_pred\ndisplay(TEST)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submit=TEST[['id','label']]\nsubmit.to_csv('submission.csv',index=False)\ndisplay(submit)","metadata":{"_cell_guid":"9cbe0b47-ae82-48b3-9927-b19f47ccf7bc","_uuid":"57c8a236-6589-4b65-ae79-0fba0ac407c0","collapsed":false,"jupyter":{"outputs_hidden":false},"papermill":{"duration":0.076141,"end_time":"2025-05-01T07:40:26.020029","exception":false,"start_time":"2025-05-01T07:40:25.943888","status":"completed"},"tags":[]},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}