diff --git "a/detection.ipynb" "b/detection.ipynb" new file mode 100644--- /dev/null +++ "b/detection.ipynb" @@ -0,0 +1,2218 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "gpuType": "V28" + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "TPU", + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "69a62d46747e46ddad5261495a1c3790": { + "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_b9e15f2aaef94604b6a7b69dcc9f61d0", + "IPY_MODEL_f39e8e0efd364a63804bf5c27cfc3e25", + "IPY_MODEL_7bf95b8733814eccbd60e898e0294146" + ], + "layout": "IPY_MODEL_2efdf7cc1cf94b9794c4e5ea52ec145d" + } + }, + "b9e15f2aaef94604b6a7b69dcc9f61d0": { + "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_58a216caecd1442682f1c27097ead127", + "placeholder": "​", + "style": "IPY_MODEL_d5b6085bb65e4fb782681ff7e71cd8c8", + "value": "Collecting labels: " + } + }, + "f39e8e0efd364a63804bf5c27cfc3e25": { + "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_44a0801e62b04c40afb4a3d353399eca", + "max": 1, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_2fc349b63d934922ad2a61e0d9bd060c", + "value": 1 + } + }, + "7bf95b8733814eccbd60e898e0294146": { + "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_771f9e5276a84589bd8d3e3a26ea4100", + "placeholder": "​", + "style": "IPY_MODEL_8d7777b761ab4cdaa0ad787c666d57d5", + "value": " 43503/? [01:05<00:00, 683.55it/s]" + } + }, + "2efdf7cc1cf94b9794c4e5ea52ec145d": { + "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 + } + }, + "58a216caecd1442682f1c27097ead127": { + "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 + } + }, + "d5b6085bb65e4fb782681ff7e71cd8c8": { + "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": "" + } + }, + "44a0801e62b04c40afb4a3d353399eca": { + "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": "20px" + } + }, + "2fc349b63d934922ad2a61e0d9bd060c": { + "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": "" + } + }, + "771f9e5276a84589bd8d3e3a26ea4100": { + "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 + } + }, + "8d7777b761ab4cdaa0ad787c666d57d5": { + "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": "" + } + }, + "2046fdcbaee744edaa528dd60fa31d21": { + "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_03362efffc77447b8a08bcf7d4c01cfd", + "IPY_MODEL_9f1d99e55b7a4fabbe35dd2d3a3f1743", + "IPY_MODEL_707de373165642f5bd48d78f0a574a5e" + ], + "layout": "IPY_MODEL_7b56475edf004b2eb63337d327514deb" + } + }, + "03362efffc77447b8a08bcf7d4c01cfd": { + "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_154e3a2ffc6747c1a2696648aba6ddc2", + "placeholder": "​", + "style": "IPY_MODEL_1e90bbfe08054cd395cf330f5ebdb57f", + "value": "Loading train: " + } + }, + "9f1d99e55b7a4fabbe35dd2d3a3f1743": { + "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_e183b07566c44060a98d699dec31f19f", + "max": 1, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_0d56c5aedfda4190b4b71d66dfe3be2c", + "value": 1 + } + }, + "707de373165642f5bd48d78f0a574a5e": { + "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_b385e38a2d3b492f81535a19da9c10e7", + "placeholder": "​", + "style": "IPY_MODEL_8053de86bdbb4f53985fb9c9310f9301", + "value": " 43503/? [01:10<00:00, 621.22it/s]" + } + }, + "7b56475edf004b2eb63337d327514deb": { + "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 + } + }, + "154e3a2ffc6747c1a2696648aba6ddc2": { + "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 + } + }, + "1e90bbfe08054cd395cf330f5ebdb57f": { + "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": "" + } + }, + "e183b07566c44060a98d699dec31f19f": { + "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": "20px" + } + }, + "0d56c5aedfda4190b4b71d66dfe3be2c": { + "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": "" + } + }, + "b385e38a2d3b492f81535a19da9c10e7": { + "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 + } + }, + "8053de86bdbb4f53985fb9c9310f9301": { + "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": "" + } + }, + "2a7e45b8dd534e67a23577404d725b58": { + "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_85ac73f124394664a17c9dfe940605f3", + "IPY_MODEL_d84b85a8a85a4ad09cd2a76d878b51f6", + "IPY_MODEL_5d0b465783eb4d979570e7780276a421" + ], + "layout": "IPY_MODEL_d00caeab260b476f8d36a206d116526d" + } + }, + "85ac73f124394664a17c9dfe940605f3": { + "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_da2dcd5cb02e4412b8536a1839d8adf5", + "placeholder": "​", + "style": "IPY_MODEL_e240cfa86ed74ea0ad3b7226530ff41f", + "value": "Loading test: " + } + }, + "d84b85a8a85a4ad09cd2a76d878b51f6": { + "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_69771c4b6a914764a2f367bcf59bea49", + "max": 1, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_44fc02ca931641608193a34922977d08", + "value": 1 + } + }, + "5d0b465783eb4d979570e7780276a421": { + "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_834144da422b4a9495d0e5655714cbf9", + "placeholder": "​", + "style": "IPY_MODEL_5521f8014e854f1cbe3c93ecb2780af5", + "value": " 10878/? [00:17<00:00, 656.58it/s]" + } + }, + "d00caeab260b476f8d36a206d116526d": { + "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 + } + }, + "da2dcd5cb02e4412b8536a1839d8adf5": { + "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 + } + }, + "e240cfa86ed74ea0ad3b7226530ff41f": { + "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": "" + } + }, + "69771c4b6a914764a2f367bcf59bea49": { + "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": "20px" + } + }, + "44fc02ca931641608193a34922977d08": { + "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": "" + } + }, + "834144da422b4a9495d0e5655714cbf9": { + "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 + } + }, + "5521f8014e854f1cbe3c93ecb2780af5": { + "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": "" + } + }, + "681d23e34e334f1b83e6afa9903fe72c": { + "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_12434f0d1a33473997d752900043cfbc", + "IPY_MODEL_8ba7ea8bfcc84228b7a8b00d27aaec62", + "IPY_MODEL_ef28e650217649a6a09b18a870ccf9f3" + ], + "layout": "IPY_MODEL_029419d39b774759a3672b810e5f283d" + } + }, + "12434f0d1a33473997d752900043cfbc": { + "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_c0c317b2311149bd96a5ed0f5d737411", + "placeholder": "​", + "style": "IPY_MODEL_a3837d4e34fa44199c15eee100991c51", + "value": "Loading train: " + } + }, + "8ba7ea8bfcc84228b7a8b00d27aaec62": { + "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": "info", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_8be0aef085f14db98c01055ac6377419", + "max": 1, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_eac5b5ff64d14810928db28d72f66398", + "value": 1 + } + }, + "ef28e650217649a6a09b18a870ccf9f3": { + "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_8528453a25df4b33acba942a4a74d6ed", + "placeholder": "​", + "style": "IPY_MODEL_a69e2de4b71349b0ba962751fe63ee1b", + "value": " 7801/? [03:40<00:00, 13.50it/s]" + } + }, + "029419d39b774759a3672b810e5f283d": { + "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 + } + }, + "c0c317b2311149bd96a5ed0f5d737411": { + "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 + } + }, + "a3837d4e34fa44199c15eee100991c51": { + "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": "" + } + }, + "8be0aef085f14db98c01055ac6377419": { + "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": "20px" + } + }, + "eac5b5ff64d14810928db28d72f66398": { + "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": "" + } + }, + "8528453a25df4b33acba942a4a74d6ed": { + "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 + } + }, + "a69e2de4b71349b0ba962751fe63ee1b": { + "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": "" + } + } + } + } + }, + "cells": [ + { + "cell_type": "code", + "source": [ + "!pip install tensorflow datasets tqdm typing-extensions==4.11.0 --quiet\n", + "\n", + "# 2. IMPORT LIBRARIES\n", + "import numpy as np\n", + "import tensorflow as tf\n", + "from tensorflow.keras.models import Sequential\n", + "from tensorflow.keras.layers import Conv2D, MaxPooling2D, BatchNormalization, LeakyReLU\n", + "from tensorflow.keras.layers import Dense, Dropout, Flatten, Activation\n", + "from tensorflow.keras.regularizers import l2\n", + "from tensorflow.keras.optimizers import Adam\n", + "from tensorflow.keras.preprocessing.image import ImageDataGenerator,img_to_array\n", + "from tensorflow.keras.callbacks import EarlyStopping, ReduceLROnPlateau, ModelCheckpoint\n", + "from sklearn.utils.class_weight import compute_class_weight\n", + "from datasets import load_dataset\n", + "from tqdm.auto import tqdm\n", + "from sklearn.preprocessing import LabelEncoder\n", + "import matplotlib.pyplot as plt\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "collapsed": true, + "id": "yTl22T6lTrQz", + "outputId": "7946553e-a6ff-460c-f4a1-cda10f56089a" + }, + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m69.2/69.2 kB\u001b[0m \u001b[31m2.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m644.9/644.9 MB\u001b[0m \u001b[31m1.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m491.2/491.2 kB\u001b[0m \u001b[31m96.6 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m116.3/116.3 kB\u001b[0m \u001b[31m9.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m183.9/183.9 kB\u001b[0m \u001b[31m15.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.7/1.7 MB\u001b[0m \u001b[31m68.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m57.5/57.5 kB\u001b[0m \u001b[31m4.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m24.5/24.5 MB\u001b[0m \u001b[31m70.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m143.5/143.5 kB\u001b[0m \u001b[31m11.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.5/5.5 MB\u001b[0m \u001b[31m106.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m5.1/5.1 MB\u001b[0m \u001b[31m101.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m194.8/194.8 kB\u001b[0m \u001b[31m16.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m274.9/274.9 kB\u001b[0m \u001b[31m19.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m232.5/232.5 kB\u001b[0m \u001b[31m16.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.6/6.6 MB\u001b[0m \u001b[31m111.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m224.5/224.5 kB\u001b[0m \u001b[31m16.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m72.5/72.5 kB\u001b[0m \u001b[31m5.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m344.1/344.1 kB\u001b[0m \u001b[31m25.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "pydantic 2.10.6 requires typing-extensions>=4.12.2, but you have typing-extensions 4.11.0 which is incompatible.\u001b[0m\u001b[31m\n", + "\u001b[0m" + ] + } + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "k8fTZRWiSyX1" + }, + "outputs": [], + "source": [ + "CONFIG = {\n", + " \"image_size\": (128, 128),\n", + " \"batch_size\": 64,\n", + " \"epochs\": 30,\n", + " \"num_train_samples\": 5000,\n", + " \"num_test_samples\": 1000,\n", + " \"learning_rate\": 3e-4,\n", + " \"weight_decay\": 1e-4,\n", + " \"early_stop_patience\": 10,\n", + " \"lr_patience\": 5,\n", + "\n", + "}" + ] + }, + { + "cell_type": "code", + "source": [ + "def preprocess_image(sample):\n", + " \"\"\"Preprocess images for TensorFlow Dataset\"\"\"\n", + " img = sample['image'].convert(\"RGB\")\n", + " img = img.resize(CONFIG[\"image_size\"])\n", + "\n", + " img_array = np.array(img, dtype=np.float32) / 255.0\n", + "\n", + " return img_array, sample['label']\n", + "\n", + "def load_data_generator(split, le, batch_size=CONFIG[\"batch_size\"]):\n", + " \"\"\"Loads data as a generator using streaming\"\"\"\n", + " dataset = load_dataset(\"GVJahnavi/PlantVillage_dataset\", split=split, streaming=True)\n", + "\n", + " images, labels = [], []\n", + " count = 0 # Track the number of samples processed\n", + "\n", + " for sample in tqdm(dataset, desc=f\"Loading {split}\"):\n", + " try:\n", + " img_array, label = preprocess_image(sample)\n", + "\n", + " # Ensure image has correct shape (128, 128, 3)\n", + " if img_array.shape != (CONFIG[\"image_size\"][0], CONFIG[\"image_size\"][1], 3):\n", + " print(f\"Skipping image with wrong shape: {img_array.shape}\")\n", + " continue\n", + "\n", + " images.append(img_array)\n", + " labels.append(label)\n", + " count += 1\n", + "\n", + " # Yield batch\n", + " if len(images) == batch_size:\n", + " yield np.array(images), le.transform(np.array(labels))\n", + " images, labels = [], [] # Reset batch\n", + "\n", + " except Exception as e:\n", + " print(f\"Skipping image due to error: {e}\")\n", + " continue\n", + "\n", + " # Yield last batch if exists\n", + " if images:\n", + " yield np.array(images), le.transform(np.array(labels)) # Encode labels" + ], + "metadata": { + "id": "ZgMPkjYzr94R" + }, + "execution_count": 5, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# ==============================================\n", + "# Data Loading\n", + "# ==============================================\n", + "print(\"Loading data...\")\n", + "\n", + "# Initialize LabelEncoder\n", + "le = LabelEncoder()\n", + "\n", + "# Collect all labels to encode them\n", + "all_labels = []\n", + "dataset = load_dataset(\"GVJahnavi/PlantVillage_dataset\", split=\"train\", streaming=True)\n", + "for sample in tqdm(dataset, desc=\"Collecting labels\"):\n", + " try:\n", + " _, label = preprocess_image(sample)\n", + " all_labels.append(label)\n", + " except Exception as e:\n", + " print(f\"Skipping label due to error: {e}\")\n", + " continue\n", + "\n", + "le.fit(all_labels) # Fit on all labels\n", + "\n", + "# Split labels for train and test\n", + "train_labels = all_labels[:len(all_labels)//2]\n", + "test_labels = all_labels[len(all_labels)//2:]\n", + "\n", + "# Compute class weights\n", + "y_train = le.transform(train_labels)\n", + "class_weights = compute_class_weight('balanced', classes=np.unique(y_train), y=y_train)\n", + "class_weights = dict(enumerate(class_weights))\n", + "\n", + "# Initialize generators and consume them to load data\n", + "train_generator = list(load_data_generator(\"train\", le))\n", + "test_generator = list(load_data_generator(\"test\", le))\n", + "\n", + "\n", + "print(\"Data loading complete.\")\n" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 148, + "referenced_widgets": [ + "69a62d46747e46ddad5261495a1c3790", + "b9e15f2aaef94604b6a7b69dcc9f61d0", + "f39e8e0efd364a63804bf5c27cfc3e25", + "7bf95b8733814eccbd60e898e0294146", + "2efdf7cc1cf94b9794c4e5ea52ec145d", + "58a216caecd1442682f1c27097ead127", + "d5b6085bb65e4fb782681ff7e71cd8c8", + "44a0801e62b04c40afb4a3d353399eca", + "2fc349b63d934922ad2a61e0d9bd060c", + "771f9e5276a84589bd8d3e3a26ea4100", + "8d7777b761ab4cdaa0ad787c666d57d5", + "2046fdcbaee744edaa528dd60fa31d21", + "03362efffc77447b8a08bcf7d4c01cfd", + "9f1d99e55b7a4fabbe35dd2d3a3f1743", + "707de373165642f5bd48d78f0a574a5e", + "7b56475edf004b2eb63337d327514deb", + "154e3a2ffc6747c1a2696648aba6ddc2", + "1e90bbfe08054cd395cf330f5ebdb57f", + "e183b07566c44060a98d699dec31f19f", + "0d56c5aedfda4190b4b71d66dfe3be2c", + "b385e38a2d3b492f81535a19da9c10e7", + "8053de86bdbb4f53985fb9c9310f9301", + "2a7e45b8dd534e67a23577404d725b58", + "85ac73f124394664a17c9dfe940605f3", + "d84b85a8a85a4ad09cd2a76d878b51f6", + "5d0b465783eb4d979570e7780276a421", + "d00caeab260b476f8d36a206d116526d", + "da2dcd5cb02e4412b8536a1839d8adf5", + "e240cfa86ed74ea0ad3b7226530ff41f", + "69771c4b6a914764a2f367bcf59bea49", + "44fc02ca931641608193a34922977d08", + "834144da422b4a9495d0e5655714cbf9", + "5521f8014e854f1cbe3c93ecb2780af5" + ] + }, + "id": "bU4XWv-MTAUG", + "outputId": "cccc9488-3848-4a51-8ea8-033b47b1af42" + }, + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Loading data...\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Collecting labels: 0it [00:00, ?it/s]" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "69a62d46747e46ddad5261495a1c3790" + } + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Loading train: 0it [00:00, ?it/s]" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "2046fdcbaee744edaa528dd60fa31d21" + } + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Loading test: 0it [00:00, ?it/s]" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "2a7e45b8dd534e67a23577404d725b58" + } + }, + "metadata": {} + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Data loading complete.\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "# ==============================================\n", + "# Data Augmentation\n", + "# ==============================================\n", + "train_datagen = ImageDataGenerator(\n", + " rotation_range=40,\n", + " width_shift_range=0.2,\n", + " height_shift_range=0.2,\n", + " shear_range=0.2,\n", + " zoom_range=0.2,\n", + " horizontal_flip=True,\n", + " vertical_flip=True, # Added vertical flip\n", + " fill_mode='nearest'\n", + ")\n", + "\n", + "val_datagen = ImageDataGenerator()\n" + ], + "metadata": { + "id": "jxzXz9NoTCCT" + }, + "execution_count": 7, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# ==============================================\n", + "# Enhanced Model Architecture\n", + "# ==============================================\n", + "def build_model():\n", + " model = Sequential()\n", + " input_shape = (*CONFIG[\"image_size\"], 3)\n", + "\n", + " # Conv Blocks\n", + " filters = [32, 64, 128, 256]\n", + " dropouts = [0.25, 0.3, 0.4, 0.5]\n", + "\n", + " for i, (f, dr) in enumerate(zip(filters, dropouts)):\n", + " # First block has input_shape\n", + " if i == 0:\n", + " model.add(Conv2D(f, (3,3), padding=\"same\", input_shape=input_shape,\n", + " kernel_regularizer=l2(CONFIG[\"weight_decay\"])) )\n", + " else:\n", + " model.add(Conv2D(f, (3,3), padding=\"same\", kernel_regularizer=l2(CONFIG[\"weight_decay\"])))\n", + "\n", + " model.add(LeakyReLU(alpha=0.1))\n", + " model.add(BatchNormalization())\n", + "\n", + " # Add second conv layer for deeper blocks\n", + " if i >= 1:\n", + " model.add(Conv2D(f, (3,3), padding=\"same\"))\n", + " model.add(LeakyReLU(alpha=0.1))\n", + " model.add(BatchNormalization())\n", + "\n", + " model.add(MaxPooling2D((2,2)))\n", + " model.add(Dropout(dr))\n", + "\n", + " # Classifier\n", + " model.add(Flatten())\n", + " model.add(Dense(1024, kernel_regularizer=l2(CONFIG[\"weight_decay\"])) )\n", + " model.add(LeakyReLU(alpha=0.1))\n", + " model.add(BatchNormalization())\n", + " model.add(Dropout(0.6))\n", + "\n", + " model.add(Dense(len(le.classes_), activation='softmax'))\n", + "\n", + " return model\n", + "\n", + "model = build_model()\n", + "model.summary()" + ], + "metadata": { + "id": "_vJw4cBKXDT1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "collapsed": true, + "outputId": "1ee5d619-7e01-49af-91ad-4c96e2b0d0cb" + }, + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "/usr/local/lib/python3.11/dist-packages/keras/src/layers/convolutional/base_conv.py:107: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n", + " super().__init__(activity_regularizer=activity_regularizer, **kwargs)\n", + "/usr/local/lib/python3.11/dist-packages/keras/src/layers/activations/leaky_relu.py:41: UserWarning: Argument `alpha` is deprecated. Use `negative_slope` instead.\n", + " warnings.warn(\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\u001b[1mModel: \"sequential\"\u001b[0m\n" + ], + "text/html": [ + "
Model: \"sequential\"\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓\n", + "┃\u001b[1m \u001b[0m\u001b[1mLayer (type) \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mOutput Shape \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1m Param #\u001b[0m\u001b[1m \u001b[0m┃\n", + "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩\n", + "│ conv2d (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m896\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ leaky_re_lu (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ batch_normalization │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m128\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m128\u001b[0m │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ max_pooling2d (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ dropout (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m32\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ conv2d_1 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m18,496\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ leaky_re_lu_1 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ batch_normalization_1 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m256\u001b[0m │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ conv2d_2 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m36,928\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ leaky_re_lu_2 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ batch_normalization_2 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m256\u001b[0m │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ max_pooling2d_1 (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ dropout_1 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m64\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ conv2d_3 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m73,856\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ leaky_re_lu_3 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ batch_normalization_3 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\u001b[0m │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ conv2d_4 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m147,584\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ leaky_re_lu_4 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ batch_normalization_4 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m32\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m512\u001b[0m │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ max_pooling2d_2 (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ dropout_2 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m128\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ conv2d_5 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m295,168\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ leaky_re_lu_5 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ batch_normalization_5 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ conv2d_6 (\u001b[38;5;33mConv2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m590,080\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ leaky_re_lu_6 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ batch_normalization_6 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m16\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m1,024\u001b[0m │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ max_pooling2d_3 (\u001b[38;5;33mMaxPooling2D\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ dropout_3 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m8\u001b[0m, \u001b[38;5;34m256\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ flatten (\u001b[38;5;33mFlatten\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m16384\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ dense (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m16,778,240\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ leaky_re_lu_7 (\u001b[38;5;33mLeakyReLU\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ batch_normalization_7 │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m4,096\u001b[0m │\n", + "│ (\u001b[38;5;33mBatchNormalization\u001b[0m) │ │ │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ dropout_4 (\u001b[38;5;33mDropout\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m1024\u001b[0m) │ \u001b[38;5;34m0\u001b[0m │\n", + "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n", + "│ dense_1 (\u001b[38;5;33mDense\u001b[0m) │ (\u001b[38;5;45mNone\u001b[0m, \u001b[38;5;34m38\u001b[0m) │ \u001b[38;5;34m38,950\u001b[0m │\n", + "└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘\n" + ], + "text/html": [ + "
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓\n",
+              "┃ Layer (type)                          Output Shape                         Param # ┃\n",
+              "┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩\n",
+              "│ conv2d (Conv2D)                      │ (None, 128, 128, 32)        │             896 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ leaky_re_lu (LeakyReLU)              │ (None, 128, 128, 32)        │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ batch_normalization                  │ (None, 128, 128, 32)        │             128 │\n",
+              "│ (BatchNormalization)                 │                             │                 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ max_pooling2d (MaxPooling2D)         │ (None, 64, 64, 32)          │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ dropout (Dropout)                    │ (None, 64, 64, 32)          │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ conv2d_1 (Conv2D)                    │ (None, 64, 64, 64)          │          18,496 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼──────────────��──┤\n",
+              "│ leaky_re_lu_1 (LeakyReLU)            │ (None, 64, 64, 64)          │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ batch_normalization_1                │ (None, 64, 64, 64)          │             256 │\n",
+              "│ (BatchNormalization)                 │                             │                 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ conv2d_2 (Conv2D)                    │ (None, 64, 64, 64)          │          36,928 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ leaky_re_lu_2 (LeakyReLU)            │ (None, 64, 64, 64)          │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ batch_normalization_2                │ (None, 64, 64, 64)          │             256 │\n",
+              "│ (BatchNormalization)                 │                             │                 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ max_pooling2d_1 (MaxPooling2D)       │ (None, 32, 32, 64)          │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────���─────────────────┤\n",
+              "│ dropout_1 (Dropout)                  │ (None, 32, 32, 64)          │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ conv2d_3 (Conv2D)                    │ (None, 32, 32, 128)         │          73,856 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ leaky_re_lu_3 (LeakyReLU)            │ (None, 32, 32, 128)         │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ batch_normalization_3                │ (None, 32, 32, 128)         │             512 │\n",
+              "│ (BatchNormalization)                 │                             │                 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ conv2d_4 (Conv2D)                    │ (None, 32, 32, 128)         │         147,584 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ leaky_re_lu_4 (LeakyReLU)            │ (None, 32, 32, 128)         │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ batch_normalization_4                │ (None, 32, 32, 128)         │             512 │\n",
+              "│ (BatchNormalization)                 │                             │                 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ max_pooling2d_2 (MaxPooling2D)       │ (None, 16, 16, 128)         │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ dropout_2 (Dropout)                  │ (None, 16, 16, 128)         │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ conv2d_5 (Conv2D)                    │ (None, 16, 16, 256)         │         295,168 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ leaky_re_lu_5 (LeakyReLU)            │ (None, 16, 16, 256)         │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ batch_normalization_5                │ (None, 16, 16, 256)         │           1,024 │\n",
+              "│ (BatchNormalization)                 │                             │                 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼───────��─────────┤\n",
+              "│ conv2d_6 (Conv2D)                    │ (None, 16, 16, 256)         │         590,080 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ leaky_re_lu_6 (LeakyReLU)            │ (None, 16, 16, 256)         │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ batch_normalization_6                │ (None, 16, 16, 256)         │           1,024 │\n",
+              "│ (BatchNormalization)                 │                             │                 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ max_pooling2d_3 (MaxPooling2D)       │ (None, 8, 8, 256)           │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ dropout_3 (Dropout)                  │ (None, 8, 8, 256)           │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ flatten (Flatten)                    │ (None, 16384)               │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ dense (Dense)                        │ (None, 1024)                │      16,778,240 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ leaky_re_lu_7 (LeakyReLU)            │ (None, 1024)                │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ batch_normalization_7                │ (None, 1024)                │           4,096 │\n",
+              "│ (BatchNormalization)                 │                             │                 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ dropout_4 (Dropout)                  │ (None, 1024)                │               0 │\n",
+              "├──────────────────────────────────────┼─────────────────────────────┼─────────────────┤\n",
+              "│ dense_1 (Dense)                      │ (None, 38)                  │          38,950 │\n",
+              "└──────────────────────────────────────┴─────────────────────────────┴─────────────────┘\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\u001b[1m Total params: \u001b[0m\u001b[38;5;34m17,988,006\u001b[0m (68.62 MB)\n" + ], + "text/html": [ + "
 Total params: 17,988,006 (68.62 MB)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\u001b[1m Trainable params: \u001b[0m\u001b[38;5;34m17,984,102\u001b[0m (68.60 MB)\n" + ], + "text/html": [ + "
 Trainable params: 17,984,102 (68.60 MB)\n",
+              "
\n" + ] + }, + "metadata": {} + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "\u001b[1m Non-trainable params: \u001b[0m\u001b[38;5;34m3,904\u001b[0m (15.25 KB)\n" + ], + "text/html": [ + "
 Non-trainable params: 3,904 (15.25 KB)\n",
+              "
\n" + ] + }, + "metadata": {} + } + ] + }, + { + "cell_type": "code", + "source": [ + "# ==============================================\n", + "# Training Setup\n", + "# ==============================================\n", + "optimizer = Adam(learning_rate=CONFIG[\"learning_rate\"],\n", + " weight_decay=CONFIG[\"weight_decay\"])\n", + "\n", + "model.compile(\n", + " loss=\"sparse_categorical_crossentropy\",\n", + " optimizer=optimizer,\n", + " metrics=[\"accuracy\", \"sparse_top_k_categorical_accuracy\"]\n", + ")\n", + "\n", + "\n", + "callbacks = [\n", + " EarlyStopping(patience=CONFIG[\"early_stop_patience\"],\n", + " restore_best_weights=True,\n", + " monitor='val_accuracy'),\n", + " ReduceLROnPlateau(factor=0.5,\n", + " patience=CONFIG[\"lr_patience\"],\n", + " verbose=1),\n", + "]\n" + ], + "metadata": { + "collapsed": true, + "id": "fXlZmUeOXPiQ" + }, + "execution_count": 9, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# ==============================================\n", + "# Training Execution\n", + "# ==============================================\n", + "print(\"\\nTraining model...\")\n", + "\n", + "train_dataset = tf.data.Dataset.from_generator(\n", + " #lambda: load_data_generator(\"train\", le),\n", + " lambda: load_data_generator(\"train\", le),\n", + "\n", + " output_signature=(\n", + " tf.TensorSpec(shape=(None, CONFIG[\"image_size\"][0], CONFIG[\"image_size\"][1], 3), dtype=tf.float32),\n", + " tf.TensorSpec(shape=(None,), dtype=tf.int32)\n", + " )\n", + ").prefetch(tf.data.AUTOTUNE)\n", + "\n", + "test_dataset = tf.data.Dataset.from_generator(\n", + " #lambda: load_data_generator(\"test\", le),\n", + " lambda: load_data_generator(\"test\", le),\n", + " output_signature=(\n", + " tf.TensorSpec(shape=(None, CONFIG[\"image_size\"][0], CONFIG[\"image_size\"][1], 3), dtype=tf.float32),\n", + " tf.TensorSpec(shape=(None,), dtype=tf.int32)\n", + " )\n", + ").prefetch(tf.data.AUTOTUNE)\n", + "\n", + "steps_per_epoch = len(train_labels) // CONFIG[\"batch_size\"]\n", + "validation_steps = len(test_labels) // CONFIG[\"batch_size\"]\n", + "\n", + "history = model.fit(\n", + " train_dataset,\n", + " validation_data=test_dataset,\n", + " epochs=CONFIG[\"epochs\"],\n", + " steps_per_epoch=steps_per_epoch,\n", + " validation_steps=validation_steps,\n", + " callbacks=callbacks,\n", + " class_weight=class_weights,\n", + " verbose=1\n", + ")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 118, + "referenced_widgets": [ + "681d23e34e334f1b83e6afa9903fe72c", + "12434f0d1a33473997d752900043cfbc", + "8ba7ea8bfcc84228b7a8b00d27aaec62", + "ef28e650217649a6a09b18a870ccf9f3", + "029419d39b774759a3672b810e5f283d", + "c0c317b2311149bd96a5ed0f5d737411", + "a3837d4e34fa44199c15eee100991c51", + "8be0aef085f14db98c01055ac6377419", + "eac5b5ff64d14810928db28d72f66398", + "8528453a25df4b33acba942a4a74d6ed", + "a69e2de4b71349b0ba962751fe63ee1b" + ] + }, + "collapsed": true, + "id": "HLnYP2aqXRpn", + "outputId": "1968fa2d-922e-46a3-f492-3934d1272c98" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "Training model...\n", + "Epoch 1/30\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "Loading train: 0it [00:00, ?it/s]" + ], + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "681d23e34e334f1b83e6afa9903fe72c" + } + }, + "metadata": {} + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\u001b[1m 22/339\u001b[0m \u001b[32m━\u001b[0m\u001b[37m━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[1m52:12\u001b[0m 10s/step - accuracy: 0.0668 - loss: 11.2268 - sparse_top_k_categorical_accuracy: 0.2142" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "# ==============================================\n", + "# Evaluation & Visualization\n", + "# ==============================================\n", + "plt.figure(figsize=(14, 5))\n", + "plt.subplot(1, 2, 1)\n", + "plt.plot(history.history['accuracy'], label='Train')\n", + "plt.plot(history.history['val_accuracy'], label='Validation')\n", + "plt.title('Model Accuracy')\n", + "plt.ylabel('Accuracy')\n", + "plt.xlabel('Epoch')\n", + "plt.legend()\n", + "\n", + "plt.subplot(1, 2, 2)\n", + "plt.plot(history.history['loss'], label='Train')\n", + "plt.plot(history.history['val_loss'], label='Validation')\n", + "plt.title('Model Loss')\n", + "plt.ylabel('Loss')\n", + "plt.xlabel('Epoch')\n", + "plt.legend()\n", + "plt.show()" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 645 + }, + "id": "9AS1u6snYYHy", + "outputId": "cf27c0a9-a78f-4d70-896d-a07ae233a7e7" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "error", + "ename": "KeyError", + "evalue": "'accuracy'", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m14\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhistory\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhistory\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'accuracy'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Train'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhistory\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhistory\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'val_accuracy'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'Validation'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtitle\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Model Accuracy'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyError\u001b[0m: 'accuracy'" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + "
" + ], + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAisAAAGyCAYAAAAlL4Q+AAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQAAHR5JREFUeJzt3X9s3VX9+PFX29FbiLRM59ptFico8nvDjdWChGAqTSDD/WGsYLa58EN0ElyjsjFYRXSdfIAsgcLCBPEPcFMCxLiliJWFADWL25qgbBAcuGls2VTaWbRl7fv7h1+qdd3YLW13bB+P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+8MV555ZXYtGlTrF69OpYuXTpyzwIAGLfy/p6Vurq62LdvX6xatSra29tj9uzZ0dzcPPCh2z179kRh4b8bqLKyMp566qlYtmxZnHvuuTFjxoy48cYb46abbhq5ZwEAjFt5f8/KseB7VgDgf8Mx/54VAICxJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkDStWmpqaYubMmVFSUhJVVVWxdevWo1q3YcOGKCgoiAULFgznYQGACSjvWNm4cWPU19dHQ0NDbN++PWbNmhW1tbXxxhtvHHHd66+/Ht/4xjfioosuGvZmAYCJJ+9Yufvuu+Paa6+NJUuWxJlnnhnr1q2LE044IR566KHDrunr64svfvGLcdttt8Upp5zynjYMAEwsecVKb29vbNu2LWpqav59B4WFUVNTE62trYdd953vfCemTp0aV1999VE9Tk9PT3R1dQ26AQATU16xsn///ujr64vy8vJB4+Xl5dHe3j7kmueeey4efPDBWL9+/VE/TmNjY5SVlQ3cKisr89kmADCOjOpPAx04cCAWLlwY69evjylTphz1uhUrVkRnZ+fAbe/evaO4SwAgZZPymTxlypQoKiqKjo6OQeMdHR1RUVFxyPzf//738frrr8f8+fMHxvr7+//1wJMmxcsvvxynnnrqIetyuVzkcrl8tgYAjFN5XVkpLi6OOXPmREtLy8BYf39/tLS0RHV19SHzTz/99HjxxRejra1t4HbFFVfEJZdcEm1tbd7eAQDeVV5XViIi6uvrY/HixTF37tyYN29erF27Nrq7u2PJkiUREbFo0aKYMWNGNDY2RklJSZx99tmD1p900kkREYeMAwAMJe9Yqauri3379sWqVauivb09Zs+eHc3NzQMfut2zZ08UFvpiXABgZBRkWZYd6028m66urigrK4vOzs4oLS091tsBAA5jNF6zXQIBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKSJFQAgaWIFAEiaWAEAkiZWAICkiRUAIGliBQBImlgBAJImVgCApIkVACBpYgUASJpYAQCSJlYAgKQNK1aamppi5syZUVJSElVVVbF169bDzl2/fn1cdNFFMXny5Jg8eXLU1NQccT4AwH/KO1Y2btwY9fX10dDQENu3b49Zs2ZFbW1tvPHGG0PO37JlS1x55ZXxzDPPRGtra1RWVsall14af/rTn97z5gGA8a8gy7IsnwVVVVVx/vnnx7333hsREf39/VFZWRk33HBDLF++/F3X9/X1xeTJk+Pee++NRYsWHdVjdnV1RVlZWXR2dkZpaWk+2wUAxtBovGbndWWlt7c3tm3bFjU1Nf++g8LCqKmpidbW1qO6j7feeivefvvteP/733/YOT09PdHV1TXoBgBMTHnFyv79+6Ovry/Ky8sHjZeXl0d7e/tR3cdNN90U06dPHxQ8/62xsTHKysoGbpWVlflsEwAYR8b0p4HWrFkTGzZsiCeeeCJKSkoOO2/FihXR2dk5cNu7d+8Y7hIASMmkfCZPmTIlioqKoqOjY9B4R0dHVFRUHHHtnXfeGWvWrIlf/vKXce655x5xbi6Xi1wul8/WAIBxKq8rK8XFxTFnzpxoaWkZGOvv74+Wlpaorq4+7Lo77rgjbr/99mhubo65c+cOf7cAwIST15WViIj6+vpYvHhxzJ07N+bNmxdr166N7u7uWLJkSURELFq0KGbMmBGNjY0REfH9738/Vq1aFY8++mjMnDlz4LMt73vf++J973vfCD4VAGA8yjtW6urqYt++fbFq1apob2+P2bNnR3Nz88CHbvfs2ROFhf++YHP//fdHb29vfO5znxt0Pw0NDfHtb3/7ve0eABj38v6elWPB96wAwP+GY/49KwAAY02sAABJEysAQNLECgCQNLECACRNrAAASRMrAEDSxAoAkDSxAgAkTawAAEkTKwBA0sQKAJA0sQIAJE2sAABJEysAQNLECgCQNLECACRNrAAASRMrAEDSxAoAkDSxAgAkTawAAEkTKwBA0sQKAJA0sQIAJE2sAABJEysAQNLECgCQNLECACRNrAAASRMrAEDSxAoAkDSxAgAkTawAAEkTKwBA0sQKAJA0sQIAJE2sAABJEysAQNLECgCQNLECACRNrAAASRMrAEDSxAoAkDSxAgAkTawAAEkTKwBA0sQKAJA0sQIAJE2sAABJEysAQNLECgCQNLECACRNrAAASRMrAEDSxAoAkDSxAgAkTawAAEkTKwBA0sQKAJA0sQIAJE2sAABJEysAQNLECgCQNLECACRNrAAASRtWrDQ1NcXMmTOjpKQkqqqqYuvWrUec/9Of/jROP/30KCkpiXPOOSc2b948rM0CABNP3rGycePGqK+vj4aGhti+fXvMmjUramtr44033hhy/gsvvBBXXnllXH311bFjx45YsGBBLFiwIH7729++580DAONfQZZlWT4Lqqqq4vzzz4977703IiL6+/ujsrIybrjhhli+fPkh8+vq6qK7uzt+/vOfD4x98pOfjNmzZ8e6deuO6jG7urqirKwsOjs7o7S0NJ/tAgBjaDResyflM7m3tze2bdsWK1asGBgrLCyMmpqaaG1tHXJNa2tr1NfXDxqrra2NJ5988rCP09PTEz09PQN/7uzsjIh//QsAANL1zmt1ntdCjiivWNm/f3/09fVFeXn5oPHy8vLYtWvXkGva29uHnN/e3n7Yx2lsbIzbbrvt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2Pu3LljsdVxL9+zOP300+PFF1+Mtra2gdsVV1wRl1xySbS1tUVlZeVYbn9cGc7fiwsvvDBeffXVgWCMiHjllVdi2rRpQmWYhnMOb7311iFB8k5AZn4l3pgZsdfr/D77Ozo2bNiQ5XK57OGHH85eeuml7LrrrstOOumkrL29PcuyLFu4cGG2fPnygfnPP/98NmnSpOzOO+/Mdu7cmTU0NPjR5RGQ7zmsWbMmKy4uzh577LHsz3/+88DtwIEDx+opjBv5nsV/89NAIyffs9izZ0924oknZl/72teyl19+Ofv5z3+eTZ06Nfvud797rJ7CuJDvOTQ0NGQnnnhi9uMf/zjbvXt39otf/CI79dRTs89//vPH6imMCwcOHMh27NiR7dixI4uI7O6778527NiR/eEPf8iyLMuWL1+eLVy4cGD+Oz+6/M1vfjPbuXNn1tTU9L/7o8tZlmX33HNPdvLJJ2fFxcXZvHnzsl//+tcD/+ziiy/OFi9ePGj+T37yk+y0007LiouLs7POOivbtGnTGO94fMrnHD784Q9nEXHIraGhYew3Pg7l+3fiP4mVkZXvWbzwwgtZVVVVlsvlslNOOSX73ve+lx08eHCMdz3+5HMOb7/9dvbtb387O/XUU7OSkpKssrIy++pXv5r97W9/G/uNjyPPPPPMkP/ff+ff/eLFi7OLL774kDWzZ8/OiouLs1NOOSX74Q9/mPfjFmSZ62EAQLqO+WdWAACORKwAAEkTKwBA0sQKAJA0sQIAJE2sAABJEysAQNLECgCQNLECACRNrAAASRMrAEDSxAoAkLT/B2bvhUyp908MAAAAAElFTkSuQmCC\n" + }, + "metadata": {} + } + ] + }, + { + "cell_type": "code", + "source": [ + "# Final evaluation\n", + "results = model.evaluate(test_dataset, verbose=0)\n", + "print(f\"\\nFinal Metrics:\")\n", + "print(f\"Test Accuracy: {results[1]*100:.2f}%\")\n", + "print(f\"Top-3 Accuracy: {results[2]*100:.2f}%\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "QGp4IlF0XU1f", + "outputId": "66bfcaa4-0b2e-4690-dc75-71ed57757ef6" + }, + "execution_count": null, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "Final Metrics:\n", + "Test Accuracy: 86.50%\n", + "Top-3 Accuracy: 99.60%\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "model.save('PDD_completemodel.h5') # Save as HDF5 format for easy loading\n", + "\n", + "print(\"Model training and saving complete.\")" + ], + "metadata": { + "id": "dy_M7QHwXW4Z" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file