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