{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "mmocr.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3",
      "language": "python"
    },
    "language_info": {
      "name": "python",
      "version": "3.8.5"
    },
    "accelerator": "GPU",
    "widgets": {
      "application/vnd.jupyter.widget-state+json": {
        "9922c33a131f41cfac84af47b5e5981c": {
          "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_9be2b6bd525c4b31be2d386b37d573b6",
              "IPY_MODEL_edb36ab14ab44bc98983d447c1cb150a",
              "IPY_MODEL_46dafdb514c049a7bb18ada61c7dee49"
            ],
            "layout": "IPY_MODEL_c267e0b248154c028a93390ea187ef7f"
          }
        },
        "9be2b6bd525c4b31be2d386b37d573b6": {
          "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_e2bc0c96bdee4d9c981f71c1001ec637",
            "placeholder": "​",
            "style": "IPY_MODEL_b735ff5dcd114345bc89b462bc276759",
            "value": "100%"
          }
        },
        "edb36ab14ab44bc98983d447c1cb150a": {
          "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_5ef02d42f1d34f6a81dbbe8b4fbd7ffc",
            "max": 229956710,
            "min": 0,
            "orientation": "horizontal",
            "style": "IPY_MODEL_1712f2cbff4a4cbdaaa238d89905ec21",
            "value": 229956710
          }
        },
        "46dafdb514c049a7bb18ada61c7dee49": {
          "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_1e43262b71ef45f1a5535d78594a0235",
            "placeholder": "​",
            "style": "IPY_MODEL_5e7c98e0dbc4463c81b15c56c48ba1cf",
            "value": " 219M/219M [00:30&lt;00:00, 7.18MB/s]"
          }
        },
        "c267e0b248154c028a93390ea187ef7f": {
          "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
          }
        },
        "e2bc0c96bdee4d9c981f71c1001ec637": {
          "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
          }
        },
        "b735ff5dcd114345bc89b462bc276759": {
          "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": ""
          }
        },
        "5ef02d42f1d34f6a81dbbe8b4fbd7ffc": {
          "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
          }
        },
        "1712f2cbff4a4cbdaaa238d89905ec21": {
          "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": ""
          }
        },
        "1e43262b71ef45f1a5535d78594a0235": {
          "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
          }
        },
        "5e7c98e0dbc4463c81b15c56c48ba1cf": {
          "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": ""
          }
        },
        "0cfa2ece94314ed186b834646623852a": {
          "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_5f5f9ed460404047bfda112283b4f159",
              "IPY_MODEL_7c6bbe29702444b9a6adfef0d11f2a5c",
              "IPY_MODEL_b48490fd9f0d4cc38acd6c0ccf57b68a"
            ],
            "layout": "IPY_MODEL_6f6240bf87a3442dbce39764c97dbd8f"
          }
        },
        "5f5f9ed460404047bfda112283b4f159": {
          "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_b3adfe1225ac4497ae818e5a78132c34",
            "placeholder": "​",
            "style": "IPY_MODEL_c36a853d851249c49c63599219f73c38",
            "value": "100%"
          }
        },
        "7c6bbe29702444b9a6adfef0d11f2a5c": {
          "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_a4d14f12345b4956a7861d5c54a51fad",
            "max": 145703066,
            "min": 0,
            "orientation": "horizontal",
            "style": "IPY_MODEL_592582312a0c4ddfa40e55026fd51e3f",
            "value": 145703066
          }
        },
        "b48490fd9f0d4cc38acd6c0ccf57b68a": {
          "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_3947416ef2c245d197e7b254d0d513b8",
            "placeholder": "​",
            "style": "IPY_MODEL_dc187713177749469e49eed82769df1c",
            "value": " 139M/139M [00:22&lt;00:00, 5.26MB/s]"
          }
        },
        "6f6240bf87a3442dbce39764c97dbd8f": {
          "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
          }
        },
        "b3adfe1225ac4497ae818e5a78132c34": {
          "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
          }
        },
        "c36a853d851249c49c63599219f73c38": {
          "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": ""
          }
        },
        "a4d14f12345b4956a7861d5c54a51fad": {
          "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
          }
        },
        "592582312a0c4ddfa40e55026fd51e3f": {
          "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": ""
          }
        },
        "3947416ef2c245d197e7b254d0d513b8": {
          "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
          }
        },
        "dc187713177749469e49eed82769df1c": {
          "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": ""
          }
        },
        "cd5e91174a6441ad9d7b8c0a05f18f60": {
          "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_7f0e77d508574ec485243125375cedfb",
              "IPY_MODEL_45cc8c746da74a8fbc32d5bdfb1e350e",
              "IPY_MODEL_4153b5f7dd474c079cb9b38f79d515d8"
            ],
            "layout": "IPY_MODEL_31a4e677ff8849e8b9050ece3e516413"
          }
        },
        "7f0e77d508574ec485243125375cedfb": {
          "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_3761f71633874fd39205adb5fafe98fe",
            "placeholder": "​",
            "style": "IPY_MODEL_12377605aaa24988b2075e88c5fd77cc",
            "value": "100%"
          }
        },
        "45cc8c746da74a8fbc32d5bdfb1e350e": {
          "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_39bb6e08d13c4979a731ca6c8a8e5668",
            "max": 19256299,
            "min": 0,
            "orientation": "horizontal",
            "style": "IPY_MODEL_97992daf80b5487595712d675d17a9da",
            "value": 19256299
          }
        },
        "4153b5f7dd474c079cb9b38f79d515d8": {
          "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_f1d3884457d8426db6a59bda51249444",
            "placeholder": "​",
            "style": "IPY_MODEL_a2220a97632e449e95ff559987245b0b",
            "value": " 18.4M/18.4M [00:02&lt;00:00, 8.57MB/s]"
          }
        },
        "31a4e677ff8849e8b9050ece3e516413": {
          "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
          }
        },
        "3761f71633874fd39205adb5fafe98fe": {
          "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
          }
        },
        "12377605aaa24988b2075e88c5fd77cc": {
          "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": ""
          }
        },
        "39bb6e08d13c4979a731ca6c8a8e5668": {
          "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
          }
        },
        "97992daf80b5487595712d675d17a9da": {
          "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": ""
          }
        },
        "f1d3884457d8426db6a59bda51249444": {
          "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
          }
        },
        "a2220a97632e449e95ff559987245b0b": {
          "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": "markdown",
      "source": [
        "# MMOCR Tutorial\n",
        "\n",
        "Welcome to MMOCR! This is the official colab tutorial for using MMOCR. In this tutorial, you will learn how to\n",
        "\n",
        "- Perform inference with a pretrained text recognizer\n",
        "- Perform inference with a pretrained text detector\n",
        "- Perform end-to-end OCR with pretrained recognizer and detector\n",
        "- Combine OCR with downstream tasks\n",
        "- Perform inference with a pretrained Key Information Extraction (KIE) model\n",
        "- Train a text recognizer with a toy dataset\n",
        "\n",
        "Let's start!"
      ],
      "metadata": {
        "id": "jU9T31gbQmvs"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Install MMOCR"
      ],
      "metadata": {
        "id": "Sfvz1sywQ9_4"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "When installing dependencies for mmocr, please ensure that all the dependency versions are compatible with each other. For instance, if CUDA 10.1 is installed, then the Pytorch version must be compatible with cu10.1. Please see [getting_started.md](docs/getting_started.md) for more details. "
      ],
      "metadata": {
        "id": "q3fZP1LspEUp"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "source": [
        "%cd .."
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "rB3qciTXpEUq",
        "outputId": "8d40f08d-47d5-48d4-dd2a-e43d5ae67529"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Check PyTorch version"
      ],
      "metadata": {
        "id": "mSkZOdrMpEUr"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "source": [
        "!pip show torch\n"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Name: torch\n",
            "Version: 1.10.0+cu111\n",
            "Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration\n",
            "Home-page: https://pytorch.org/\n",
            "Author: PyTorch Team\n",
            "Author-email: packages@pytorch.org\n",
            "License: BSD-3\n",
            "Location: /usr/local/lib/python3.7/dist-packages\n",
            "Requires: typing-extensions\n",
            "Required-by: torchvision, torchtext, torchaudio, fastai\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "2DBpcKj2RDfu",
        "outputId": "68295988-9769-4667-bc14-dc308a61d69d"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Install Dependencies "
      ],
      "metadata": {
        "id": "Tw7u_baQpEUs"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "source": [
        "# Install mmcv-full thus we could use CUDA operators\n",
        "!pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.10.0/index.html\n",
        "\n",
        "# Install mmdetection\n",
        "!pip install mmdet\n",
        "\n",
        "# Install mmocr\n",
        "!git clone https://github.com/open-mmlab/mmocr.git\n",
        "%cd mmocr\n",
        "!pip install -r requirements.txt\n",
        "!pip install -v -e ."
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Looking in links: https://download.openmmlab.com/mmcv/dist/cu111/torch1.10.0/index.html\n",
            "Collecting mmcv-full\n",
            "  Downloading https://download.openmmlab.com/mmcv/dist/cu111/torch1.10.0/mmcv_full-1.4.6-cp37-cp37m-manylinux1_x86_64.whl (46.0 MB)\n",
            "\u001b[K     |████████████████████████████████| 46.0 MB 50.2 MB/s \n",
            "\u001b[?25hCollecting yapf\n",
            "  Downloading yapf-0.32.0-py2.py3-none-any.whl (190 kB)\n",
            "\u001b[K     |████████████████████████████████| 190 kB 3.9 MB/s \n",
            "\u001b[?25hRequirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (7.1.2)\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (1.21.5)\n",
            "Collecting addict\n",
            "  Downloading addict-2.4.0-py3-none-any.whl (3.8 kB)\n",
            "Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (3.13)\n",
            "Requirement already satisfied: opencv-python>=3 in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (4.1.2.30)\n",
            "Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (21.3)\n",
            "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->mmcv-full) (3.0.7)\n",
            "Installing collected packages: yapf, addict, mmcv-full\n",
            "Successfully installed addict-2.4.0 mmcv-full-1.4.6 yapf-0.32.0\n",
            "Collecting mmdet\n",
            "  Downloading mmdet-2.22.0-py3-none-any.whl (1.3 MB)\n",
            "\u001b[K     |████████████████████████████████| 1.3 MB 4.1 MB/s \n",
            "\u001b[?25hCollecting terminaltables\n",
            "  Downloading terminaltables-3.1.10-py2.py3-none-any.whl (15 kB)\n",
            "Requirement already satisfied: pycocotools in /usr/local/lib/python3.7/dist-packages (from mmdet) (2.0.4)\n",
            "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from mmdet) (1.15.0)\n",
            "Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from mmdet) (3.2.2)\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmdet) (1.21.5)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet) (0.11.0)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet) (1.3.2)\n",
            "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet) (2.8.2)\n",
            "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet) (3.0.7)\n",
            "Installing collected packages: terminaltables, mmdet\n",
            "Successfully installed mmdet-2.22.0 terminaltables-3.1.10\n",
            "Cloning into 'mmocr'...\n",
            "remote: Enumerating objects: 5670, done.\u001b[K\n",
            "remote: Counting objects: 100% (560/560), done.\u001b[K\n",
            "remote: Compressing objects: 100% (375/375), done.\u001b[K\n",
            "remote: Total 5670 (delta 252), reused 381 (delta 177), pack-reused 5110\u001b[K\n",
            "Receiving objects: 100% (5670/5670), 12.35 MiB | 14.10 MiB/s, done.\n",
            "Resolving deltas: 100% (3360/3360), done.\n",
            "/mmocr\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from -r requirements/build.txt (line 2)) (1.21.5)\n",
            "Collecting pyclipper\n",
            "  Downloading pyclipper-1.3.0.post2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (603 kB)\n",
            "\u001b[K     |████████████████████████████████| 603 kB 4.4 MB/s \n",
            "\u001b[?25hRequirement already satisfied: torch>=1.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements/build.txt (line 4)) (1.10.0+cu111)\n",
            "Collecting albumentations>=1.1.0\n",
            "  Downloading albumentations-1.1.0-py3-none-any.whl (102 kB)\n",
            "\u001b[K     |████████████████████████████████| 102 kB 49.2 MB/s \n",
            "\u001b[?25hRequirement already satisfied: imgaug in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 1)) (0.2.9)\n",
            "Collecting lanms-neo==1.0.2\n",
            "  Downloading lanms_neo-1.0.2.tar.gz (39 kB)\n",
            "  Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
            "  Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
            "    Preparing wheel metadata ... \u001b[?25l\u001b[?25hdone\n",
            "Requirement already satisfied: lmdb in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 3)) (0.99)\n",
            "Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 4)) (3.2.2)\n",
            "Requirement already satisfied: numba>=0.45.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 5)) (0.51.2)\n",
            "Collecting opencv-python-headless<=4.5.4.60\n",
            "  Downloading opencv_python_headless-4.5.4.60-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (47.6 MB)\n",
            "\u001b[K     |████████████████████████████████| 47.6 MB 2.2 MB/s \n",
            "\u001b[?25hCollecting pycocotools<=2.0.2\n",
            "  Downloading pycocotools-2.0.2.tar.gz (23 kB)\n",
            "Collecting rapidfuzz\n",
            "  Downloading rapidfuzz-2.0.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB)\n",
            "\u001b[K     |████████████████████████████████| 1.6 MB 38.8 MB/s \n",
            "\u001b[?25hRequirement already satisfied: scikit-image in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 11)) (0.18.3)\n",
            "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 12)) (1.15.0)\n",
            "Requirement already satisfied: terminaltables in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 13)) (3.1.10)\n",
            "Collecting asynctest\n",
            "  Downloading asynctest-0.13.0-py3-none-any.whl (26 kB)\n",
            "Collecting codecov\n",
            "  Downloading codecov-2.1.12-py2.py3-none-any.whl (16 kB)\n",
            "Collecting flake8\n",
            "  Downloading flake8-4.0.1-py2.py3-none-any.whl (64 kB)\n",
            "\u001b[K     |████████████████████████████████| 64 kB 2.6 MB/s \n",
            "\u001b[?25hCollecting isort\n",
            "  Downloading isort-5.10.1-py3-none-any.whl (103 kB)\n",
            "\u001b[K     |████████████████████████████████| 103 kB 45.2 MB/s \n",
            "\u001b[?25hCollecting kwarray\n",
            "  Downloading kwarray-0.6.0-py3-none-any.whl (78 kB)\n",
            "\u001b[K     |████████████████████████████████| 78 kB 7.4 MB/s \n",
            "\u001b[?25hRequirement already satisfied: pytest in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 7)) (3.6.4)\n",
            "Collecting pytest-cov\n",
            "  Downloading pytest_cov-3.0.0-py3-none-any.whl (20 kB)\n",
            "Collecting pytest-runner\n",
            "  Downloading pytest_runner-6.0.0-py3-none-any.whl (7.2 kB)\n",
            "Collecting ubelt\n",
            "  Downloading ubelt-1.0.1-py3-none-any.whl (151 kB)\n",
            "\u001b[K     |████████████████████████████████| 151 kB 36.4 MB/s \n",
            "\u001b[?25hCollecting xdoctest>=0.10.0\n",
            "  Downloading xdoctest-0.15.10-py3-none-any.whl (116 kB)\n",
            "\u001b[K     |████████████████████████████████| 116 kB 27.1 MB/s \n",
            "\u001b[?25hRequirement already satisfied: yapf in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 12)) (0.32.0)\n",
            "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch>=1.1->-r requirements/build.txt (line 4)) (3.10.0.2)\n",
            "Requirement already satisfied: PyYAML in /usr/local/lib/python3.7/dist-packages (from albumentations>=1.1.0->-r requirements/optional.txt (line 1)) (3.13)\n",
            "Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from albumentations>=1.1.0->-r requirements/optional.txt (line 1)) (1.4.1)\n",
            "Collecting qudida>=0.0.4\n",
            "  Downloading qudida-0.0.4-py3-none-any.whl (3.5 kB)\n",
            "Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from numba>=0.45.1->-r requirements/runtime.txt (line 5)) (57.4.0)\n",
            "Requirement already satisfied: llvmlite<0.35,>=0.34.0.dev0 in /usr/local/lib/python3.7/dist-packages (from numba>=0.45.1->-r requirements/runtime.txt (line 5)) (0.34.0)\n",
            "Requirement already satisfied: cython>=0.27.3 in /usr/local/lib/python3.7/dist-packages (from pycocotools<=2.0.2->-r requirements/runtime.txt (line 9)) (0.29.28)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->-r requirements/runtime.txt (line 4)) (1.3.2)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->-r requirements/runtime.txt (line 4)) (0.11.0)\n",
            "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->-r requirements/runtime.txt (line 4)) (2.8.2)\n",
            "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->-r requirements/runtime.txt (line 4)) (3.0.7)\n",
            "Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from scikit-image->-r requirements/runtime.txt (line 11)) (1.2.0)\n",
            "Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->-r requirements/runtime.txt (line 11)) (2.6.3)\n",
            "Requirement already satisfied: pillow!=7.1.0,!=7.1.1,>=4.3.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->-r requirements/runtime.txt (line 11)) (7.1.2)\n",
            "Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.7/dist-packages (from scikit-image->-r requirements/runtime.txt (line 11)) (2021.11.2)\n",
            "Requirement already satisfied: imageio>=2.3.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->-r requirements/runtime.txt (line 11)) (2.4.1)\n",
            "Requirement already satisfied: scikit-learn>=0.19.1 in /usr/local/lib/python3.7/dist-packages (from qudida>=0.0.4->albumentations>=1.1.0->-r requirements/optional.txt (line 1)) (1.0.2)\n",
            "Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.19.1->qudida>=0.0.4->albumentations>=1.1.0->-r requirements/optional.txt (line 1)) (1.1.0)\n",
            "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.19.1->qudida>=0.0.4->albumentations>=1.1.0->-r requirements/optional.txt (line 1)) (3.1.0)\n",
            "Requirement already satisfied: opencv-python in /usr/local/lib/python3.7/dist-packages (from imgaug->-r requirements/runtime.txt (line 1)) (4.1.2.30)\n",
            "Requirement already satisfied: Shapely in /usr/local/lib/python3.7/dist-packages (from imgaug->-r requirements/runtime.txt (line 1)) (1.8.1.post1)\n",
            "Collecting jarowinkler<1.1.0,>=1.0.2\n",
            "  Downloading jarowinkler-1.0.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (103 kB)\n",
            "\u001b[K     |████████████████████████████████| 103 kB 14.3 MB/s \n",
            "\u001b[?25hRequirement already satisfied: coverage in /usr/local/lib/python3.7/dist-packages (from codecov->-r requirements/tests.txt (line 2)) (3.7.1)\n",
            "Requirement already satisfied: requests>=2.7.9 in /usr/local/lib/python3.7/dist-packages (from codecov->-r requirements/tests.txt (line 2)) (2.23.0)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.7.9->codecov->-r requirements/tests.txt (line 2)) (2021.10.8)\n",
            "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.7.9->codecov->-r requirements/tests.txt (line 2)) (1.24.3)\n",
            "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.7.9->codecov->-r requirements/tests.txt (line 2)) (3.0.4)\n",
            "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.7.9->codecov->-r requirements/tests.txt (line 2)) (2.10)\n",
            "Collecting importlib-metadata<4.3\n",
            "  Downloading importlib_metadata-4.2.0-py3-none-any.whl (16 kB)\n",
            "Collecting mccabe<0.7.0,>=0.6.0\n",
            "  Downloading mccabe-0.6.1-py2.py3-none-any.whl (8.6 kB)\n",
            "Collecting pyflakes<2.5.0,>=2.4.0\n",
            "  Downloading pyflakes-2.4.0-py2.py3-none-any.whl (69 kB)\n",
            "\u001b[K     |████████████████████████████████| 69 kB 7.6 MB/s \n",
            "\u001b[?25hCollecting pycodestyle<2.9.0,>=2.8.0\n",
            "  Downloading pycodestyle-2.8.0-py2.py3-none-any.whl (42 kB)\n",
            "\u001b[K     |████████████████████████████████| 42 kB 860 kB/s \n",
            "\u001b[?25hRequirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata<4.3->flake8->-r requirements/tests.txt (line 3)) (3.7.0)\n",
            "Requirement already satisfied: more-itertools>=4.0.0 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 7)) (8.12.0)\n",
            "Requirement already satisfied: atomicwrites>=1.0 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 7)) (1.4.0)\n",
            "Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 7)) (21.4.0)\n",
            "Requirement already satisfied: pluggy<0.8,>=0.5 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 7)) (0.7.1)\n",
            "Requirement already satisfied: py>=1.5.0 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 7)) (1.11.0)\n",
            "Collecting pytest\n",
            "  Downloading pytest-7.1.1-py3-none-any.whl (297 kB)\n",
            "\u001b[K     |████████████████████████████████| 297 kB 51.4 MB/s \n",
            "\u001b[?25hCollecting coverage[toml]>=5.2.1\n",
            "  Downloading coverage-6.3.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (207 kB)\n",
            "\u001b[K     |████████████████████████████████| 207 kB 48.1 MB/s \n",
            "\u001b[?25hRequirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 7)) (21.3)\n",
            "Requirement already satisfied: tomli>=1.0.0 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 7)) (2.0.1)\n",
            "Requirement already satisfied: iniconfig in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 7)) (1.1.1)\n",
            "Collecting pytest\n",
            "  Downloading pytest-7.1.0-py3-none-any.whl (297 kB)\n",
            "\u001b[K     |████████████████████████████████| 297 kB 32.1 MB/s \n",
            "\u001b[?25h  Downloading pytest-7.0.1-py3-none-any.whl (296 kB)\n",
            "\u001b[K     |████████████████████████████████| 296 kB 51.9 MB/s \n",
            "\u001b[?25h  Downloading pytest-7.0.0-py3-none-any.whl (296 kB)\n",
            "\u001b[K     |████████████████████████████████| 296 kB 51.2 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.2.5-py3-none-any.whl (280 kB)\n",
            "\u001b[K     |████████████████████████████████| 280 kB 50.5 MB/s \n",
            "\u001b[?25hCollecting toml\n",
            "  Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)\n",
            "Collecting pytest\n",
            "  Downloading pytest-6.2.4-py3-none-any.whl (280 kB)\n",
            "\u001b[K     |████████████████████████████████| 280 kB 50.2 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.2.3-py3-none-any.whl (280 kB)\n",
            "\u001b[K     |████████████████████████████████| 280 kB 52.3 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.2.2-py3-none-any.whl (280 kB)\n",
            "\u001b[K     |████████████████████████████████| 280 kB 33.3 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.2.1-py3-none-any.whl (279 kB)\n",
            "\u001b[K     |████████████████████████████████| 279 kB 55.5 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.2.0-py3-none-any.whl (279 kB)\n",
            "\u001b[K     |████████████████████████████████| 279 kB 49.7 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.1.2-py3-none-any.whl (272 kB)\n",
            "\u001b[K     |████████████████████████████████| 272 kB 52.8 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.1.1-py3-none-any.whl (272 kB)\n",
            "\u001b[K     |████████████████████████████████| 272 kB 56.1 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.1.0-py3-none-any.whl (272 kB)\n",
            "\u001b[K     |████████████████████████████████| 272 kB 46.7 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.0.2-py3-none-any.whl (270 kB)\n",
            "\u001b[K     |████████████████████████████████| 270 kB 50.1 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.0.1-py3-none-any.whl (270 kB)\n",
            "\u001b[K     |████████████████████████████████| 270 kB 48.2 MB/s \n",
            "\u001b[?25h  Downloading pytest-6.0.0-py3-none-any.whl (270 kB)\n",
            "\u001b[K     |████████████████████████████████| 270 kB 48.1 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.4.3-py3-none-any.whl (248 kB)\n",
            "\u001b[K     |████████████████████████████████| 248 kB 39.4 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.4.2-py3-none-any.whl (247 kB)\n",
            "\u001b[K     |████████████████████████████████| 247 kB 50.6 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.4.1-py3-none-any.whl (246 kB)\n",
            "\u001b[K     |████████████████████████████████| 246 kB 49.3 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.4.0-py3-none-any.whl (247 kB)\n",
            "\u001b[K     |████████████████████████████████| 247 kB 53.6 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.3.5-py3-none-any.whl (235 kB)\n",
            "\u001b[K     |████████████████████████████████| 235 kB 48.2 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.3.4-py3-none-any.whl (235 kB)\n",
            "\u001b[K     |████████████████████████████████| 235 kB 45.6 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.3.3-py3-none-any.whl (235 kB)\n",
            "\u001b[K     |████████████████████████████████| 235 kB 48.5 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.3.2-py3-none-any.whl (234 kB)\n",
            "\u001b[K     |████████████████████████████████| 234 kB 49.2 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.3.1-py3-none-any.whl (233 kB)\n",
            "\u001b[K     |████████████████████████████████| 233 kB 44.0 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.3.0-py3-none-any.whl (233 kB)\n",
            "\u001b[K     |████████████████████████████████| 233 kB 52.1 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.2.4-py3-none-any.whl (227 kB)\n",
            "\u001b[K     |████████████████████████████████| 227 kB 51.8 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.2.3-py3-none-any.whl (227 kB)\n",
            "\u001b[K     |████████████████████████████████| 227 kB 40.6 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.2.2-py3-none-any.whl (227 kB)\n",
            "\u001b[K     |████████████████████████████████| 227 kB 46.4 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.2.1-py3-none-any.whl (226 kB)\n",
            "\u001b[K     |████████████████████████████████| 226 kB 52.0 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.2.0-py3-none-any.whl (226 kB)\n",
            "\u001b[K     |████████████████████████████████| 226 kB 52.4 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.1.3-py3-none-any.whl (224 kB)\n",
            "\u001b[K     |████████████████████████████████| 224 kB 46.2 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.1.2-py3-none-any.whl (224 kB)\n",
            "\u001b[K     |████████████████████████████████| 224 kB 51.8 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.1.1-py3-none-any.whl (223 kB)\n",
            "\u001b[K     |████████████████████████████████| 223 kB 39.0 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.1.0-py3-none-any.whl (223 kB)\n",
            "\u001b[K     |████████████████████████████████| 223 kB 55.1 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.0.1-py3-none-any.whl (221 kB)\n",
            "\u001b[K     |████████████████████████████████| 221 kB 51.1 MB/s \n",
            "\u001b[?25h  Downloading pytest-5.0.0-py3-none-any.whl (221 kB)\n",
            "\u001b[K     |████████████████████████████████| 221 kB 49.6 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.11-py2.py3-none-any.whl (231 kB)\n",
            "\u001b[K     |████████████████████████████████| 231 kB 53.4 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.10-py2.py3-none-any.whl (231 kB)\n",
            "\u001b[K     |████████████████████████████████| 231 kB 50.6 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.9-py2.py3-none-any.whl (231 kB)\n",
            "\u001b[K     |████████████████████████████████| 231 kB 40.0 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.8-py2.py3-none-any.whl (230 kB)\n",
            "\u001b[K     |████████████████████████████████| 230 kB 54.2 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.7-py2.py3-none-any.whl (230 kB)\n",
            "\u001b[K     |████████████████████████████████| 230 kB 51.7 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.6-py2.py3-none-any.whl (230 kB)\n",
            "\u001b[K     |████████████████████████████████| 230 kB 52.7 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.5-py2.py3-none-any.whl (230 kB)\n",
            "\u001b[K     |████████████████████████████████| 230 kB 47.7 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.4-py2.py3-none-any.whl (229 kB)\n",
            "\u001b[K     |████████████████████████████████| 229 kB 48.9 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.3-py2.py3-none-any.whl (229 kB)\n",
            "\u001b[K     |████████████████████████████████| 229 kB 54.7 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.2-py2.py3-none-any.whl (229 kB)\n",
            "\u001b[K     |████████████████████████████████| 229 kB 50.2 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.1-py2.py3-none-any.whl (229 kB)\n",
            "\u001b[K     |████████████████████████████████| 229 kB 51.7 MB/s \n",
            "\u001b[?25h  Downloading pytest-4.6.0-py2.py3-none-any.whl (229 kB)\n",
            "\u001b[K     |████████████████████████████████| 229 kB 52.2 MB/s \n",
            "\u001b[?25hINFO: pip is looking at multiple versions of pytest-cov to determine which version is compatible with other requirements. This could take a while.\n",
            "Collecting pytest-cov\n",
            "  Downloading pytest_cov-2.12.1-py2.py3-none-any.whl (20 kB)\n",
            "  Downloading pytest_cov-2.12.0-py2.py3-none-any.whl (20 kB)\n",
            "  Downloading pytest_cov-2.11.1-py2.py3-none-any.whl (20 kB)\n",
            "  Downloading pytest_cov-2.11.0-py2.py3-none-any.whl (20 kB)\n",
            "  Downloading pytest_cov-2.10.1-py2.py3-none-any.whl (19 kB)\n",
            "  Downloading pytest_cov-2.10.0-py2.py3-none-any.whl (19 kB)\n",
            "  Downloading pytest_cov-2.9.0-py2.py3-none-any.whl (19 kB)\n",
            "Collecting ordered-set\n",
            "  Downloading ordered_set-4.1.0-py3-none-any.whl (7.6 kB)\n",
            "Building wheels for collected packages: lanms-neo, pycocotools\n",
            "  Building wheel for lanms-neo (PEP 517) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for lanms-neo: filename=lanms_neo-1.0.2-cp37-cp37m-linux_x86_64.whl size=107259 sha256=3e542a5f84605022e07797cdf0f3920886b8691eb51761e88efb22698aeafa1a\n",
            "  Stored in directory: /root/.cache/pip/wheels/09/7b/5e/1e4d24a8f94c1116afa284ce2968ef2f72b986a5457164b340\n",
            "  Building wheel for pycocotools (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for pycocotools: filename=pycocotools-2.0.2-cp37-cp37m-linux_x86_64.whl size=264430 sha256=07b5f1105f875f05483590366fdf06fcecbf6b6f2ca974d8fd53dea538a3b979\n",
            "  Stored in directory: /root/.cache/pip/wheels/bc/cf/1b/e95c99c5f9d1648be3f500ca55e7ce55f24818b0f48336adaf\n",
            "Successfully built lanms-neo pycocotools\n",
            "Installing collected packages: ordered-set, opencv-python-headless, ubelt, qudida, pyflakes, pycodestyle, mccabe, jarowinkler, importlib-metadata, coverage, xdoctest, rapidfuzz, pytest-runner, pytest-cov, pycocotools, pyclipper, lanms-neo, kwarray, isort, flake8, codecov, asynctest, albumentations\n",
            "  Attempting uninstall: importlib-metadata\n",
            "    Found existing installation: importlib-metadata 4.11.2\n",
            "    Uninstalling importlib-metadata-4.11.2:\n",
            "      Successfully uninstalled importlib-metadata-4.11.2\n",
            "  Attempting uninstall: coverage\n",
            "    Found existing installation: coverage 3.7.1\n",
            "    Uninstalling coverage-3.7.1:\n",
            "      Successfully uninstalled coverage-3.7.1\n",
            "  Attempting uninstall: pycocotools\n",
            "    Found existing installation: pycocotools 2.0.4\n",
            "    Uninstalling pycocotools-2.0.4:\n",
            "      Successfully uninstalled pycocotools-2.0.4\n",
            "  Attempting uninstall: albumentations\n",
            "    Found existing installation: albumentations 0.1.12\n",
            "    Uninstalling albumentations-0.1.12:\n",
            "      Successfully uninstalled albumentations-0.1.12\n",
            "\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",
            "markdown 3.3.6 requires importlib-metadata>=4.4; python_version < \"3.10\", but you have importlib-metadata 4.2.0 which is incompatible.\n",
            "datascience 0.10.6 requires coverage==3.7.1, but you have coverage 6.3.2 which is incompatible.\n",
            "datascience 0.10.6 requires folium==0.2.1, but you have folium 0.8.3 which is incompatible.\n",
            "coveralls 0.5 requires coverage<3.999,>=3.6, but you have coverage 6.3.2 which is incompatible.\u001b[0m\n",
            "Successfully installed albumentations-1.1.0 asynctest-0.13.0 codecov-2.1.12 coverage-6.3.2 flake8-4.0.1 importlib-metadata-4.2.0 isort-5.10.1 jarowinkler-1.0.2 kwarray-0.6.0 lanms-neo-1.0.2 mccabe-0.6.1 opencv-python-headless-4.5.4.60 ordered-set-4.1.0 pyclipper-1.3.0.post2 pycocotools-2.0.2 pycodestyle-2.8.0 pyflakes-2.4.0 pytest-cov-2.9.0 pytest-runner-6.0.0 qudida-0.0.4 rapidfuzz-2.0.7 ubelt-1.0.1 xdoctest-0.15.10\n",
            "Using pip 21.1.3 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)\n",
            "Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local/lib/python3.7/dist-packages\n",
            "sysconfig: /usr/lib/python3.7/site-packages\n",
            "Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local/lib/python3.7/dist-packages\n",
            "sysconfig: /usr/lib/python3.7/site-packages\n",
            "Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local/include/python3.7/UNKNOWN\n",
            "sysconfig: /usr/include/python3.7m/UNKNOWN\n",
            "Value for scheme.scripts does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local/bin\n",
            "sysconfig: /usr/bin\n",
            "Value for scheme.data does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local\n",
            "sysconfig: /usr\n",
            "Additional context:\n",
            "user = False\n",
            "home = None\n",
            "root = None\n",
            "prefix = None\n",
            "Non-user install because site-packages writeable\n",
            "Created temporary directory: /tmp/pip-ephem-wheel-cache-m7z_fdwx\n",
            "Created temporary directory: /tmp/pip-req-tracker-3hnmi5sj\n",
            "Initialized build tracking at /tmp/pip-req-tracker-3hnmi5sj\n",
            "Created build tracker: /tmp/pip-req-tracker-3hnmi5sj\n",
            "Entered build tracker: /tmp/pip-req-tracker-3hnmi5sj\n",
            "Created temporary directory: /tmp/pip-install-b370etpc\n",
            "Obtaining file:///mmocr\n",
            "  Added file:///mmocr to build tracker '/tmp/pip-req-tracker-3hnmi5sj'\n",
            "    Running setup.py (path:/mmocr/setup.py) egg_info for package from file:///mmocr\n",
            "    Created temporary directory: /tmp/pip-pip-egg-info-3wcoj0vo\n",
            "    Running command python setup.py egg_info\n",
            "    running egg_info\n",
            "    creating /tmp/pip-pip-egg-info-3wcoj0vo/mmocr.egg-info\n",
            "    writing /tmp/pip-pip-egg-info-3wcoj0vo/mmocr.egg-info/PKG-INFO\n",
            "    writing dependency_links to /tmp/pip-pip-egg-info-3wcoj0vo/mmocr.egg-info/dependency_links.txt\n",
            "    writing requirements to /tmp/pip-pip-egg-info-3wcoj0vo/mmocr.egg-info/requires.txt\n",
            "    writing top-level names to /tmp/pip-pip-egg-info-3wcoj0vo/mmocr.egg-info/top_level.txt\n",
            "    writing manifest file '/tmp/pip-pip-egg-info-3wcoj0vo/mmocr.egg-info/SOURCES.txt'\n",
            "    reading manifest template 'MANIFEST.in'\n",
            "    warning: no files found matching 'mmocr/.mim/model-index.yml'\n",
            "    warning: no files found matching '*.py' under directory 'mmocr/.mim/configs'\n",
            "    warning: no files found matching '*.yml' under directory 'mmocr/.mim/configs'\n",
            "    warning: no files found matching '*.sh' under directory 'mmocr/.mim/tools'\n",
            "    warning: no files found matching '*.py' under directory 'mmocr/.mim/tools'\n",
            "    adding license file 'LICENSE'\n",
            "    writing manifest file '/tmp/pip-pip-egg-info-3wcoj0vo/mmocr.egg-info/SOURCES.txt'\n",
            "  Source in /mmocr has version 0.4.1, which satisfies requirement mmocr==0.4.1 from file:///mmocr\n",
            "  Removed mmocr==0.4.1 from file:///mmocr from build tracker '/tmp/pip-req-tracker-3hnmi5sj'\n",
            "Requirement already satisfied: imgaug in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (0.2.9)\n",
            "Requirement already satisfied: lanms-neo==1.0.2 in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (1.0.2)\n",
            "Requirement already satisfied: lmdb in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (0.99)\n",
            "Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (3.2.2)\n",
            "Requirement already satisfied: numba>=0.45.1 in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (0.51.2)\n",
            "Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (1.21.5)\n",
            "Requirement already satisfied: opencv-python-headless<=4.5.4.60 in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (4.5.4.60)\n",
            "Requirement already satisfied: pyclipper in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (1.3.0.post2)\n",
            "Requirement already satisfied: pycocotools<=2.0.2 in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (2.0.2)\n",
            "Requirement already satisfied: rapidfuzz in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (2.0.7)\n",
            "Requirement already satisfied: scikit-image in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (0.18.3)\n",
            "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (1.15.0)\n",
            "Requirement already satisfied: terminaltables in /usr/local/lib/python3.7/dist-packages (from mmocr==0.4.1) (3.1.10)\n",
            "Requirement already satisfied: llvmlite<0.35,>=0.34.0.dev0 in /usr/local/lib/python3.7/dist-packages (from numba>=0.45.1->mmocr==0.4.1) (0.34.0)\n",
            "Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from numba>=0.45.1->mmocr==0.4.1) (57.4.0)\n",
            "Requirement already satisfied: cython>=0.27.3 in /usr/local/lib/python3.7/dist-packages (from pycocotools<=2.0.2->mmocr==0.4.1) (0.29.28)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmocr==0.4.1) (1.3.2)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmocr==0.4.1) (0.11.0)\n",
            "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmocr==0.4.1) (2.8.2)\n",
            "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmocr==0.4.1) (3.0.7)\n",
            "Requirement already satisfied: imageio in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.4.1) (2.4.1)\n",
            "Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.4.1) (7.1.2)\n",
            "Requirement already satisfied: opencv-python in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.4.1) (4.1.2.30)\n",
            "Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.4.1) (1.4.1)\n",
            "Requirement already satisfied: Shapely in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.4.1) (1.8.1.post1)\n",
            "Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.7/dist-packages (from scikit-image->mmocr==0.4.1) (1.2.0)\n",
            "Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.7/dist-packages (from scikit-image->mmocr==0.4.1) (2021.11.2)\n",
            "Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->mmocr==0.4.1) (2.6.3)\n",
            "Requirement already satisfied: jarowinkler<1.1.0,>=1.0.2 in /usr/local/lib/python3.7/dist-packages (from rapidfuzz->mmocr==0.4.1) (1.0.2)\n",
            "Created temporary directory: /tmp/pip-unpack-iha62low\n",
            "Installing collected packages: mmocr\n",
            "  Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "  distutils: /usr/local/lib/python3.7/dist-packages\n",
            "  sysconfig: /usr/lib/python3.7/site-packages\n",
            "  Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "  distutils: /usr/local/lib/python3.7/dist-packages\n",
            "  sysconfig: /usr/lib/python3.7/site-packages\n",
            "  Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "  distutils: /usr/local/include/python3.7/mmocr\n",
            "  sysconfig: /usr/include/python3.7m/mmocr\n",
            "  Value for scheme.scripts does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "  distutils: /usr/local/bin\n",
            "  sysconfig: /usr/bin\n",
            "  Value for scheme.data does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "  distutils: /usr/local\n",
            "  sysconfig: /usr\n",
            "  Additional context:\n",
            "  user = False\n",
            "  home = None\n",
            "  root = None\n",
            "  prefix = None\n",
            "  Running setup.py develop for mmocr\n",
            "    Running command /usr/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '\"'\"'/mmocr/setup.py'\"'\"'; __file__='\"'\"'/mmocr/setup.py'\"'\"';f = getattr(tokenize, '\"'\"'open'\"'\"', open)(__file__) if os.path.exists(__file__) else io.StringIO('\"'\"'from setuptools import setup; setup()'\"'\"');code = f.read().replace('\"'\"'\\r\\n'\"'\"', '\"'\"'\\n'\"'\"');f.close();exec(compile(code, __file__, '\"'\"'exec'\"'\"'))' develop --no-deps\n",
            "    running develop\n",
            "    running egg_info\n",
            "    creating mmocr.egg-info\n",
            "    writing mmocr.egg-info/PKG-INFO\n",
            "    writing dependency_links to mmocr.egg-info/dependency_links.txt\n",
            "    writing requirements to mmocr.egg-info/requires.txt\n",
            "    writing top-level names to mmocr.egg-info/top_level.txt\n",
            "    writing manifest file 'mmocr.egg-info/SOURCES.txt'\n",
            "    reading manifest template 'MANIFEST.in'\n",
            "    adding license file 'LICENSE'\n",
            "    writing manifest file 'mmocr.egg-info/SOURCES.txt'\n",
            "    running build_ext\n",
            "    Creating /usr/local/lib/python3.7/dist-packages/mmocr.egg-link (link to .)\n",
            "    Adding mmocr 0.4.1 to easy-install.pth file\n",
            "\n",
            "    Installed /mmocr\n",
            "Value for scheme.platlib does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local/lib/python3.7/dist-packages\n",
            "sysconfig: /usr/lib/python3.7/site-packages\n",
            "Value for scheme.purelib does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local/lib/python3.7/dist-packages\n",
            "sysconfig: /usr/lib/python3.7/site-packages\n",
            "Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local/include/python3.7/UNKNOWN\n",
            "sysconfig: /usr/include/python3.7m/UNKNOWN\n",
            "Value for scheme.scripts does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local/bin\n",
            "sysconfig: /usr/bin\n",
            "Value for scheme.data does not match. Please report this to <https://github.com/pypa/pip/issues/9617>\n",
            "distutils: /usr/local\n",
            "sysconfig: /usr\n",
            "Additional context:\n",
            "user = False\n",
            "home = None\n",
            "root = None\n",
            "prefix = None\n",
            "Successfully installed mmocr-0.4.1\n",
            "Removed build tracker: '/tmp/pip-req-tracker-3hnmi5sj'\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "DwDY3puNNmhe",
        "tags": [
          "outputPrepend"
        ],
        "outputId": "5058e757-1742-499a-dcda-aa3e800a72a3"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Check Installed Dependencies Versions"
      ],
      "metadata": {
        "id": "DY64JCc0pEUu"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "source": [
        "# Check Pytorch installation\n",
        "import torch, torchvision\n",
        "print(torch.__version__, torch.cuda.is_available())\n",
        "\n",
        "# Check MMDetection installation\n",
        "import mmdet\n",
        "print(mmdet.__version__)\n",
        "\n",
        "# Check mmcv installation\n",
        "import mmcv\n",
        "from mmcv.ops import get_compiling_cuda_version, get_compiler_version\n",
        "print(mmcv.__version__)\n",
        "print(get_compiling_cuda_version())\n",
        "print(get_compiler_version())\n",
        "\n",
        "# Check mmocr installation\n",
        "import mmocr\n",
        "print(mmocr.__version__)\n",
        "\n",
        "%cd /mmocr/\n",
        "!ls"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "1.10.0+cu111 True\n",
            "2.22.0\n",
            "1.4.6\n",
            "11.1\n",
            "GCC 7.3\n",
            "0.4.1\n",
            "/mmocr\n",
            "CITATION.cff  docs\t   mmocr.egg-info   requirements      setup.py\n",
            "configs       LICENSE\t   model-index.yml  requirements.txt  tests\n",
            "demo\t      MANIFEST.in  README.md\t    resources\t      tools\n",
            "docker\t      mmocr\t   README_zh-CN.md  setup.cfg\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "JABQfPwQN52g",
        "outputId": "61fa6153-4128-45b8-f684-fb96d6b557ab"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Inference\n",
        "\n",
        "We provide an easy-to-use inference script, `mmocr/utils/ocr.py`, that can be either called through command line or imported as an object (the `MMOCR` class inside). In this notebook, we choose the latter option for ease of demonstration. You can check out its full usage and examples in our [official documentation](https://mmocr.readthedocs.io/en/latest/demo.html)."
      ],
      "metadata": {
        "id": "YCLL7zlu5Hm1"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Perform Inference with a Pretrained Text Recognizer \n",
        "\n",
        "We now demonstrate how to inference on a [demo text recognition image](https://github.com/open-mmlab/mmocr/raw/main/demo/demo_text_recog.jpg) with a pretrained text recognizer using command line. SAR text recognizer is used for this demo, whose checkpoint can be found in the [official documentation](https://mmocr.readthedocs.io/en/latest/textrecog_models.html#show-attend-and-read-a-simple-and-strong-baseline-for-irregular-text-recognition). But you don't need to download it manually -- Our inference script handles these cumbersome setup steps for you! \n",
        "\n",
        "Run the following command and the recognition result will be saved to `outputs/demo_text_recog_pred.jpg`. We will visualize the result in the end."
      ],
      "metadata": {
        "id": "59gHy8Y4pEUv"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "source": [
        "from mmocr.utils.ocr import MMOCR\n",
        "mmocr = MMOCR(det=None, recog='SAR')\n",
        "mmocr.readtext('demo/demo_text_recog.jpg', print_result=True, output='outputs/demo_text_recog_pred.jpg')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.7/dist-packages/mmdet/datasets/pipelines/formating.py:7: UserWarning: DeprecationWarning: mmdet.datasets.pipelines.formating will be deprecated, please replace it with mmdet.datasets.pipelines.formatting.\n",
            "  warnings.warn('DeprecationWarning: mmdet.datasets.pipelines.formating will be '\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "load checkpoint from http path: https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_academic-dba3a4a3.pth\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "Downloading: \"https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_academic-dba3a4a3.pth\" to /root/.cache/torch/hub/checkpoints/sar_r31_parallel_decoder_academic-dba3a4a3.pth\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "  0%|          | 0.00/219M [00:00<?, ?B/s]"
            ],
            "application/vnd.jupyter.widget-view+json": {
              "version_major": 2,
              "version_minor": 0,
              "model_id": "9922c33a131f41cfac84af47b5e5981c"
            }
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/mmocr/mmocr/apis/inference.py:50: UserWarning: Class names are not saved in the checkpoint's meta data, use COCO classes by default.\n",
            "  warnings.warn('Class names are not saved in the checkpoint\\'s '\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{'text': 'STAR', 'score': 0.9664110243320465}\n",
            "\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[{'score': 0.9664110243320465, 'text': 'STAR'}]"
            ]
          },
          "metadata": {},
          "execution_count": 6
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 229,
          "referenced_widgets": [
            "9922c33a131f41cfac84af47b5e5981c",
            "9be2b6bd525c4b31be2d386b37d573b6",
            "edb36ab14ab44bc98983d447c1cb150a",
            "46dafdb514c049a7bb18ada61c7dee49",
            "c267e0b248154c028a93390ea187ef7f",
            "e2bc0c96bdee4d9c981f71c1001ec637",
            "b735ff5dcd114345bc89b462bc276759",
            "5ef02d42f1d34f6a81dbbe8b4fbd7ffc",
            "1712f2cbff4a4cbdaaa238d89905ec21",
            "1e43262b71ef45f1a5535d78594a0235",
            "5e7c98e0dbc4463c81b15c56c48ba1cf"
          ]
        },
        "id": "iQQIVH9ApEUv",
        "outputId": "565fff52-5f8f-4614-df2b-3d3e7f0c166b"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "source": [
        "# Visualize the results\n",
        "import matplotlib.pyplot as plt\n",
        "predicted_img = mmcv.imread('./outputs/demo_text_recog_pred.jpg')\n",
        "plt.imshow(mmcv.bgr2rgb(predicted_img))\n",
        "plt.show()"
      ],
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ],
            "image/png": "[encoded data, 51992 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 268
        },
        "id": "0ab_YJnXpEUw",
        "outputId": "e514b1c0-25af-4b18-b9a2-686a4a2aa47a"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Perform Inference with a Pretrained Text Detector \n",
        "\n",
        "Next, we perform inference with a pretrained TextSnake text detector and visualize the bounding box results for the demo text detection image provided in [demo_text_det.jpg](https://raw.githubusercontent.com/open-mmlab/mmocr/main/demo/demo_text_det.jpg)."
      ],
      "metadata": {
        "id": "NgoH6qEcC9CL"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "source": [
        "from mmocr.utils.ocr import MMOCR\n",
        "mmocr = MMOCR(det='TextSnake', recog=None)\n",
        "_ = mmocr.readtext('demo/demo_text_det.jpg', output='outputs/demo_text_det_pred.jpg')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "load checkpoint from http path: https://download.openmmlab.com/mmocr/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500-27f65b64.pth\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "Downloading: \"https://download.openmmlab.com/mmocr/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500-27f65b64.pth\" to /root/.cache/torch/hub/checkpoints/textsnake_r50_fpn_unet_1200e_ctw1500-27f65b64.pth\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "  0%|          | 0.00/139M [00:00<?, ?B/s]"
            ],
            "application/vnd.jupyter.widget-view+json": {
              "version_major": 2,
              "version_minor": 0,
              "model_id": "0cfa2ece94314ed186b834646623852a"
            }
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.7/dist-packages/mmdet/datasets/utils.py:70: UserWarning: \"ImageToTensor\" pipeline is replaced by \"DefaultFormatBundle\" for batch inference. It is recommended to manually replace it in the test data pipeline in your config file.\n",
            "  'data pipeline in your config file.', UserWarning)\n",
            "/mmocr/mmocr/models/textdet/postprocess/utils.py:51: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n",
            "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
            "  canvas = canvas[1:h + 1, 1:w + 1].astype(np.bool)\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 194,
          "referenced_widgets": [
            "0cfa2ece94314ed186b834646623852a",
            "5f5f9ed460404047bfda112283b4f159",
            "7c6bbe29702444b9a6adfef0d11f2a5c",
            "b48490fd9f0d4cc38acd6c0ccf57b68a",
            "6f6240bf87a3442dbce39764c97dbd8f",
            "b3adfe1225ac4497ae818e5a78132c34",
            "c36a853d851249c49c63599219f73c38",
            "a4d14f12345b4956a7861d5c54a51fad",
            "592582312a0c4ddfa40e55026fd51e3f",
            "3947416ef2c245d197e7b254d0d513b8",
            "dc187713177749469e49eed82769df1c"
          ]
        },
        "id": "u0YyG9y0TzL4",
        "outputId": "c781af52-61c7-48ca-bf3e-b0fe16819224"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "source": [
        "# Visualize the results\n",
        "import matplotlib.pyplot as plt\n",
        "predicted_img = mmcv.imread('./outputs/demo_text_det_pred.jpg')\n",
        "plt.figure(figsize=(9, 16))\n",
        "plt.imshow(mmcv.bgr2rgb(predicted_img))\n",
        "plt.show()"
      ],
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 648x1152 with 1 Axes>"
            ],
            "image/png": "[encoded data, 390100 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 353
        },
        "id": "2-UHsqkZJFND",
        "outputId": "edc80599-0da0-45aa-9467-46f9eef6c4a4"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Perform end-to-end OCR with pretrained recognizer and detector\n",
        "\n",
        "With the help of `ocr.py`, we can easily combine any text detector and recognizer into a pipeline that forms a standard OCR step. Now we build our own OCR pipeline with TextSnake and SAR and apply it to [demo_text_ocr.jpg](https://raw.githubusercontent.com/open-mmlab/mmocr/main/demo/demo_text_ocr.jpg)."
      ],
      "metadata": {
        "id": "x-uRAtLa63sz"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "source": [
        "from mmocr.utils.ocr import MMOCR\n",
        "mmocr = MMOCR(det='TextSnake', recog='SAR')\n",
        "mmocr.readtext('demo/demo_text_ocr.jpg', print_result=True, output='outputs/demo_text_ocr_pred.jpg')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "load checkpoint from http path: https://download.openmmlab.com/mmocr/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500-27f65b64.pth\n",
            "load checkpoint from http path: https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_academic-dba3a4a3.pth\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/mmocr/mmocr/apis/inference.py:50: UserWarning: Class names are not saved in the checkpoint's meta data, use COCO classes by default.\n",
            "  warnings.warn('Class names are not saved in the checkpoint\\'s '\n",
            "/usr/local/lib/python3.7/dist-packages/mmdet/datasets/utils.py:70: UserWarning: \"ImageToTensor\" pipeline is replaced by \"DefaultFormatBundle\" for batch inference. It is recommended to manually replace it in the test data pipeline in your config file.\n",
            "  'data pipeline in your config file.', UserWarning)\n",
            "/mmocr/mmocr/models/textdet/postprocess/utils.py:51: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n",
            "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
            "  canvas = canvas[1:h + 1, 1:w + 1].astype(np.bool)\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{'filename': 'demo_text_ocr', 'text': ['OCBCBANK', 'soculationists', 'sanetal.enance.ounces', '70%', 'ROUND', 'SALE', 'ALLYEAR', 'is', 'SALE']}\n",
            "\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[{'filename': 'demo_text_ocr',\n",
              "  'text': ['OCBCBANK',\n",
              "   'soculationists',\n",
              "   'sanetal.enance.ounces',\n",
              "   '70%',\n",
              "   'ROUND',\n",
              "   'SALE',\n",
              "   'ALLYEAR',\n",
              "   'is',\n",
              "   'SALE']}]"
            ]
          },
          "metadata": {},
          "execution_count": 10
        }
      ],
      "metadata": {
        "id": "xu68YizP8qu6",
        "outputId": "b16dc3bd-253e-4b63-ad88-8b79ededf7a9",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      }
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "source": [
        "# Visualize the results\n",
        "import matplotlib.pyplot as plt\n",
        "predicted_img = mmcv.imread('./outputs/demo_text_ocr_pred.jpg')\n",
        "plt.figure(figsize=(9, 16))\n",
        "plt.imshow(mmcv.bgr2rgb(predicted_img))\n",
        "plt.show()"
      ],
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 648x1152 with 1 Axes>"
            ],
            "image/png": "[encoded data, 144820 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ],
      "metadata": {
        "id": "2AZqwCt09XqR",
        "outputId": "ba5009b3-fc09-4561-b9d6-f5fba6353fdd",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 262
        }
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Combine OCR with Downstream Tasks\n",
        "\n",
        "MMOCR also supports downstream tasks of OCR, such as key information extraction (KIE). We can even add a KIE model, SDMG-R, to the pipeline applied to [demo_kie.jpeg](https://raw.githubusercontent.com/open-mmlab/mmocr/main/demo/demo_kie.jpeg) and visualize its prediction based on the OCR result.\n"
      ],
      "metadata": {
        "id": "WQ9zzYMa9p9Y"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "source": [
        "# SDMGR relies on the dictionary provided in wildreceipt\n",
        "# First download the KIE dataset .tar file and extract it to ./data\n",
        "!mkdir data\n",
        "!wget https://download.openmmlab.com/mmocr/data/wildreceipt.tar\n",
        "!tar -xf wildreceipt.tar \n",
        "!mv wildreceipt ./data"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "--2022-03-18 07:02:24--  https://download.openmmlab.com/mmocr/data/wildreceipt.tar\n",
            "Resolving download.openmmlab.com (download.openmmlab.com)... 47.252.96.28\n",
            "Connecting to download.openmmlab.com (download.openmmlab.com)|47.252.96.28|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 185323520 (177M) [application/x-tar]\n",
            "Saving to: ‘wildreceipt.tar’\n",
            "\n",
            "wildreceipt.tar     100%[===================>] 176.74M  6.76MB/s    in 23s     \n",
            "\n",
            "2022-03-18 07:02:49 (7.55 MB/s) - ‘wildreceipt.tar’ saved [185323520/185323520]\n",
            "\n"
          ]
        }
      ],
      "metadata": {
        "id": "oALHgzmrAqik",
        "outputId": "d1344657-ee01-459e-a6b5-34c0e370321a",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      }
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "source": [
        "from mmocr.utils.ocr import MMOCR\n",
        "mmocr = MMOCR(det='TextSnake', recog='SAR', kie='SDMGR')\n",
        "mmocr.readtext('demo/demo_kie.jpeg', print_result=True, output='outputs/demo_kie_pred.jpg')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "load checkpoint from http path: https://download.openmmlab.com/mmocr/textdet/textsnake/textsnake_r50_fpn_unet_1200e_ctw1500-27f65b64.pth\n",
            "load checkpoint from http path: https://download.openmmlab.com/mmocr/textrecog/sar/sar_r31_parallel_decoder_academic-dba3a4a3.pth\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/mmocr/mmocr/apis/inference.py:50: UserWarning: Class names are not saved in the checkpoint's meta data, use COCO classes by default.\n",
            "  warnings.warn('Class names are not saved in the checkpoint\\'s '\n",
            "Downloading: \"https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_unet16_60e_wildreceipt_20210520-7489e6de.pth\" to /root/.cache/torch/hub/checkpoints/sdmgr_unet16_60e_wildreceipt_20210520-7489e6de.pth\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "load checkpoint from http path: https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_unet16_60e_wildreceipt_20210520-7489e6de.pth\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "  0%|          | 0.00/18.4M [00:00<?, ?B/s]"
            ],
            "application/vnd.jupyter.widget-view+json": {
              "version_major": 2,
              "version_minor": 0,
              "model_id": "cd5e91174a6441ad9d7b8c0a05f18f60"
            }
          },
          "metadata": {}
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.7/dist-packages/mmdet/datasets/utils.py:70: UserWarning: \"ImageToTensor\" pipeline is replaced by \"DefaultFormatBundle\" for batch inference. It is recommended to manually replace it in the test data pipeline in your config file.\n",
            "  'data pipeline in your config file.', UserWarning)\n",
            "/mmocr/mmocr/models/textdet/postprocess/utils.py:51: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.\n",
            "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
            "  canvas = canvas[1:h + 1, 1:w + 1].astype(np.bool)\n",
            "/mmocr/mmocr/datasets/kie_dataset.py:46: UserWarning: KIEDataset is only initialized as a downstream demo task of text detection and recognition without an annotation file.\n",
            "  'without an annotation file.', UserWarning)\n",
            "/mmocr/mmocr/datasets/pipelines/box_utils.py:44: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n",
            "Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
            "  indexes = (np.arange(N, dtype=np.int) + lefttop_idx) % N\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Downloading https://download.openmmlab.com/mmocr/data/font.TTF ...\n",
            "{'filename': 'demo_kie', 'text': ['Appraval:052723', 'Acct:Xexexxx8425', '128.27', 'Master', '128.27', 'Total', 'Tax', '11.02', '117.25', 'subTotal', 'Cheese', '10.47', '3.Perreroni', '11.07', '3Supreme', '11.97', '26', '43.94', '0.00', '12.Crunchy.Taco', '10.00', 'SLACOMPARTY', '0.00', '12SFTTACO', '10.00', 'SFtt.Tac.Party.', '0.00', 'MONODELONS', '0.00', '10.Bean', 'Grande', '9.90', 'Beatean', '0.00', 'grande', '9.90', '0rder-113533', 'Cashier:.Eric', '7/30/2012', '8:27:32', '=Article-I.D.:']}\n",
            "\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "[{'filename': 'demo_kie',\n",
              "  'text': ['Appraval:052723',\n",
              "   'Acct:Xexexxx8425',\n",
              "   '128.27',\n",
              "   'Master',\n",
              "   '128.27',\n",
              "   'Total',\n",
              "   'Tax',\n",
              "   '11.02',\n",
              "   '117.25',\n",
              "   'subTotal',\n",
              "   'Cheese',\n",
              "   '10.47',\n",
              "   '3.Perreroni',\n",
              "   '11.07',\n",
              "   '3Supreme',\n",
              "   '11.97',\n",
              "   '26',\n",
              "   '43.94',\n",
              "   '0.00',\n",
              "   '12.Crunchy.Taco',\n",
              "   '10.00',\n",
              "   'SLACOMPARTY',\n",
              "   '0.00',\n",
              "   '12SFTTACO',\n",
              "   '10.00',\n",
              "   'SFtt.Tac.Party.',\n",
              "   '0.00',\n",
              "   'MONODELONS',\n",
              "   '0.00',\n",
              "   '10.Bean',\n",
              "   'Grande',\n",
              "   '9.90',\n",
              "   'Beatean',\n",
              "   '0.00',\n",
              "   'grande',\n",
              "   '9.90',\n",
              "   '0rder-113533',\n",
              "   'Cashier:.Eric',\n",
              "   '7/30/2012',\n",
              "   '8:27:32',\n",
              "   '=Article-I.D.:']}]"
            ]
          },
          "metadata": {},
          "execution_count": 13
        }
      ],
      "metadata": {
        "id": "2KPRTdHVAGfF",
        "outputId": "b77885e0-2c12-4eb3-b7f3-e7db80615f29",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000,
          "referenced_widgets": [
            "cd5e91174a6441ad9d7b8c0a05f18f60",
            "7f0e77d508574ec485243125375cedfb",
            "45cc8c746da74a8fbc32d5bdfb1e350e",
            "4153b5f7dd474c079cb9b38f79d515d8",
            "31a4e677ff8849e8b9050ece3e516413",
            "3761f71633874fd39205adb5fafe98fe",
            "12377605aaa24988b2075e88c5fd77cc",
            "39bb6e08d13c4979a731ca6c8a8e5668",
            "97992daf80b5487595712d675d17a9da",
            "f1d3884457d8426db6a59bda51249444",
            "a2220a97632e449e95ff559987245b0b"
          ]
        }
      }
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "source": [
        "# Visualize the results\n",
        "import matplotlib.pyplot as plt\n",
        "predicted_img = mmcv.imread('./outputs/demo_kie_pred.jpg')\n",
        "plt.figure(figsize=(18, 32))\n",
        "plt.imshow(mmcv.bgr2rgb(predicted_img))\n",
        "plt.show()"
      ],
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 1296x2304 with 1 Axes>"
            ],
            "image/png": "[encoded data, 578912 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ],
      "metadata": {
        "id": "96hqfaovAGhl",
        "outputId": "5d1a8f38-aac4-4f14-b65c-5792e8d496d8",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 306
        }
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Perform Testing with a Pretrained KIE Model\n",
        "\n",
        "We perform testing on the WildReceipt dataset for KIE model by first downloading the .tar file from [Datasets Preparation](https://mmocr.readthedocs.io/en/latest/datasets.html) in MMOCR documentation and then extract the dataset. We have chosen the Visual + Textual moduality test dataset, which we evaluate with Macro F1 metrics."
      ],
      "metadata": {
        "id": "PTWMzvd3E_h8"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "source": [
        "# Can skip this step if you have downloaded wildreceipt in the last section\n",
        "# Download the KIE dataset .tar file and extract it to ./data\n",
        "!mkdir data\n",
        "!wget https://download.openmmlab.com/mmocr/data/wildreceipt.tar\n",
        "!tar -xf wildreceipt.tar \n",
        "!mv wildreceipt ./data"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "mkdir: cannot create directory ‘data’: File exists\n",
            "--2022-03-18 07:03:33--  https://download.openmmlab.com/mmocr/data/wildreceipt.tar\n",
            "Resolving download.openmmlab.com (download.openmmlab.com)... 47.75.20.18\n",
            "Connecting to download.openmmlab.com (download.openmmlab.com)|47.75.20.18|:443... connected.\n",
            "HTTP request sent, awaiting response... 200 OK\n",
            "Length: 185323520 (177M) [application/x-tar]\n",
            "Saving to: ‘wildreceipt.tar.1’\n",
            "\n",
            "wildreceipt.tar.1   100%[===================>] 176.74M  6.24MB/s    in 20s     \n",
            "\n",
            "2022-03-18 07:03:54 (8.90 MB/s) - ‘wildreceipt.tar.1’ saved [185323520/185323520]\n",
            "\n",
            "mv: cannot move 'wildreceipt' to './data/wildreceipt': Directory not empty\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "3VEW3PQrFZ0g",
        "outputId": "6604ea25-cbf6-4c74-bc8e-8413abf3adba"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "source": [
        "# Test the dataset with macro f1 metrics \n",
        "!python tools/test.py configs/kie/sdmgr/sdmgr_unet16_60e_wildreceipt.py https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_unet16_60e_wildreceipt_20210405-16a47642.pth --eval macro_f1"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/usr/local/lib/python3.7/dist-packages/mmdet/datasets/pipelines/formating.py:7: UserWarning: DeprecationWarning: mmdet.datasets.pipelines.formating will be deprecated, please replace it with mmdet.datasets.pipelines.formatting.\n",
            "  warnings.warn('DeprecationWarning: mmdet.datasets.pipelines.formating will be '\n",
            "/mmocr/mmocr/utils/setup_env.py:33: UserWarning: Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.\n",
            "  f'Setting OMP_NUM_THREADS environment variable for each process '\n",
            "/mmocr/mmocr/utils/setup_env.py:43: UserWarning: Setting MKL_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.\n",
            "  f'Setting MKL_NUM_THREADS environment variable for each process '\n",
            "/mmocr/mmocr/datasets/utils/loader.py:86: UserWarning: HardDiskLoader is deprecated, please use AnnFileLoader instead.\n",
            "  'AnnFileLoader instead.', UserWarning)\n",
            "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py:481: UserWarning: This DataLoader will create 4 worker processes in total. Our suggested max number of worker in current system is 2, which is smaller than what this DataLoader is going to create. Please be aware that excessive worker creation might get DataLoader running slow or even freeze, lower the worker number to avoid potential slowness/freeze if necessary.\n",
            "  cpuset_checked))\n",
            "load checkpoint from http path: https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_unet16_60e_wildreceipt_20210405-16a47642.pth\n",
            "Downloading: \"https://download.openmmlab.com/mmocr/kie/sdmgr/sdmgr_unet16_60e_wildreceipt_20210405-16a47642.pth\" to /root/.cache/torch/hub/checkpoints/sdmgr_unet16_60e_wildreceipt_20210405-16a47642.pth\n",
            "100% 18.4M/18.4M [00:03<00:00, 6.25MB/s]\n",
            "[>>] 472/472, 12.9 task/s, elapsed: 36s, ETA:     0s{'macro_f1': 0.87641114}\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "p0MHNwybo0iI",
        "outputId": "337a3213-322d-409c-d65a-a17843d59e9d"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## Perform Training on a Toy Dataset with MMOCR Recognizer\n",
        "We now demonstrate how to perform training with an MMOCR recognizer. Since training a full academic dataset is time consuming (usually takes about several hours), we will train on the toy dataset for the SAR text recognition model and visualize the predictions. Text detection and other downstream tasks such as KIE follow similar procedures.\n",
        "\n",
        "Training a dataset usually consists of the following steps:\n",
        "1. Convert the dataset into a format supported by MMOCR (e.g. COCO for text detection). The annotation file can be in either .txt or .lmdb format, depending on the size of the dataset. This step is usually applicable to customized datasets, since the datasets and annotation files we provide are already in supported formats. \n",
        "2. Modify the config for training. \n",
        "3. Train the model. \n",
        "\n",
        "The toy dataset consisits of ten images as well as annotation files in both txt and lmdb format, which can be found in [ocr_toy_dataset](https://github.com/open-mmlab/mmocr/tree/main/tests/data/toy_dataset). "
      ],
      "metadata": {
        "id": "nYon41X7RTOT"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Visualize the Toy Dataset\n",
        "\n",
        "We first get a sense of what the toy dataset looks like by visualizing one of the images and labels. "
      ],
      "metadata": {
        "id": "FElJSp1vpEUz"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "source": [
        "import mmcv\n",
        "import matplotlib.pyplot as plt \n",
        "\n",
        "img = mmcv.imread('./tests/data/ocr_toy_dataset/imgs/1036169.jpg')\n",
        "plt.imshow(mmcv.bgr2rgb(img))\n",
        "plt.show()"
      ],
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ],
            "image/png": "[encoded data, 64696 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 121
        },
        "id": "hZfd2pnqN5-Q",
        "outputId": "8884944a-093f-4aed-c1c7-58d5e045ad31"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "source": [
        "# Inspect the labels of the annootation file\n",
        "!cat tests/data/ocr_toy_dataset/label.txt"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "1223731.jpg GRAND\n",
            "1223733.jpg HOTEL\n",
            "1223732.jpg HOTEL\n",
            "1223729.jpg PACIFIC\n",
            "1036169.jpg 03/09/2009\n",
            "1190237.jpg ANING\n",
            "1058891.jpg Virgin\n",
            "1058892.jpg america\n",
            "1240078.jpg ATTACK\n",
            "1210236.jpg DAVIDSON\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "F5M_FVVRN6Fw",
        "outputId": "35ef086b-1612-4126-a977-9d7891dd6839"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Modify the Configuration File\n",
        "\n",
        "In order to perform inference for SAR on colab, we need to modify the config file to accommodate some of the settings of colab such as the number of GPU available. "
      ],
      "metadata": {
        "id": "i-GrV0xSkAc3"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "source": [
        "from mmcv import Config\n",
        "cfg = Config.fromfile('./configs/textrecog/sar/sar_r31_parallel_decoder_toy_dataset.py')"
      ],
      "outputs": [],
      "metadata": {
        "id": "uFFH3yUgPEFj"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "source": [
        "from mmdet.apis import set_random_seed\n",
        "\n",
        "# Set up working dir to save files and logs.\n",
        "cfg.work_dir = './demo/tutorial_exps'\n",
        "\n",
        "# The original learning rate (LR) is set for 8-GPU training.\n",
        "# We divide it by 8 since we only use one GPU.\n",
        "cfg.optimizer.lr = 0.001 / 8\n",
        "cfg.lr_config.warmup = None\n",
        "# Choose to log training results every 40 images to reduce the size of log file. \n",
        "cfg.log_config.interval = 40\n",
        "\n",
        "# Set seed thus the results are more reproducible\n",
        "cfg.seed = 0\n",
        "set_random_seed(0, deterministic=False)\n",
        "cfg.gpu_ids = range(1)\n",
        "\n",
        "# We can initialize the logger for training and have a look\n",
        "# at the final config used for training\n",
        "print(f'Config:\\n{cfg.pretty_text}')"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Config:\n",
            "checkpoint_config = dict(interval=1)\n",
            "log_config = dict(interval=40, hooks=[dict(type='TextLoggerHook')])\n",
            "dist_params = dict(backend='nccl')\n",
            "log_level = 'INFO'\n",
            "load_from = None\n",
            "resume_from = None\n",
            "workflow = [('train', 1)]\n",
            "opencv_num_threads = 0\n",
            "mp_start_method = 'fork'\n",
            "label_convertor = dict(\n",
            "    type='AttnConvertor', dict_type='DICT90', with_unknown=True)\n",
            "model = dict(\n",
            "    type='SARNet',\n",
            "    backbone=dict(type='ResNet31OCR'),\n",
            "    encoder=dict(\n",
            "        type='SAREncoder', enc_bi_rnn=False, enc_do_rnn=0.1, enc_gru=False),\n",
            "    decoder=dict(\n",
            "        type='ParallelSARDecoder',\n",
            "        enc_bi_rnn=False,\n",
            "        dec_bi_rnn=False,\n",
            "        dec_do_rnn=0,\n",
            "        dec_gru=False,\n",
            "        pred_dropout=0.1,\n",
            "        d_k=512,\n",
            "        pred_concat=True),\n",
            "    loss=dict(type='SARLoss'),\n",
            "    label_convertor=dict(\n",
            "        type='AttnConvertor', dict_type='DICT90', with_unknown=True),\n",
            "    max_seq_len=30)\n",
            "optimizer = dict(type='Adam', lr=0.000125)\n",
            "optimizer_config = dict(grad_clip=None)\n",
            "lr_config = dict(policy='step', step=[3, 4], warmup=None)\n",
            "total_epochs = 5\n",
            "img_norm_cfg = dict(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])\n",
            "train_pipeline = [\n",
            "    dict(type='LoadImageFromFile'),\n",
            "    dict(\n",
            "        type='ResizeOCR',\n",
            "        height=48,\n",
            "        min_width=48,\n",
            "        max_width=160,\n",
            "        keep_aspect_ratio=True,\n",
            "        width_downsample_ratio=0.25),\n",
            "    dict(type='ToTensorOCR'),\n",
            "    dict(type='NormalizeOCR', mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),\n",
            "    dict(\n",
            "        type='Collect',\n",
            "        keys=['img'],\n",
            "        meta_keys=[\n",
            "            'filename', 'ori_shape', 'resize_shape', 'text', 'valid_ratio'\n",
            "        ])\n",
            "]\n",
            "test_pipeline = [\n",
            "    dict(type='LoadImageFromFile'),\n",
            "    dict(\n",
            "        type='MultiRotateAugOCR',\n",
            "        rotate_degrees=[0, 90, 270],\n",
            "        transforms=[\n",
            "            dict(\n",
            "                type='ResizeOCR',\n",
            "                height=48,\n",
            "                min_width=48,\n",
            "                max_width=160,\n",
            "                keep_aspect_ratio=True,\n",
            "                width_downsample_ratio=0.25),\n",
            "            dict(type='ToTensorOCR'),\n",
            "            dict(\n",
            "                type='NormalizeOCR', mean=[0.5, 0.5, 0.5], std=[0.5, 0.5,\n",
            "                                                                0.5]),\n",
            "            dict(\n",
            "                type='Collect',\n",
            "                keys=['img'],\n",
            "                meta_keys=[\n",
            "                    'filename', 'ori_shape', 'resize_shape', 'valid_ratio',\n",
            "                    'img_norm_cfg', 'ori_filename', 'img_shape'\n",
            "                ])\n",
            "        ])\n",
            "]\n",
            "dataset_type = 'OCRDataset'\n",
            "root = 'tests/data/ocr_toy_dataset'\n",
            "img_prefix = 'tests/data/ocr_toy_dataset/imgs'\n",
            "train_anno_file1 = 'tests/data/ocr_toy_dataset/label.txt'\n",
            "train1 = dict(\n",
            "    type='OCRDataset',\n",
            "    img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "    ann_file='tests/data/ocr_toy_dataset/label.txt',\n",
            "    loader=dict(\n",
            "        type='HardDiskLoader',\n",
            "        repeat=100,\n",
            "        parser=dict(\n",
            "            type='LineStrParser',\n",
            "            keys=['filename', 'text'],\n",
            "            keys_idx=[0, 1],\n",
            "            separator=' ')),\n",
            "    pipeline=None,\n",
            "    test_mode=False)\n",
            "train_anno_file2 = 'tests/data/ocr_toy_dataset/label.lmdb'\n",
            "train2 = dict(\n",
            "    type='OCRDataset',\n",
            "    img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "    ann_file='tests/data/ocr_toy_dataset/label.lmdb',\n",
            "    loader=dict(\n",
            "        type='LmdbLoader',\n",
            "        repeat=100,\n",
            "        parser=dict(\n",
            "            type='LineStrParser',\n",
            "            keys=['filename', 'text'],\n",
            "            keys_idx=[0, 1],\n",
            "            separator=' ')),\n",
            "    pipeline=None,\n",
            "    test_mode=False)\n",
            "test_anno_file1 = 'tests/data/ocr_toy_dataset/label.lmdb'\n",
            "test = dict(\n",
            "    type='OCRDataset',\n",
            "    img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "    ann_file='tests/data/ocr_toy_dataset/label.lmdb',\n",
            "    loader=dict(\n",
            "        type='LmdbLoader',\n",
            "        repeat=1,\n",
            "        parser=dict(\n",
            "            type='LineStrParser',\n",
            "            keys=['filename', 'text'],\n",
            "            keys_idx=[0, 1],\n",
            "            separator=' ')),\n",
            "    pipeline=None,\n",
            "    test_mode=True)\n",
            "train_list = [\n",
            "    dict(\n",
            "        type='OCRDataset',\n",
            "        img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "        ann_file='tests/data/ocr_toy_dataset/label.txt',\n",
            "        loader=dict(\n",
            "            type='HardDiskLoader',\n",
            "            repeat=100,\n",
            "            parser=dict(\n",
            "                type='LineStrParser',\n",
            "                keys=['filename', 'text'],\n",
            "                keys_idx=[0, 1],\n",
            "                separator=' ')),\n",
            "        pipeline=None,\n",
            "        test_mode=False),\n",
            "    dict(\n",
            "        type='OCRDataset',\n",
            "        img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "        ann_file='tests/data/ocr_toy_dataset/label.lmdb',\n",
            "        loader=dict(\n",
            "            type='LmdbLoader',\n",
            "            repeat=100,\n",
            "            parser=dict(\n",
            "                type='LineStrParser',\n",
            "                keys=['filename', 'text'],\n",
            "                keys_idx=[0, 1],\n",
            "                separator=' ')),\n",
            "        pipeline=None,\n",
            "        test_mode=False)\n",
            "]\n",
            "test_list = [\n",
            "    dict(\n",
            "        type='OCRDataset',\n",
            "        img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "        ann_file='tests/data/ocr_toy_dataset/label.lmdb',\n",
            "        loader=dict(\n",
            "            type='LmdbLoader',\n",
            "            repeat=1,\n",
            "            parser=dict(\n",
            "                type='LineStrParser',\n",
            "                keys=['filename', 'text'],\n",
            "                keys_idx=[0, 1],\n",
            "                separator=' ')),\n",
            "        pipeline=None,\n",
            "        test_mode=True)\n",
            "]\n",
            "data = dict(\n",
            "    workers_per_gpu=2,\n",
            "    samples_per_gpu=8,\n",
            "    train=dict(\n",
            "        type='UniformConcatDataset',\n",
            "        datasets=[\n",
            "            dict(\n",
            "                type='OCRDataset',\n",
            "                img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "                ann_file='tests/data/ocr_toy_dataset/label.txt',\n",
            "                loader=dict(\n",
            "                    type='HardDiskLoader',\n",
            "                    repeat=100,\n",
            "                    parser=dict(\n",
            "                        type='LineStrParser',\n",
            "                        keys=['filename', 'text'],\n",
            "                        keys_idx=[0, 1],\n",
            "                        separator=' ')),\n",
            "                pipeline=None,\n",
            "                test_mode=False),\n",
            "            dict(\n",
            "                type='OCRDataset',\n",
            "                img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "                ann_file='tests/data/ocr_toy_dataset/label.lmdb',\n",
            "                loader=dict(\n",
            "                    type='LmdbLoader',\n",
            "                    repeat=100,\n",
            "                    parser=dict(\n",
            "                        type='LineStrParser',\n",
            "                        keys=['filename', 'text'],\n",
            "                        keys_idx=[0, 1],\n",
            "                        separator=' ')),\n",
            "                pipeline=None,\n",
            "                test_mode=False)\n",
            "        ],\n",
            "        pipeline=[\n",
            "            dict(type='LoadImageFromFile'),\n",
            "            dict(\n",
            "                type='ResizeOCR',\n",
            "                height=48,\n",
            "                min_width=48,\n",
            "                max_width=160,\n",
            "                keep_aspect_ratio=True,\n",
            "                width_downsample_ratio=0.25),\n",
            "            dict(type='ToTensorOCR'),\n",
            "            dict(\n",
            "                type='NormalizeOCR', mean=[0.5, 0.5, 0.5], std=[0.5, 0.5,\n",
            "                                                                0.5]),\n",
            "            dict(\n",
            "                type='Collect',\n",
            "                keys=['img'],\n",
            "                meta_keys=[\n",
            "                    'filename', 'ori_shape', 'resize_shape', 'text',\n",
            "                    'valid_ratio'\n",
            "                ])\n",
            "        ]),\n",
            "    val=dict(\n",
            "        type='UniformConcatDataset',\n",
            "        datasets=[\n",
            "            dict(\n",
            "                type='OCRDataset',\n",
            "                img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "                ann_file='tests/data/ocr_toy_dataset/label.lmdb',\n",
            "                loader=dict(\n",
            "                    type='LmdbLoader',\n",
            "                    repeat=1,\n",
            "                    parser=dict(\n",
            "                        type='LineStrParser',\n",
            "                        keys=['filename', 'text'],\n",
            "                        keys_idx=[0, 1],\n",
            "                        separator=' ')),\n",
            "                pipeline=None,\n",
            "                test_mode=True)\n",
            "        ],\n",
            "        pipeline=[\n",
            "            dict(type='LoadImageFromFile'),\n",
            "            dict(\n",
            "                type='MultiRotateAugOCR',\n",
            "                rotate_degrees=[0, 90, 270],\n",
            "                transforms=[\n",
            "                    dict(\n",
            "                        type='ResizeOCR',\n",
            "                        height=48,\n",
            "                        min_width=48,\n",
            "                        max_width=160,\n",
            "                        keep_aspect_ratio=True,\n",
            "                        width_downsample_ratio=0.25),\n",
            "                    dict(type='ToTensorOCR'),\n",
            "                    dict(\n",
            "                        type='NormalizeOCR',\n",
            "                        mean=[0.5, 0.5, 0.5],\n",
            "                        std=[0.5, 0.5, 0.5]),\n",
            "                    dict(\n",
            "                        type='Collect',\n",
            "                        keys=['img'],\n",
            "                        meta_keys=[\n",
            "                            'filename', 'ori_shape', 'resize_shape',\n",
            "                            'valid_ratio', 'img_norm_cfg', 'ori_filename',\n",
            "                            'img_shape'\n",
            "                        ])\n",
            "                ])\n",
            "        ]),\n",
            "    test=dict(\n",
            "        type='UniformConcatDataset',\n",
            "        datasets=[\n",
            "            dict(\n",
            "                type='OCRDataset',\n",
            "                img_prefix='tests/data/ocr_toy_dataset/imgs',\n",
            "                ann_file='tests/data/ocr_toy_dataset/label.lmdb',\n",
            "                loader=dict(\n",
            "                    type='LmdbLoader',\n",
            "                    repeat=1,\n",
            "                    parser=dict(\n",
            "                        type='LineStrParser',\n",
            "                        keys=['filename', 'text'],\n",
            "                        keys_idx=[0, 1],\n",
            "                        separator=' ')),\n",
            "                pipeline=None,\n",
            "                test_mode=True)\n",
            "        ],\n",
            "        pipeline=[\n",
            "            dict(type='LoadImageFromFile'),\n",
            "            dict(\n",
            "                type='MultiRotateAugOCR',\n",
            "                rotate_degrees=[0, 90, 270],\n",
            "                transforms=[\n",
            "                    dict(\n",
            "                        type='ResizeOCR',\n",
            "                        height=48,\n",
            "                        min_width=48,\n",
            "                        max_width=160,\n",
            "                        keep_aspect_ratio=True,\n",
            "                        width_downsample_ratio=0.25),\n",
            "                    dict(type='ToTensorOCR'),\n",
            "                    dict(\n",
            "                        type='NormalizeOCR',\n",
            "                        mean=[0.5, 0.5, 0.5],\n",
            "                        std=[0.5, 0.5, 0.5]),\n",
            "                    dict(\n",
            "                        type='Collect',\n",
            "                        keys=['img'],\n",
            "                        meta_keys=[\n",
            "                            'filename', 'ori_shape', 'resize_shape',\n",
            "                            'valid_ratio', 'img_norm_cfg', 'ori_filename',\n",
            "                            'img_shape'\n",
            "                        ])\n",
            "                ])\n",
            "        ]))\n",
            "evaluation = dict(interval=1, metric='acc')\n",
            "work_dir = './demo/tutorial_exps'\n",
            "seed = 0\n",
            "gpu_ids = range(0, 1)\n",
            "\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "67OJ6oAvN6NA",
        "outputId": "ae49a1d2-3a28-478b-aabd-2bdd354663e7"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Train the SAR Text Recognizer \n",
        "Finally, we train the SAR text recognizer on the toy dataset for five epochs. "
      ],
      "metadata": {
        "id": "TZj5vyqEmulE"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "source": [
        "from mmocr.datasets import build_dataset\n",
        "from mmocr.models import build_detector\n",
        "from mmocr.apis import train_detector\n",
        "import os.path as osp\n",
        "\n",
        "# Build dataset\n",
        "datasets = [build_dataset(cfg.data.train)]\n",
        "\n",
        "# Build the detector\n",
        "model = build_detector(\n",
        "    cfg.model, train_cfg=cfg.get('train_cfg'), test_cfg=cfg.get('test_cfg'))\n",
        "# Add an attribute for visualization convenience\n",
        "model.CLASSES = datasets[0].CLASSES\n",
        "\n",
        "# Create work_dir\n",
        "mmcv.mkdir_or_exist(osp.abspath(cfg.work_dir))\n",
        "train_detector(model, datasets, cfg, distributed=False, validate=True)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/mmocr/mmocr/datasets/utils/loader.py:86: UserWarning: HardDiskLoader is deprecated, please use AnnFileLoader instead.\n",
            "  'AnnFileLoader instead.', UserWarning)\n",
            "/mmocr/mmocr/datasets/utils/loader.py:102: UserWarning: LmdbLoader is deprecated, please use AnnFileLoader instead.\n",
            "  'AnnFileLoader instead.', UserWarning)\n",
            "/mmocr/mmocr/apis/train.py:86: UserWarning: config is now expected to have a `runner` section, please set `runner` in your config.\n",
            "  'please set `runner` in your config.', UserWarning)\n",
            "/mmocr/mmocr/apis/utils.py:53: UserWarning: Remove \"MultiRotateAugOCR\" to support batch inference since samples_per_gpu > 1.\n",
            "  warnings.warn(warning_msg)\n",
            "/mmocr/mmocr/datasets/utils/loader.py:102: UserWarning: LmdbLoader is deprecated, please use AnnFileLoader instead.\n",
            "  'AnnFileLoader instead.', UserWarning)\n",
            "2022-03-18 07:04:53,221 - mmocr - INFO - Start running, host: root@366f3a61a508, work_dir: /mmocr/demo/tutorial_exps\n",
            "2022-03-18 07:04:53,223 - mmocr - INFO - Hooks will be executed in the following order:\n",
            "before_run:\n",
            "(VERY_HIGH   ) StepLrUpdaterHook                  \n",
            "(NORMAL      ) CheckpointHook                     \n",
            "(NORMAL      ) EvalHook                           \n",
            "(VERY_LOW    ) TextLoggerHook                     \n",
            " -------------------- \n",
            "before_train_epoch:\n",
            "(VERY_HIGH   ) StepLrUpdaterHook                  \n",
            "(NORMAL      ) EvalHook                           \n",
            "(LOW         ) IterTimerHook                      \n",
            "(VERY_LOW    ) TextLoggerHook                     \n",
            " -------------------- \n",
            "before_train_iter:\n",
            "(VERY_HIGH   ) StepLrUpdaterHook                  \n",
            "(NORMAL      ) EvalHook                           \n",
            "(LOW         ) IterTimerHook                      \n",
            " -------------------- \n",
            "after_train_iter:\n",
            "(ABOVE_NORMAL) OptimizerHook                      \n",
            "(NORMAL      ) CheckpointHook                     \n",
            "(NORMAL      ) EvalHook                           \n",
            "(LOW         ) IterTimerHook                      \n",
            "(VERY_LOW    ) TextLoggerHook                     \n",
            " -------------------- \n",
            "after_train_epoch:\n",
            "(NORMAL      ) CheckpointHook                     \n",
            "(NORMAL      ) EvalHook                           \n",
            "(VERY_LOW    ) TextLoggerHook                     \n",
            " -------------------- \n",
            "before_val_epoch:\n",
            "(LOW         ) IterTimerHook                      \n",
            "(VERY_LOW    ) TextLoggerHook                     \n",
            " -------------------- \n",
            "before_val_iter:\n",
            "(LOW         ) IterTimerHook                      \n",
            " -------------------- \n",
            "after_val_iter:\n",
            "(LOW         ) IterTimerHook                      \n",
            " -------------------- \n",
            "after_val_epoch:\n",
            "(VERY_LOW    ) TextLoggerHook                     \n",
            " -------------------- \n",
            "after_run:\n",
            "(VERY_LOW    ) TextLoggerHook                     \n",
            " -------------------- \n",
            "2022-03-18 07:04:53,226 - mmocr - INFO - workflow: [('train', 1)], max: 5 epochs\n",
            "2022-03-18 07:04:53,231 - mmocr - INFO - Checkpoints will be saved to /mmocr/demo/tutorial_exps by HardDiskBackend.\n",
            "2022-03-18 07:05:20,446 - mmocr - INFO - Epoch [1][40/250]\tlr: 1.250e-04, eta: 0:13:41, time: 0.679, data_time: 0.055, memory: 2142, loss_ce: 3.0851, loss: 3.0851\n",
            "2022-03-18 07:05:45,627 - mmocr - INFO - Epoch [1][80/250]\tlr: 1.250e-04, eta: 0:12:45, time: 0.630, data_time: 0.004, memory: 2142, loss_ce: 1.8488, loss: 1.8488\n",
            "2022-03-18 07:06:10,826 - mmocr - INFO - Epoch [1][120/250]\tlr: 1.250e-04, eta: 0:12:10, time: 0.630, data_time: 0.004, memory: 2142, loss_ce: 1.1972, loss: 1.1972\n",
            "2022-03-18 07:06:35,823 - mmocr - INFO - Epoch [1][160/250]\tlr: 1.250e-04, eta: 0:11:38, time: 0.625, data_time: 0.004, memory: 2142, loss_ce: 0.8279, loss: 0.8279\n",
            "2022-03-18 07:07:00,726 - mmocr - INFO - Epoch [1][200/250]\tlr: 1.250e-04, eta: 0:11:08, time: 0.623, data_time: 0.006, memory: 2142, loss_ce: 0.6695, loss: 0.6695\n",
            "2022-03-18 07:07:25,537 - mmocr - INFO - Epoch [1][240/250]\tlr: 1.250e-04, eta: 0:10:40, time: 0.620, data_time: 0.004, memory: 2142, loss_ce: 0.5306, loss: 0.5306\n",
            "2022-03-18 07:07:31,700 - mmocr - INFO - Saving checkpoint at 1 epochs\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 10/10, 4.5 task/s, elapsed: 2s, ETA:     0s"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "2022-03-18 07:07:38,433 - mmocr - INFO - \n",
            "Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 10 images now\n",
            "2022-03-18 07:07:38,442 - mmocr - INFO - Epoch(val) [1][2]\t0_word_acc: 0.8000, 0_word_acc_ignore_case: 0.8000, 0_word_acc_ignore_case_symbol: 0.8000, 0_char_recall: 0.8065, 0_char_precision: 0.8333, 0_1-N.E.D: 0.8000\n",
            "2022-03-18 07:08:05,298 - mmocr - INFO - Epoch [2][40/250]\tlr: 1.250e-04, eta: 0:09:52, time: 0.670, data_time: 0.055, memory: 2142, loss_ce: 0.4700, loss: 0.4700\n",
            "2022-03-18 07:08:30,055 - mmocr - INFO - Epoch [2][80/250]\tlr: 1.250e-04, eta: 0:09:28, time: 0.619, data_time: 0.004, memory: 2142, loss_ce: 0.3754, loss: 0.3754\n",
            "2022-03-18 07:08:54,819 - mmocr - INFO - Epoch [2][120/250]\tlr: 1.250e-04, eta: 0:09:03, time: 0.619, data_time: 0.004, memory: 2142, loss_ce: 0.3414, loss: 0.3414\n",
            "2022-03-18 07:09:19,594 - mmocr - INFO - Epoch [2][160/250]\tlr: 1.250e-04, eta: 0:08:38, time: 0.619, data_time: 0.004, memory: 2142, loss_ce: 0.2869, loss: 0.2869\n",
            "2022-03-18 07:09:44,404 - mmocr - INFO - Epoch [2][200/250]\tlr: 1.250e-04, eta: 0:08:14, time: 0.620, data_time: 0.004, memory: 2142, loss_ce: 0.2737, loss: 0.2737\n",
            "2022-03-18 07:10:09,451 - mmocr - INFO - Epoch [2][240/250]\tlr: 1.250e-04, eta: 0:07:50, time: 0.626, data_time: 0.004, memory: 2142, loss_ce: 0.2853, loss: 0.2853\n",
            "2022-03-18 07:10:15,717 - mmocr - INFO - Saving checkpoint at 2 epochs\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 10/10, 4.5 task/s, elapsed: 2s, ETA:     0s"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "2022-03-18 07:10:22,071 - mmocr - INFO - \n",
            "Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 10 images now\n",
            "2022-03-18 07:10:22,075 - mmocr - INFO - Epoch(val) [2][2]\t0_word_acc: 1.0000, 0_word_acc_ignore_case: 1.0000, 0_word_acc_ignore_case_symbol: 1.0000, 0_char_recall: 1.0000, 0_char_precision: 1.0000, 0_1-N.E.D: 1.0000\n",
            "2022-03-18 07:10:49,081 - mmocr - INFO - Epoch [3][40/250]\tlr: 1.250e-04, eta: 0:07:14, time: 0.673, data_time: 0.055, memory: 2142, loss_ce: 0.2701, loss: 0.2701\n",
            "2022-03-18 07:11:13,908 - mmocr - INFO - Epoch [3][80/250]\tlr: 1.250e-04, eta: 0:06:50, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2601, loss: 0.2601\n",
            "2022-03-18 07:11:38,740 - mmocr - INFO - Epoch [3][120/250]\tlr: 1.250e-04, eta: 0:06:25, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2371, loss: 0.2371\n",
            "2022-03-18 07:12:03,599 - mmocr - INFO - Epoch [3][160/250]\tlr: 1.250e-04, eta: 0:06:01, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2534, loss: 0.2534\n",
            "2022-03-18 07:12:28,426 - mmocr - INFO - Epoch [3][200/250]\tlr: 1.250e-04, eta: 0:05:37, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2663, loss: 0.2663\n",
            "2022-03-18 07:12:53,298 - mmocr - INFO - Epoch [3][240/250]\tlr: 1.250e-04, eta: 0:05:13, time: 0.622, data_time: 0.004, memory: 2142, loss_ce: 0.2332, loss: 0.2332\n",
            "2022-03-18 07:12:59,521 - mmocr - INFO - Saving checkpoint at 3 epochs\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 10/10, 4.4 task/s, elapsed: 2s, ETA:     0s"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "2022-03-18 07:13:05,910 - mmocr - INFO - \n",
            "Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 10 images now\n",
            "2022-03-18 07:13:05,916 - mmocr - INFO - Epoch(val) [3][2]\t0_word_acc: 1.0000, 0_word_acc_ignore_case: 1.0000, 0_word_acc_ignore_case_symbol: 1.0000, 0_char_recall: 1.0000, 0_char_precision: 1.0000, 0_1-N.E.D: 1.0000\n",
            "2022-03-18 07:13:32,892 - mmocr - INFO - Epoch [4][40/250]\tlr: 1.250e-05, eta: 0:04:40, time: 0.673, data_time: 0.055, memory: 2142, loss_ce: 0.2443, loss: 0.2443\n",
            "2022-03-18 07:13:57,706 - mmocr - INFO - Epoch [4][80/250]\tlr: 1.250e-05, eta: 0:04:16, time: 0.620, data_time: 0.003, memory: 2142, loss_ce: 0.2277, loss: 0.2277\n",
            "2022-03-18 07:14:22,555 - mmocr - INFO - Epoch [4][120/250]\tlr: 1.250e-05, eta: 0:03:51, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2369, loss: 0.2369\n",
            "2022-03-18 07:14:47,388 - mmocr - INFO - Epoch [4][160/250]\tlr: 1.250e-05, eta: 0:03:27, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2539, loss: 0.2539\n",
            "2022-03-18 07:15:12,233 - mmocr - INFO - Epoch [4][200/250]\tlr: 1.250e-05, eta: 0:03:03, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2252, loss: 0.2252\n",
            "2022-03-18 07:15:37,058 - mmocr - INFO - Epoch [4][240/250]\tlr: 1.250e-05, eta: 0:02:38, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2379, loss: 0.2379\n",
            "2022-03-18 07:15:43,277 - mmocr - INFO - Saving checkpoint at 4 epochs\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 10/10, 4.5 task/s, elapsed: 2s, ETA:     0s"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "2022-03-18 07:15:49,687 - mmocr - INFO - \n",
            "Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 10 images now\n",
            "2022-03-18 07:15:49,689 - mmocr - INFO - Epoch(val) [4][2]\t0_word_acc: 1.0000, 0_word_acc_ignore_case: 1.0000, 0_word_acc_ignore_case_symbol: 1.0000, 0_char_recall: 1.0000, 0_char_precision: 1.0000, 0_1-N.E.D: 1.0000\n",
            "2022-03-18 07:16:16,654 - mmocr - INFO - Epoch [5][40/250]\tlr: 1.250e-06, eta: 0:02:07, time: 0.672, data_time: 0.055, memory: 2142, loss_ce: 0.2473, loss: 0.2473\n",
            "2022-03-18 07:16:41,500 - mmocr - INFO - Epoch [5][80/250]\tlr: 1.250e-06, eta: 0:01:43, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2186, loss: 0.2186\n",
            "2022-03-18 07:17:06,303 - mmocr - INFO - Epoch [5][120/250]\tlr: 1.250e-06, eta: 0:01:19, time: 0.620, data_time: 0.004, memory: 2142, loss_ce: 0.2392, loss: 0.2392\n",
            "2022-03-18 07:17:31,166 - mmocr - INFO - Epoch [5][160/250]\tlr: 1.250e-06, eta: 0:00:54, time: 0.622, data_time: 0.004, memory: 2142, loss_ce: 0.2261, loss: 0.2261\n",
            "2022-03-18 07:17:56,010 - mmocr - INFO - Epoch [5][200/250]\tlr: 1.250e-06, eta: 0:00:30, time: 0.621, data_time: 0.004, memory: 2142, loss_ce: 0.2393, loss: 0.2393\n",
            "2022-03-18 07:18:20,905 - mmocr - INFO - Epoch [5][240/250]\tlr: 1.250e-06, eta: 0:00:06, time: 0.622, data_time: 0.004, memory: 2142, loss_ce: 0.2376, loss: 0.2376\n",
            "2022-03-18 07:18:27,106 - mmocr - INFO - Saving checkpoint at 5 epochs\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 10/10, 4.5 task/s, elapsed: 2s, ETA:     0s"
          ]
        },
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "2022-03-18 07:18:33,784 - mmocr - INFO - \n",
            "Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 10 images now\n",
            "2022-03-18 07:18:33,787 - mmocr - INFO - Epoch(val) [5][2]\t0_word_acc: 1.0000, 0_word_acc_ignore_case: 1.0000, 0_word_acc_ignore_case_symbol: 1.0000, 0_char_recall: 1.0000, 0_char_precision: 1.0000, 0_1-N.E.D: 1.0000\n"
          ]
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "mDVkK6yjpEU1",
        "outputId": "122c38d1-cb9d-4c67-804d-89c2aa6e8021"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Test and Visualize the Predictions\n",
        "\n",
        "For completeness, we also perform testing on the latest checkpoint and evaluate the results with hmean-iou metrics. The predictions are saved in the ./outputs file. "
      ],
      "metadata": {
        "id": "sklydRNXnfJk"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 22,
      "source": [
        "from mmocr.apis import init_detector, model_inference\n",
        "\n",
        "img = './tests/data/ocr_toy_dataset/imgs/1036169.jpg'\n",
        "checkpoint = \"./demo/tutorial_exps/epoch_5.pth\"\n",
        "out_file = 'outputs/1036169.jpg'\n",
        "\n",
        "model = init_detector(cfg, checkpoint, device=\"cuda:0\")\n",
        "if model.cfg.data.test['type'] == 'ConcatDataset':\n",
        "    model.cfg.data.test.pipeline = model.cfg.data.test['datasets'][0].pipeline\n",
        "\n",
        "\n",
        "result = model_inference(model, img)\n",
        "print(f'result: {result}')\n",
        "\n",
        "img = model.show_result(\n",
        "        img, result, out_file=out_file, show=False)\n",
        "\n",
        "mmcv.imwrite(img, out_file)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "load checkpoint from local path: ./demo/tutorial_exps/epoch_5.pth\n",
            "result: {'text': '03/09/2009', 'score': 0.9990636646747589}\n"
          ]
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "True"
            ]
          },
          "metadata": {},
          "execution_count": 22
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "-HbXY7uUpEU1",
        "outputId": "02012c83-6825-4171-aa35-fd048d939274"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 23,
      "source": [
        "# Visualize the results\n",
        "predicted_img = mmcv.imread('./outputs/1036169.jpg')\n",
        "plt.figure(figsize=(4, 4))\n",
        "plt.imshow(mmcv.bgr2rgb(predicted_img))\n",
        "plt.show()"
      ],
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 288x288 with 1 Axes>"
            ],
            "image/png": "[encoded data, 48188 characters]\n"
          },
          "metadata": {
            "needs_background": "light"
          }
        }
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 146
        },
        "id": "k3s27QIGQCnT",
        "outputId": "ccf798dc-2934-468f-e346-a051bbf97612"
      }
    }
  ]
}
