mmocr/demo/MMOCR_Tutorial.ipynb

2183 lines
1.3 MiB
Plaintext
Raw Normal View History

{
"nbformat": 4,
2021-08-25 16:41:07 +08:00
"nbformat_minor": 2,
"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": {
"2c92390d57494a4281fe95cc5e061092": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HBoxModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "HBoxView",
"_dom_classes": [],
"_model_name": "HBoxModel",
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.5.0",
"box_style": "",
"layout": "IPY_MODEL_a73f09aca9e24725b2e35347a902de89",
"_model_module": "@jupyter-widgets/controls",
"children": [
"IPY_MODEL_0ca81ff36c61401e9943825dccd671da",
"IPY_MODEL_728a93a11fe44e9e977ca8d75d67c7af",
"IPY_MODEL_330f4551fe984d1ea40e4bea51831533"
]
}
},
"a73f09aca9e24725b2e35347a902de89": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
},
"0ca81ff36c61401e9943825dccd671da": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "HTMLView",
"style": "IPY_MODEL_62a06be59f204e9ab16e4160db18e808",
"_dom_classes": [],
"description": "",
"_model_name": "HTMLModel",
"placeholder": "",
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"value": "100%",
"_view_count": null,
"_view_module_version": "1.5.0",
"description_tooltip": null,
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_aa7261dfcabb4b85be7611ea1b6f7046"
}
},
"728a93a11fe44e9e977ca8d75d67c7af": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FloatProgressModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "ProgressView",
"style": "IPY_MODEL_cd501d23a4d04be3897db97e3261f9c0",
"_dom_classes": [],
"description": "",
"_model_name": "FloatProgressModel",
"bar_style": "success",
"max": 145703066,
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"value": 145703066,
"_view_count": null,
"_view_module_version": "1.5.0",
"orientation": "horizontal",
"min": 0,
"description_tooltip": null,
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_c678a46976e8469b8e77ba23b266174f"
}
},
"330f4551fe984d1ea40e4bea51831533": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "HTMLView",
"style": "IPY_MODEL_9f7b0826508147c4be923443e8e6243b",
"_dom_classes": [],
"description": "",
"_model_name": "HTMLModel",
"placeholder": "",
"_view_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"value": " 139M/139M [00:12<00:00, 12.3MB/s]",
"_view_count": null,
"_view_module_version": "1.5.0",
"description_tooltip": null,
"_model_module": "@jupyter-widgets/controls",
"layout": "IPY_MODEL_3d80c260ae4f4ea0ab07b2ed8367600f"
}
},
"62a06be59f204e9ab16e4160db18e808": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "StyleView",
"_model_name": "DescriptionStyleModel",
"description_width": "",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.2.0",
"_model_module": "@jupyter-widgets/controls"
}
},
"aa7261dfcabb4b85be7611ea1b6f7046": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
},
"cd501d23a4d04be3897db97e3261f9c0": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ProgressStyleModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "StyleView",
"_model_name": "ProgressStyleModel",
"description_width": "",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.2.0",
"bar_color": null,
"_model_module": "@jupyter-widgets/controls"
}
},
"c678a46976e8469b8e77ba23b266174f": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
},
"9f7b0826508147c4be923443e8e6243b": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_view_name": "StyleView",
"_model_name": "DescriptionStyleModel",
"description_width": "",
"_view_module": "@jupyter-widgets/base",
"_model_module_version": "1.5.0",
"_view_count": null,
"_view_module_version": "1.2.0",
"_model_module": "@jupyter-widgets/controls"
}
},
"3d80c260ae4f4ea0ab07b2ed8367600f": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_view_name": "LayoutView",
"grid_template_rows": null,
"right": null,
"justify_content": null,
"_view_module": "@jupyter-widgets/base",
"overflow": null,
"_model_module_version": "1.2.0",
"_view_count": null,
"flex_flow": null,
"width": null,
"min_width": null,
"border": null,
"align_items": null,
"bottom": null,
"_model_module": "@jupyter-widgets/base",
"top": null,
"grid_column": null,
"overflow_y": null,
"overflow_x": null,
"grid_auto_flow": null,
"grid_area": null,
"grid_template_columns": null,
"flex": null,
"_model_name": "LayoutModel",
"justify_items": null,
"grid_row": null,
"max_height": null,
"align_content": null,
"visibility": null,
"align_self": null,
"height": null,
"min_height": null,
"padding": null,
"grid_auto_rows": null,
"grid_gap": null,
"max_width": null,
"order": null,
"_view_module_version": "1.2.0",
"grid_template_areas": null,
"object_position": null,
"object_fit": null,
"grid_auto_columns": null,
"margin": null,
"display": null,
"left": null
}
}
}
}
},
"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!"
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "jU9T31gbQmvs"
}
},
{
"cell_type": "markdown",
"source": [
"## Install MMOCR"
2021-08-25 16:41:07 +08:00
],
"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. "
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "q3fZP1LspEUp"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 12,
"source": [
"%cd .."
],
"outputs": [
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"/\n"
2021-08-25 16:41:07 +08:00
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "rB3qciTXpEUq",
"outputId": "4a32aea6-3b92-4da0-b096-c6127ae71957"
}
},
{
"cell_type": "markdown",
"source": [
"### Check NVCC and GCC compiler version"
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "mSkZOdrMpEUr"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 2,
"source": [
"!nvcc -V\n",
"!gcc --version"
],
"outputs": [
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"nvcc: NVIDIA (R) Cuda compiler driver\n",
"Copyright (c) 2005-2020 NVIDIA Corporation\n",
"Built on Wed_Jul_22_19:09:09_PDT_2020\n",
"Cuda compilation tools, release 11.0, V11.0.221\n",
"Build cuda_11.0_bu.TC445_37.28845127_0\n",
"gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0\n",
"Copyright (C) 2017 Free Software Foundation, Inc.\n",
"This is free software; see the source for copying conditions. There is NO\n",
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
"\n"
2021-08-25 16:41:07 +08:00
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "2DBpcKj2RDfu",
"outputId": "cbb83e76-b4df-418b-ea78-b8ceacdc07c2"
}
},
{
"cell_type": "markdown",
"source": [
"### Install Dependencies "
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "Tw7u_baQpEUs"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 13,
"source": [
"# Install torch dependencies: (use cu110 since colab has CUDA 11)\n",
"!pip install -U torch==1.7.0+cu110 torchvision==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html\n",
"\n",
"# Install mmcv-full thus we could use CUDA operators\n",
"!pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.6.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",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"Looking in links: https://download.pytorch.org/whl/torch_stable.html\n",
"Collecting torch==1.7.0+cu110\n",
"tcmalloc: large alloc 1137090560 bytes == 0x55fec2658000 @ 0x7ff4c85391e7 0x55febfab6a18 0x55febfa81987 0x55febfc00335 0x55febfb9aa48 0x55febfa85252 0x55febfb6396e 0x55febfa84ea9 0x55febfb76c0d 0x55febfaf90d8 0x55febfa8665a 0x55febfaf4d67 0x55febfa8665a 0x55febfaf4d67 0x55febfaf3dcc 0x55febfa86fec 0x55febfa871f1 0x55febfaf6318 0x55febfaf3c35 0x55febfa86fec 0x55febfa871f1 0x55febfaf6318 0x55febfaf3c35 0x55febfa86fec 0x55febfa871f1 0x55febfaf6318 0x55febfaf3dcc 0x55febfa86fec 0x55febfa871f1 0x55febfaf6318 0x55febfaf3c35\n",
"tcmalloc: large alloc 1421369344 bytes == 0x55ff062c2000 @ 0x7ff4c853a615 0x55febfa8202c 0x55febfb6217a 0x55febfa84e4d 0x55febfb76c0d 0x55febfaf90d8 0x55febfaf3c35 0x55febfa8673a 0x55febfaf4d67 0x55febfaf3c35 0x55febfa8673a 0x55febfaf4d67 0x55febfaf3c35 0x55febfa8673a 0x55febfaf4d67 0x55febfaf3c35 0x55febfa8673a 0x55febfaf4d67 0x55febfaf3c35 0x55febfa8673a 0x55febfaf4d67 0x55febfa8665a 0x55febfaf4d67 0x55febfaf3c35 0x55febfa8673a 0x55febfaf593b 0x55febfaf3c35 0x55febfa8673a 0x55febfaf4d67 0x55febfaf4235 0x55febfa8673a\n",
" Using cached https://download.pytorch.org/whl/cu110/torch-1.7.0%2Bcu110-cp37-cp37m-linux_x86_64.whl (1137.1 MB)\n",
"Collecting torchvision==0.8.0\n",
" Downloading torchvision-0.8.0-cp37-cp37m-manylinux1_x86_64.whl (11.8 MB)\n",
"\u001b[K |████████████████████████████████| 11.8 MB 258 kB/s \n",
"\u001b[?25hRequirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch==1.7.0+cu110) (3.7.4.3)\n",
"Collecting dataclasses\n",
" Downloading dataclasses-0.6-py3-none-any.whl (14 kB)\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torch==1.7.0+cu110) (1.19.5)\n",
"Requirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from torch==1.7.0+cu110) (0.16.0)\n",
"Requirement already satisfied: pillow>=4.1.1 in /usr/local/lib/python3.7/dist-packages (from torchvision==0.8.0) (7.1.2)\n",
"Installing collected packages: dataclasses, torch, torchvision\n",
" Attempting uninstall: torch\n",
" Found existing installation: torch 1.9.0+cu102\n",
" Uninstalling torch-1.9.0+cu102:\n",
" Successfully uninstalled torch-1.9.0+cu102\n",
" Attempting uninstall: torchvision\n",
" Found existing installation: torchvision 0.10.0+cu102\n",
" Uninstalling torchvision-0.10.0+cu102:\n",
" Successfully uninstalled torchvision-0.10.0+cu102\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",
"torchtext 0.10.0 requires torch==1.9.0, but you have torch 1.7.0+cu110 which is incompatible.\u001b[0m\n",
"Successfully installed dataclasses-0.6 torch-1.7.0+cu110 torchvision-0.8.0\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "display_data",
"data": {
"application/vnd.colab-display-data+json": {
"pip_warning": {
"packages": [
"dataclasses",
"torch",
"torchvision"
]
}
}
},
"metadata": {}
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"Looking in links: https://download.openmmlab.com/mmcv/dist/cu110/torch1.6.0/index.html\n",
"Requirement already satisfied: mmcv-full in /usr/local/lib/python3.7/dist-packages (1.3.11)\n",
"Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (21.0)\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (1.19.5)\n",
"Requirement already satisfied: yapf in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (0.31.0)\n",
"Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (7.1.2)\n",
"Requirement already satisfied: addict in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (2.4.0)\n",
"Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (3.13)\n",
"Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->mmcv-full) (2.4.7)\n",
"Requirement already satisfied: mmdet in /usr/local/lib/python3.7/dist-packages (2.15.1)\n",
"Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from mmdet) (3.2.2)\n",
"Requirement already satisfied: pycocotools in /usr/local/lib/python3.7/dist-packages (from mmdet) (2.0.2)\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmdet) (1.19.5)\n",
"Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from mmdet) (1.15.0)\n",
"Requirement already satisfied: terminaltables in /usr/local/lib/python3.7/dist-packages (from mmdet) (3.1.0)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet) (0.10.0)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmdet) (1.3.1)\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) (2.4.7)\n",
"Requirement already satisfied: setuptools>=18.0 in /usr/local/lib/python3.7/dist-packages (from pycocotools->mmdet) (57.4.0)\n",
"Requirement already satisfied: cython>=0.27.3 in /usr/local/lib/python3.7/dist-packages (from pycocotools->mmdet) (0.29.24)\n",
"fatal: destination path 'mmocr' already exists and is not an empty directory.\n",
"/mmocr\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from -r requirements/build.txt (line 2)) (1.19.5)\n",
"Requirement already satisfied: Polygon3 in /usr/local/lib/python3.7/dist-packages (from -r requirements/build.txt (line 3)) (3.0.9.1)\n",
"Requirement already satisfied: pyclipper in /usr/local/lib/python3.7/dist-packages (from -r requirements/build.txt (line 4)) (1.3.0)\n",
"Requirement already satisfied: torch>=1.1 in /usr/local/lib/python3.7/dist-packages (from -r requirements/build.txt (line 5)) (1.7.0+cu110)\n",
"Requirement already satisfied: imgaug in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 1)) (0.2.9)\n",
"Requirement already satisfied: lanms-proper in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 2)) (1.0.1)\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",
"Requirement already satisfied: rapidfuzz in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 9)) (1.5.0)\n",
"Requirement already satisfied: scikit-image in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 10)) (0.16.2)\n",
"Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 11)) (1.15.0)\n",
"Requirement already satisfied: terminaltables in /usr/local/lib/python3.7/dist-packages (from -r requirements/runtime.txt (line 12)) (3.1.0)\n",
"Requirement already satisfied: asynctest in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 1)) (0.13.0)\n",
"Requirement already satisfied: codecov in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 2)) (2.1.12)\n",
"Requirement already satisfied: flake8 in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 3)) (3.9.2)\n",
"Requirement already satisfied: isort in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 4)) (5.9.3)\n",
"Requirement already satisfied: kwarray in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 6)) (0.5.19)\n",
"Requirement already satisfied: pytest in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 8)) (3.6.4)\n",
"Requirement already satisfied: pytest-cov in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 9)) (2.9.0)\n",
"Requirement already satisfied: pytest-runner in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 10)) (5.3.1)\n",
"Requirement already satisfied: ubelt in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 11)) (0.10.0)\n",
"Requirement already satisfied: xdoctest>=0.10.0 in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 12)) (0.15.6)\n",
"Requirement already satisfied: yapf in /usr/local/lib/python3.7/dist-packages (from -r requirements/tests.txt (line 13)) (0.31.0)\n",
"Requirement already satisfied: dataclasses in /usr/local/lib/python3.7/dist-packages (from torch>=1.1->-r requirements/build.txt (line 5)) (0.6)\n",
"Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch>=1.1->-r requirements/build.txt (line 5)) (3.7.4.3)\n",
"Requirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from torch>=1.1->-r requirements/build.txt (line 5)) (0.16.0)\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: scipy in /usr/local/lib/python3.7/dist-packages (from imgaug->-r requirements/runtime.txt (line 1)) (1.4.1)\n",
"Requirement already satisfied: imageio in /usr/local/lib/python3.7/dist-packages (from imgaug->-r requirements/runtime.txt (line 1)) (2.4.1)\n",
"Requirement already satisfied: Shapely in /usr/local/lib/python3.7/dist-packages (from imgaug->-r requirements/runtime.txt (line 1)) (1.7.1)\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: Pillow in /usr/local/lib/python3.7/dist-packages (from imgaug->-r requirements/runtime.txt (line 1)) (7.1.2)\n",
"Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->-r requirements/runtime.txt (line 10)) (2.6.2)\n",
"Requirement already satisfied: PyWavelets>=0.4.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->-r requirements/runtime.txt (line 10)) (1.1.1)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->-r requirements/runtime.txt (line 4)) (0.10.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: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->-r requirements/runtime.txt (line 4)) (1.3.1)\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)) (2.4.7)\n",
"Requirement already satisfied: coverage in /usr/local/lib/python3.7/dist-packages (from codecov->-r requirements/tests.txt (line 2)) (5.5)\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.5.30)\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",
"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: pycodestyle<2.8.0,>=2.7.0 in /usr/local/lib/python3.7/dist-packages (from flake8->-r requirements/tests.txt (line 3)) (2.7.0)\n",
"Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from flake8->-r requirements/tests.txt (line 3)) (4.6.4)\n",
"Requirement already satisfied: pyflakes<2.4.0,>=2.3.0 in /usr/local/lib/python3.7/dist-packages (from flake8->-r requirements/tests.txt (line 3)) (2.3.1)\n",
"Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /usr/local/lib/python3.7/dist-packages (from flake8->-r requirements/tests.txt (line 3)) (0.6.1)\n",
"Requirement already satisfied: more-itertools>=4.0.0 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 8)) (8.8.0)\n",
"Requirement already satisfied: py>=1.5.0 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 8)) (1.10.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 8)) (0.7.1)\n",
"Requirement already satisfied: attrs>=17.4.0 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 8)) (21.2.0)\n",
"Requirement already satisfied: atomicwrites>=1.0 in /usr/local/lib/python3.7/dist-packages (from pytest->-r requirements/tests.txt (line 8)) (1.4.0)\n",
"Requirement already satisfied: ordered-set in /usr/local/lib/python3.7/dist-packages (from ubelt->-r requirements/tests.txt (line 11)) (4.0.2)\n",
"Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->flake8->-r requirements/tests.txt (line 3)) (3.5.0)\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-fvycazpz\n",
"Created temporary directory: /tmp/pip-req-tracker-we_a93c3\n",
"Initialized build tracking at /tmp/pip-req-tracker-we_a93c3\n",
"Created build tracker: /tmp/pip-req-tracker-we_a93c3\n",
"Entered build tracker: /tmp/pip-req-tracker-we_a93c3\n",
"Created temporary directory: /tmp/pip-install-ok1naoq0\n",
"Obtaining file:///mmocr\n",
" Added file:///mmocr to build tracker '/tmp/pip-req-tracker-we_a93c3'\n",
" Running setup.py (path:/mmocr/setup.py) egg_info for package from file:///mmocr\n",
" Created temporary directory: /tmp/pip-pip-egg-info-rei2_m70\n",
" Running command python setup.py egg_info\n",
" running egg_info\n",
" creating /tmp/pip-pip-egg-info-rei2_m70/mmocr.egg-info\n",
" writing /tmp/pip-pip-egg-info-rei2_m70/mmocr.egg-info/PKG-INFO\n",
" writing dependency_links to /tmp/pip-pip-egg-info-rei2_m70/mmocr.egg-info/dependency_links.txt\n",
" writing requirements to /tmp/pip-pip-egg-info-rei2_m70/mmocr.egg-info/requires.txt\n",
" writing top-level names to /tmp/pip-pip-egg-info-rei2_m70/mmocr.egg-info/top_level.txt\n",
" writing manifest file '/tmp/pip-pip-egg-info-rei2_m70/mmocr.egg-info/SOURCES.txt'\n",
" reading manifest template 'MANIFEST.in'\n",
" adding license file 'LICENSE'\n",
" writing manifest file '/tmp/pip-pip-egg-info-rei2_m70/mmocr.egg-info/SOURCES.txt'\n",
" Source in /mmocr has version 0.2.1, which satisfies requirement mmocr==0.2.1 from file:///mmocr\n",
" Removed mmocr==0.2.1 from file:///mmocr from build tracker '/tmp/pip-req-tracker-we_a93c3'\n",
"Requirement already satisfied: imgaug in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (0.2.9)\n",
"Requirement already satisfied: lanms-proper in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (1.0.1)\n",
"Requirement already satisfied: lmdb in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (0.99)\n",
"Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (3.2.2)\n",
"Requirement already satisfied: numba>=0.45.1 in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (0.51.2)\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (1.19.5)\n",
"Requirement already satisfied: Polygon3 in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (3.0.9.1)\n",
"Requirement already satisfied: pyclipper in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (1.3.0)\n",
"Requirement already satisfied: rapidfuzz in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (1.5.0)\n",
"Requirement already satisfied: scikit-image in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (0.16.2)\n",
"Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (1.15.0)\n",
"Requirement already satisfied: terminaltables in /usr/local/lib/python3.7/dist-packages (from mmocr==0.2.1) (3.1.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->mmocr==0.2.1) (0.34.0)\n",
"Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from numba>=0.45.1->mmocr==0.2.1) (57.4.0)\n",
"Requirement already satisfied: imageio in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.2.1) (2.4.1)\n",
"Requirement already satisfied: Shapely in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.2.1) (1.7.1)\n",
"Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.2.1) (7.1.2)\n",
"Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.2.1) (1.4.1)\n",
"Requirement already satisfied: opencv-python in /usr/local/lib/python3.7/dist-packages (from imgaug->mmocr==0.2.1) (4.1.2.30)\n",
"Requirement already satisfied: networkx>=2.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->mmocr==0.2.1) (2.6.2)\n",
"Requirement already satisfied: PyWavelets>=0.4.0 in /usr/local/lib/python3.7/dist-packages (from scikit-image->mmocr==0.2.1) (1.1.1)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmocr==0.2.1) (0.10.0)\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.2.1) (2.4.7)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmocr==0.2.1) (1.3.1)\n",
"Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->mmocr==0.2.1) (2.8.2)\n",
"Created temporary directory: /tmp/pip-unpack-khia4f7t\n",
"Installing collected packages: mmocr\n",
" Attempting uninstall: mmocr\n",
" Found existing installation: mmocr 0.2.1\n",
" Not sure how to uninstall: mmocr 0.2.1 - Check: /mmocr\n",
" Can't uninstall 'mmocr'. No files were found to uninstall.\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",
" 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",
" 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",
" mmocr 0.2.1 is already the active version in easy-install.pth\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.2.1\n",
"Removed build tracker: '/tmp/pip-req-tracker-we_a93c3'\n"
2021-08-25 16:41:07 +08:00
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
2021-08-25 16:41:07 +08:00
"height": 1000
},
"id": "DwDY3puNNmhe",
"tags": [
"outputPrepend"
],
"outputId": "f9a5ff35-f44f-459f-ca79-7f943938a99a"
}
},
{
"cell_type": "code",
"execution_count": 5,
"source": [
"!pip uninstall mmcv-full\n",
"!pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.6.0/index.html --no-cache-dir"
],
"outputs": [
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"Found existing installation: mmcv-full 1.3.11\n",
"Uninstalling mmcv-full-1.3.11:\n",
" Would remove:\n",
" /usr/local/lib/python3.7/dist-packages/mmcv/*\n",
" /usr/local/lib/python3.7/dist-packages/mmcv_full-1.3.11.dist-info/*\n",
"Proceed (y/n)? y\n",
" Successfully uninstalled mmcv-full-1.3.11\n",
"Looking in links: https://download.openmmlab.com/mmcv/dist/cu110/torch1.6.0/index.html\n",
"Collecting mmcv-full\n",
" Downloading mmcv-full-1.3.11.tar.gz (307 kB)\n",
"\u001b[K |████████████████████████████████| 307 kB 8.2 MB/s \n",
"\u001b[?25hRequirement already satisfied: addict in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (2.4.0)\n",
"Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (1.19.5)\n",
"Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (21.0)\n",
"Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (7.1.2)\n",
"Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (3.13)\n",
"Requirement already satisfied: yapf in /usr/local/lib/python3.7/dist-packages (from mmcv-full) (0.31.0)\n",
"Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->mmcv-full) (2.4.7)\n",
"Building wheels for collected packages: mmcv-full\n",
" Building wheel for mmcv-full (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for mmcv-full: filename=mmcv_full-1.3.11-cp37-cp37m-linux_x86_64.whl size=25895154 sha256=8cedf064bd88018d0cfba49032423d19888db695f5dc98dce606653bc40d8321\n",
" Stored in directory: /tmp/pip-ephem-wheel-cache-8t9ngi9u/wheels/4c/8f/1d/903456a291e5bf33d99cb03cb1bbc822e2c5d32c123b873ebe\n",
"Successfully built mmcv-full\n",
"Installing collected packages: mmcv-full\n",
"Successfully installed mmcv-full-1.3.11\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "display_data",
"data": {
"application/vnd.colab-display-data+json": {
"pip_warning": {
"packages": [
"mmcv"
]
}
}
},
"metadata": {}
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "_o0PrIixutjd",
"outputId": "e3a3fd44-9f4e-41e8-c6dc-58993edb4666",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 547
}
}
},
{
"cell_type": "markdown",
"source": [
"### Check Installed Dependencies Versions"
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "DY64JCc0pEUu"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 12,
"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",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"1.7.0+cu110 True\n",
"2.15.1\n",
"1.3.11\n",
"11.0\n",
"GCC 7.5\n",
"0.2.1\n",
"/mmocr\n",
"configs docs_zh_CN mmocr.egg-info requirements\t setup.py\n",
"demo\t LICENSE model-index.yml requirements.txt tests\n",
"docker\t MANIFEST.in README.md resources\t tools\n",
"docs\t mmocr\t README_zh-CN.md setup.cfg\n"
2021-08-25 16:41:07 +08:00
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "JABQfPwQN52g",
"outputId": "188c72bd-5aa2-4521-f63b-bf6a829633c0"
}
},
{
"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)."
2021-08-25 16:41:07 +08:00
],
"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."
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "59gHy8Y4pEUv"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 15,
"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",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"Use load_from_http loader\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"/mmocr/mmocr/apis/inference.py:48: 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"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"{'text': 'STAR', 'score': 0.9664112031459808}\n",
"\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[{'score': 0.9664112031459808, 'text': 'STAR'}]"
]
},
"metadata": {},
"execution_count": 15
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
2021-08-25 16:41:07 +08:00
"base_uri": "https://localhost:8080/"
},
2021-08-25 16:41:07 +08:00
"id": "iQQIVH9ApEUv",
"outputId": "34347c86-7e88-4e2f-d875-ff92533c2793"
}
},
{
"cell_type": "code",
"execution_count": 16,
"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>"
2021-08-25 16:41:07 +08:00
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAKIAAAD7CAYAAADpc08kAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9e9xlR1Xn/V1Ve+9znvPc+pruTjqX7iTkThIIBLwAAXFkwBej6GfED4LyOuO884rjjAgO6EdnZNRRX2+jOHgZdfR9GRQYUYKgoGiUSwhCQhISkpBLJ52+dz+3c9m7ar1/VNXe+5zn6U5CkplH5qz+PH3O2bt27br8atVaq1atElVlSlP6X03mf3UBpjQlmAJxSpuEpkCc0qagKRCntCloCsQpbQqaAnFKm4KeMSC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xIRPao6kER2QMcfmK5pUZKmmRsrKh4iGqYip2D4YCVu+7iyIc+RPEPn2Pv0ipbhwNyrxRiGFhhaC2VDRwIkwXlwSvdqiLzio0cY3FYYRzMeeHwH/531i67lHNe862YmS7kBVe8/BvZc965nPj936M6eRJFMRqe7WDIVMkRCu/oqKPjBKNKZYWBtZwqCoY2oxKL5BYnln5WsJJnrBQ5+179rWy54nJsdwZsUmKiIpCUNI2mFe/IyxGzoxE7K8dwbY35csTR972X1S/exQXf+73YxS2YLMmM0jRtPZfG6VE9eIOpoNsf0fMwKxYvwtAIlbEMjTKyUFnBi4DPajgn1TFzjszDrGp4pyqz5YjMO0Z4+p+6hc+/853s+yffxOL555+295+K1izAbwN3q
},
"metadata": {
"needs_background": "light"
}
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 268
},
"id": "0ab_YJnXpEUw",
"outputId": "0ee7b117-f75c-49b3-f4cd-6289713ae260"
}
},
{
"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)."
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "NgoH6qEcC9CL"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": null,
"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": [],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000,
"referenced_widgets": [
"2c92390d57494a4281fe95cc5e061092",
"a73f09aca9e24725b2e35347a902de89",
"0ca81ff36c61401e9943825dccd671da",
"728a93a11fe44e9e977ca8d75d67c7af",
"330f4551fe984d1ea40e4bea51831533",
"62a06be59f204e9ab16e4160db18e808",
"aa7261dfcabb4b85be7611ea1b6f7046",
"cd501d23a4d04be3897db97e3261f9c0",
"c678a46976e8469b8e77ba23b266174f",
"9f7b0826508147c4be923443e8e6243b",
"3d80c260ae4f4ea0ab07b2ed8367600f"
]
},
"id": "u0YyG9y0TzL4",
"outputId": "8ba20ef3-31bc-41a6-b596-42adf9fd83f8"
2021-08-25 16:41:07 +08:00
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 19,
"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>"
2021-08-25 16:41:07 +08:00
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh4AAAFQCAYAAADweXfLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9y45kSZKm94mo6jEzj4jMqu7hzDRnhhcQTQLkhivyCQhwxx1B8gFmxQfgs8yCOwJ8gga4Ighw1wMMAV4ADrrJHvSlblmZlRkR7m5HVUW4ENFjFlGRdSE7u7OartXeGe5mduxcVEV++eUXUXF3XsbLeBkv42W8jJfxMv4mhv5tn8DLeBkv42W8jJfxMv7/M16Ax8t4GS/jZbyMl/Ey/sbGC/B4GS/jZbyMl/EyXsbf2HgBHi/jZbyMl/EyXsbL+BsbL8DjZbyMl/EyXsbLeBl/Y+MFeLyMl/EyXsbLeBkv429sfGfAQ0T+UxH5P0XkT0Tkv/muvudlvIyX8TJexst4Gb87Q76LPh4iUoB/CfwnwF8Afwz8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ZJpIRa/NxGpEdbkkGWE8/2LooxU0C0qifTFLRqZvcePGZih4hQr+DTGGOzA1HRgYrhLRqNCFaUuo/9sPD8/gwhbOnrcGb3TdVJsggeFugDKoo8l/+ZmiEY6wKdhDJwAVADXa8c0GBHDmRa3Q0WoGeXYnPicAQjcmGNQegfAHGprOLBfO2OMYBC00UQwqVAa1xmOTySTDH5Lkbk64pPz6YyNQfgWv6XU8mkIS
},
"metadata": {
"needs_background": "light"
}
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 353
},
"id": "2-UHsqkZJFND",
"outputId": "08f51ae9-1124-46fd-f858-7e659e2f2f88"
}
},
{
"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)."
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "x-uRAtLa63sz"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 21,
"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",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"Use load_from_http loader\n",
"Use load_from_http loader\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"/mmocr/mmocr/apis/inference.py:48: 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:68: 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"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"{'filename': 'demo_text_ocr', 'text': ['OCBCBANK', 'soculationists', 'sanetal.enance.ounces', '70%', 'ROUND', 'SALE', 'ALLYEAR', 'is', 'SALE']}\n",
"\n"
2021-08-25 16:41:07 +08:00
]
},
{
"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": 21
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
2021-08-25 16:41:07 +08:00
"id": "xu68YizP8qu6",
"outputId": "8633e7eb-49c4-490b-d2fe-0d669383f156",
"colab": {
2021-08-25 16:41:07 +08:00
"base_uri": "https://localhost:8080/"
}
2021-08-25 16:41:07 +08:00
}
},
{
"cell_type": "code",
"execution_count": 22,
"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>"
2021-08-25 16:41:07 +08:00
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAh4AAAD1CAYAAAAf3/wiAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9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RoVjKApf1iivcN7j6zgfbenAW6+8yvLmOpc//QlKYnpGk8CTCtGpxRuaXusRtDV5epWgiEnQpHGUQRS026ycOUf71Dnqo0MG71zFSo0BtJcIvCSgdXxhxtRGwBgQsXjvUBLwdZUcqALRSFAzE7wZXgxxmUggcpyn0Y7GaU+c+Ux6qBkvs7836zbLHv7ufcbqI4DJTIQEdWIW26wXQoxUIAFRARE/Scmd3M/0HIOKESiRlPIKoHWM60wj7w23ogEfQl1XuLpO4DHEpSkSiBKUNRwcH+LKGt3XFEVBS0FIQFFEYprIObxAlmXkWYZvtWm32+l6Qkyz+ADNtSFICBGo+gAiuBDwSpHnLYbjMf3hgE7ejlGUgwO279zmje9/n9VTaywt9mgbS2YNq2trdNsd7t65w/qlp9/3mXw4bXacBUajPoNhP743rMV5NzP+DZ12F2MMed5CG4tCo5V5aD8wRyVz+6jaz4XjISJ/CPzhT76FSs7eIlrjJebFY+RhGpEIgCemB1RKufi8xcbTl7h79y6t5XXcuMDWY6j6oGqcETwZVhQEm2benkAAZOJISUdxImhtqYOibOWUQDUasCgVbT1A7/QpDm+QKYP2Dh+n7mhiNCB4GI1HZDqgr95m+PY27pefo/XFT6NPb+KrkqODIbZS5EtrhPVFdu7exxyN0GWFF8EdD6n39xkNBlAGf
},
"metadata": {
"needs_background": "light"
}
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "2AZqwCt09XqR",
"outputId": "c7941729-ffdc-4360-fa20-84b4dc9087f2",
"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"
2021-08-25 16:41:07 +08:00
],
"metadata": {
2021-08-25 16:41:07 +08:00
"id": "WQ9zzYMa9p9Y"
}
},
{
"cell_type": "code",
"execution_count": 24,
"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",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"--2021-08-23 03:17:39-- https://download.openmmlab.com/mmocr/data/wildreceipt.tar\n",
"Resolving download.openmmlab.com (download.openmmlab.com)... 47.254.186.225\n",
"Connecting to download.openmmlab.com (download.openmmlab.com)|47.254.186.225|: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 11.2MB/s in 16s \n",
"\n",
"2021-08-23 03:17:58 (10.8 MB/s) - wildreceipt.tar saved [185323520/185323520]\n",
"\n"
2021-08-25 16:41:07 +08:00
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
2021-08-25 16:41:07 +08:00
"id": "oALHgzmrAqik",
"outputId": "9f0ca247-37fb-44a4-f08e-9945b7885804",
"colab": {
"base_uri": "https://localhost:8080/"
}
2021-08-25 16:41:07 +08:00
}
},
{
"cell_type": "code",
"execution_count": 25,
"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",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"Use load_from_http loader\n",
"Use load_from_http loader\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"/mmocr/mmocr/apis/inference.py:48: 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"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"Use load_from_http loader\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"/usr/local/lib/python3.7/dist-packages/mmdet/datasets/utils.py:68: 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/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"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"{'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"
2021-08-25 16:41:07 +08:00
]
},
{
"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": 25
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
2021-08-25 16:41:07 +08:00
"id": "2KPRTdHVAGfF",
"outputId": "792c3a41-c447-4b94-b23b-dfb0ddbb5bdf",
"colab": {
2021-08-25 16:41:07 +08:00
"base_uri": "https://localhost:8080/"
}
2021-08-25 16:41:07 +08:00
}
},
{
"cell_type": "code",
"execution_count": 28,
"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>"
2021-08-25 16:41:07 +08:00
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAABBQAAAHhCAYAAADeeO2RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9ebxlV1Xv+x1zzrX3Pv2pOtWk+lRV+pYmQAwBLkEQAS9X+YiIAgF9iihXbK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UNih+lpzzOeuQXRCOJR8zpRiaMsE+/7k09x4ZZ1fOKz+/jx1z6FVSum+InXv5e3vf3lBC9US8JPvO59vO2dL+fzt+3mi198kB/70Wfxpjfewk//zLNZtXaCj3z0dgZLiZe8+An88Ov+kud/59VM9UwX7EwUPO36i/nJ17+bP3rHK3E+G2QKiOlfP/OzH+Jnf/aFrFs9hvhU72ykKPzxH3yGJ167nqc+/UIqEf7yw1+kFwLPee4T+Mk3vId3/MErwcPiUuTNv/tXvPrVz2bThllU4P0f+BIrZqd43ndcgncp60VDp14rjzdRVE3HUxxVUu752kF+/uc+wOatczgCK2c7vOZHb2LT1pUsLpS85MXv4porp/nlX34pb/rVP+WXf/OVjIdAKoWf/rk/4vf+rx/hvrsP8tM/9R62b1uPuAHf871P5JnPegKf+eTtHNl3nO9+2Q3g4Ja/+hLvfveXuWD1HEuLji1be7zxF17AO9/x1zzl2m1c99Tt4BOSHAllMFD+63/5b/zem19t8wrh1o/8Ex/+4
},
"metadata": {
"needs_background": "light"
}
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "96hqfaovAGhl",
"outputId": "1d5b91b6-8885-4bc2-ca9a-4925d780b4e9",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 498
}
}
},
{
"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."
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "PTWMzvd3E_h8"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": null,
"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": [
"--2021-05-17 11:39:10-- https://download.openmmlab.com/mmocr/data/wildreceipt.tar\n",
"Resolving download.openmmlab.com (download.openmmlab.com)... 47.75.20.25\n",
"Connecting to download.openmmlab.com (download.openmmlab.com)|47.75.20.25|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 185323520 (177M) [application/x-tar]\n",
"Saving to: wildreceipt.tar.3\n",
"\n",
"wildreceipt.tar.3 100%[===================>] 176.74M 17.7MB/s in 10s \n",
"\n",
"2021-05-17 11:39:21 (17.1 MB/s) - wildreceipt.tar.3 saved [185323520/185323520]\n",
"\n"
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
2021-08-25 16:41:07 +08:00
"id": "3VEW3PQrFZ0g",
"outputId": "885a4d2e-ca78-42ab-f4a2-dddd9a2d8321"
}
},
{
"cell_type": "code",
"execution_count": 29,
"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",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"Use load_from_http loader\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:01<00:00, 10.2MB/s]\n",
"[>>] 472/472, 21.1 task/s, elapsed: 22s, ETA: 0s{'macro_f1': 0.87641114}\n"
2021-08-25 16:41:07 +08:00
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "p0MHNwybo0iI",
"outputId": "2ac962be-9db7-4557-8853-7201c9e0696f"
}
},
{
"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). "
2021-08-25 16:41:07 +08:00
],
"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. "
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "FElJSp1vpEUz"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 30,
"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>"
2021-08-25 16:41:07 +08:00
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAABoCAYAAADo66t9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZ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UZUgkkBdjuZiGJxE3I+tZGcvolBGoYwGSSDQ5T75IOBAK01RpLH+Ve3XMeDfB94WkWckw/0/AP/Tr/qAkCa3LCqqskKJoigqjDbEkEYrhVvJIOscFt7lpSQG4h2vtEfhe14O1H5Wbv9P7xt4TUWCDXeIqD1CTL5TqXyPOHCp3CKRSKZjYupLvq4pDGVZpoVgLV48RheUZZUoiK5LCz94vE/huFYKn5+ZfF+dWCS08qDJ4XFIuCgmJCUxbTCz55AzWMiLJ4SQN5nsucq7tNseaceYjarc4fLYj1MIka5LjsZ7jxKNUZpYlCglRO/x0WfkJ5l7DwlpqBTIS0avr6L7u/dhf+8BSfsAPjEl+9ctaM90QzZwPgxb7g46lRQJSTY8QZKTQob8ScAHB+h9tDfA3rsI/CuDlt4yjKlS+3Xy1WcbnksNizNGYlR3op+M0gcOWQmibudrf6mQx0ZijkS/Mo/5u/0I5PlPVFm6yDA/g4EPISS0KoCoNC5EYpR9/4bHv32g/EwkZKxEZ6cW95HJsEckPw+Efc7q7h6O2ailPoXbe95BxfubkpyLz847DPtWhIIiPb8olDZ53NW+Lwz9gTuR/B0k/tXbcTc6HEb5NlLcByJRyEOV526Yt
},
"metadata": {
"needs_background": "light"
}
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
2021-08-25 16:41:07 +08:00
"base_uri": "https://localhost:8080/",
"height": 121
},
2021-08-25 16:41:07 +08:00
"id": "hZfd2pnqN5-Q",
"outputId": "70e81e99-983b-4c2d-d947-c83aaaa67e11"
}
},
{
"cell_type": "code",
"execution_count": 31,
"source": [
"# Inspect the labels of the annootation file\n",
"!cat tests/data/ocr_toy_dataset/label.txt"
],
"outputs": [
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"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"
2021-08-25 16:41:07 +08:00
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "F5M_FVVRN6Fw",
"outputId": "7d396de9-deb8-415c-eb21-cdc0339a7bec"
}
},
{
"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. "
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "i-GrV0xSkAc3"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 32,
"source": [
"from mmcv import Config\n",
"cfg = Config.fromfile('./configs/textrecog/sar/sar_r31_parallel_decoder_toy_dataset.py')"
],
2021-08-25 16:41:07 +08:00
"outputs": [],
"metadata": {
"id": "uFFH3yUgPEFj"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 33,
"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",
2021-08-25 16:41:07 +08:00
"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",
"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",
" 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='ResizeOCR',\n",
" height=48,\n",
" min_width=48,\n",
" max_width=160,\n",
" keep_aspect_ratio=True),\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', 'valid_ratio',\n",
" 'img_norm_cfg', 'ori_filename'\n",
" ])\n",
"]\n",
"dataset_type = 'OCRDataset'\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=10,\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",
"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",
" 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=10,\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='ResizeOCR',\n",
" height=48,\n",
" min_width=48,\n",
" max_width=160,\n",
" keep_aspect_ratio=True),\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'\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=10,\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='ResizeOCR',\n",
" height=48,\n",
" min_width=48,\n",
" max_width=160,\n",
" keep_aspect_ratio=True),\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'\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"
2021-08-25 16:41:07 +08:00
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "67OJ6oAvN6NA",
"outputId": "a20033ed-a5d3-45d6-bdb2-29feae88004e"
}
},
{
"cell_type": "markdown",
"source": [
"### Train the SAR Text Recognizer \n",
"Finally, we train the SAR text recognizer on the toy dataset for five epochs. "
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "TZj5vyqEmulE"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 34,
"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",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"/mmocr/mmocr/apis/train.py:80: 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",
"2021-08-23 03:27:59,310 - mmocr - INFO - Start running, host: root@0c6e7899740e, work_dir: /mmocr/demo/tutorial_exps\n",
"2021-08-23 03:27:59,311 - 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",
"2021-08-23 03:27:59,313 - mmocr - INFO - workflow: [('train', 1)], max: 5 epochs\n",
"2021-08-23 03:28:11,809 - mmocr - INFO - Epoch [1][40/250]\tlr: 1.250e-04, eta: 0:06:16, time: 0.312, data_time: 0.054, memory: 2149, loss_ce: 3.1350, loss: 3.1350\n",
"2021-08-23 03:28:22,325 - mmocr - INFO - Epoch [1][80/250]\tlr: 1.250e-04, eta: 0:05:36, time: 0.263, data_time: 0.002, memory: 2149, loss_ce: 2.0554, loss: 2.0554\n",
"2021-08-23 03:28:32,623 - mmocr - INFO - Epoch [1][120/250]\tlr: 1.250e-04, eta: 0:05:13, time: 0.257, data_time: 0.002, memory: 2149, loss_ce: 1.3114, loss: 1.3114\n",
"2021-08-23 03:28:42,724 - mmocr - INFO - Epoch [1][160/250]\tlr: 1.250e-04, eta: 0:04:55, time: 0.253, data_time: 0.002, memory: 2149, loss_ce: 0.9297, loss: 0.9297\n",
"2021-08-23 03:28:52,679 - mmocr - INFO - Epoch [1][200/250]\tlr: 1.250e-04, eta: 0:04:39, time: 0.249, data_time: 0.002, memory: 2149, loss_ce: 0.7357, loss: 0.7357\n",
"2021-08-23 03:29:02,564 - mmocr - INFO - Epoch [1][240/250]\tlr: 1.250e-04, eta: 0:04:26, time: 0.247, data_time: 0.002, memory: 2149, loss_ce: 0.5924, loss: 0.5924\n",
"2021-08-23 03:29:05,069 - mmocr - INFO - Saving checkpoint at 1 epochs\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 100/100, 15.6 task/s, elapsed: 6s, ETA: 0s"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"2021-08-23 03:29:13,961 - mmocr - INFO - \n",
"Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 100 images now\n",
"2021-08-23 03:29:13,975 - mmocr - INFO - Epoch(val) [1][13]\t0_word_acc: 0.9000, 0_word_acc_ignore_case: 0.9000, 0_word_acc_ignore_case_symbol: 0.9000, 0_char_recall: 0.9355, 0_char_precision: 0.9062, 0_1-N.E.D: 0.9000\n",
"2021-08-23 03:29:26,001 - mmocr - INFO - Epoch [2][40/250]\tlr: 1.250e-04, eta: 0:04:08, time: 0.300, data_time: 0.054, memory: 2149, loss_ce: 0.4840, loss: 0.4840\n",
"2021-08-23 03:29:36,000 - mmocr - INFO - Epoch [2][80/250]\tlr: 1.250e-04, eta: 0:03:57, time: 0.250, data_time: 0.002, memory: 2149, loss_ce: 0.3639, loss: 0.3639\n",
"2021-08-23 03:29:46,164 - mmocr - INFO - Epoch [2][120/250]\tlr: 1.250e-04, eta: 0:03:46, time: 0.254, data_time: 0.002, memory: 2149, loss_ce: 0.3488, loss: 0.3488\n",
"2021-08-23 03:29:56,310 - mmocr - INFO - Epoch [2][160/250]\tlr: 1.250e-04, eta: 0:03:36, time: 0.254, data_time: 0.002, memory: 2149, loss_ce: 0.3102, loss: 0.3102\n",
"2021-08-23 03:30:06,387 - mmocr - INFO - Epoch [2][200/250]\tlr: 1.250e-04, eta: 0:03:25, time: 0.252, data_time: 0.002, memory: 2149, loss_ce: 0.3109, loss: 0.3109\n",
"2021-08-23 03:30:16,397 - mmocr - INFO - Epoch [2][240/250]\tlr: 1.250e-04, eta: 0:03:14, time: 0.250, data_time: 0.002, memory: 2149, loss_ce: 0.3027, loss: 0.3027\n",
"2021-08-23 03:30:18,939 - mmocr - INFO - Saving checkpoint at 2 epochs\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 100/100, 15.4 task/s, elapsed: 6s, ETA: 0s"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"2021-08-23 03:30:27,896 - mmocr - INFO - \n",
"Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 100 images now\n",
"2021-08-23 03:30:27,903 - mmocr - INFO - Epoch(val) [2][13]\t0_word_acc: 0.9000, 0_word_acc_ignore_case: 0.9000, 0_word_acc_ignore_case_symbol: 0.9000, 0_char_recall: 0.9355, 0_char_precision: 0.9062, 0_1-N.E.D: 0.9000\n",
"2021-08-23 03:30:39,993 - mmocr - INFO - Epoch [3][40/250]\tlr: 1.250e-04, eta: 0:03:00, time: 0.301, data_time: 0.054, memory: 2149, loss_ce: 0.2920, loss: 0.2920\n",
"2021-08-23 03:30:49,971 - mmocr - INFO - Epoch [3][80/250]\tlr: 1.250e-04, eta: 0:02:50, time: 0.249, data_time: 0.002, memory: 2149, loss_ce: 0.2860, loss: 0.2860\n",
"2021-08-23 03:30:59,999 - mmocr - INFO - Epoch [3][120/250]\tlr: 1.250e-04, eta: 0:02:40, time: 0.251, data_time: 0.002, memory: 2149, loss_ce: 0.2801, loss: 0.2801\n",
"2021-08-23 03:31:10,073 - mmocr - INFO - Epoch [3][160/250]\tlr: 1.250e-04, eta: 0:02:29, time: 0.252, data_time: 0.002, memory: 2149, loss_ce: 0.2863, loss: 0.2863\n",
"2021-08-23 03:31:20,139 - mmocr - INFO - Epoch [3][200/250]\tlr: 1.250e-04, eta: 0:02:19, time: 0.252, data_time: 0.002, memory: 2149, loss_ce: 0.2881, loss: 0.2881\n",
"2021-08-23 03:31:30,175 - mmocr - INFO - Epoch [3][240/250]\tlr: 1.250e-04, eta: 0:02:09, time: 0.251, data_time: 0.002, memory: 2149, loss_ce: 0.2644, loss: 0.2644\n",
"2021-08-23 03:31:32,719 - mmocr - INFO - Saving checkpoint at 3 epochs\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 100/100, 15.3 task/s, elapsed: 7s, ETA: 0s"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"2021-08-23 03:31:41,616 - mmocr - INFO - \n",
"Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 100 images now\n",
"2021-08-23 03:31:41,622 - mmocr - INFO - Epoch(val) [3][13]\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",
"2021-08-23 03:31:53,746 - mmocr - INFO - Epoch [4][40/250]\tlr: 1.250e-05, eta: 0:01:56, time: 0.302, data_time: 0.054, memory: 2149, loss_ce: 0.2739, loss: 0.2739\n",
"2021-08-23 03:32:03,736 - mmocr - INFO - Epoch [4][80/250]\tlr: 1.250e-05, eta: 0:01:46, time: 0.250, data_time: 0.002, memory: 2149, loss_ce: 0.2507, loss: 0.2507\n",
"2021-08-23 03:32:13,784 - mmocr - INFO - Epoch [4][120/250]\tlr: 1.250e-05, eta: 0:01:36, time: 0.251, data_time: 0.002, memory: 2149, loss_ce: 0.2563, loss: 0.2563\n",
"2021-08-23 03:32:23,840 - mmocr - INFO - Epoch [4][160/250]\tlr: 1.250e-05, eta: 0:01:25, time: 0.251, data_time: 0.002, memory: 2149, loss_ce: 0.2738, loss: 0.2738\n",
"2021-08-23 03:32:33,902 - mmocr - INFO - Epoch [4][200/250]\tlr: 1.250e-05, eta: 0:01:15, time: 0.252, data_time: 0.002, memory: 2149, loss_ce: 0.2401, loss: 0.2401\n",
"2021-08-23 03:32:43,940 - mmocr - INFO - Epoch [4][240/250]\tlr: 1.250e-05, eta: 0:01:05, time: 0.251, data_time: 0.002, memory: 2149, loss_ce: 0.2558, loss: 0.2558\n",
"2021-08-23 03:32:46,493 - mmocr - INFO - Saving checkpoint at 4 epochs\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 100/100, 15.4 task/s, elapsed: 6s, ETA: 0s"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"2021-08-23 03:32:55,484 - mmocr - INFO - \n",
"Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 100 images now\n",
"2021-08-23 03:32:55,492 - mmocr - INFO - Epoch(val) [4][13]\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",
"2021-08-23 03:33:07,613 - mmocr - INFO - Epoch [5][40/250]\tlr: 1.250e-06, eta: 0:00:52, time: 0.302, data_time: 0.054, memory: 2149, loss_ce: 0.2637, loss: 0.2637\n",
"2021-08-23 03:33:17,612 - mmocr - INFO - Epoch [5][80/250]\tlr: 1.250e-06, eta: 0:00:42, time: 0.250, data_time: 0.002, memory: 2149, loss_ce: 0.2344, loss: 0.2344\n",
"2021-08-23 03:33:27,652 - mmocr - INFO - Epoch [5][120/250]\tlr: 1.250e-06, eta: 0:00:32, time: 0.251, data_time: 0.002, memory: 2149, loss_ce: 0.2523, loss: 0.2523\n",
"2021-08-23 03:33:37,712 - mmocr - INFO - Epoch [5][160/250]\tlr: 1.250e-06, eta: 0:00:22, time: 0.251, data_time: 0.002, memory: 2149, loss_ce: 0.2391, loss: 0.2391\n",
"2021-08-23 03:33:47,752 - mmocr - INFO - Epoch [5][200/250]\tlr: 1.250e-06, eta: 0:00:12, time: 0.251, data_time: 0.002, memory: 2149, loss_ce: 0.2556, loss: 0.2556\n",
"2021-08-23 03:33:57,763 - mmocr - INFO - Epoch [5][240/250]\tlr: 1.250e-06, eta: 0:00:02, time: 0.250, data_time: 0.002, memory: 2149, loss_ce: 0.2495, loss: 0.2495\n",
"2021-08-23 03:34:00,311 - mmocr - INFO - Saving checkpoint at 5 epochs\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 100/100, 15.4 task/s, elapsed: 6s, ETA: 0s"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "stream",
2021-08-25 16:41:07 +08:00
"name": "stderr",
"text": [
"2021-08-23 03:34:09,084 - mmocr - INFO - \n",
"Evaluateing tests/data/ocr_toy_dataset/label.lmdb with 100 images now\n",
"2021-08-23 03:34:09,090 - mmocr - INFO - Epoch(val) [5][13]\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"
2021-08-25 16:41:07 +08:00
]
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "mDVkK6yjpEU1",
"outputId": "9d0494c8-06c5-4c75-c898-71b679198b83"
}
},
{
"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. "
2021-08-25 16:41:07 +08:00
],
"metadata": {
"id": "sklydRNXnfJk"
}
},
{
"cell_type": "code",
2021-08-25 16:41:07 +08:00
"execution_count": 35,
"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",
2021-08-25 16:41:07 +08:00
"name": "stdout",
"text": [
"Use load_from_local loader\n",
"result: {'text': '03/09/2009', 'score': [0.9998674392700195, 0.9986717700958252, 0.9974325299263, 0.9999891519546509, 0.9976925849914551, 0.9968488812446594, 0.997633695602417, 0.9999977350234985, 0.999995231628418, 0.9993376135826111]}\n"
2021-08-25 16:41:07 +08:00
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"True"
]
},
"metadata": {},
"execution_count": 35
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
2021-08-25 16:41:07 +08:00
"base_uri": "https://localhost:8080/"
},
2021-08-25 16:41:07 +08:00
"id": "-HbXY7uUpEU1",
"outputId": "535374c9-aae8-4a80-caa7-45a8402daa22"
}
},
{
"cell_type": "code",
"execution_count": 36,
"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>"
2021-08-25 16:41:07 +08:00
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAQ4AAACBCAYAAAAxIFQcAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9d7glR3Xu/VtV1b3DyWeiNKNRHJQRMoNIApHEBQO2ccAYXwMmCIxJxjZgQGCMAxkDxoh4uSRzjYgiiGSBEEEggVBCQtJoZjQ5nrBjd1Wt+0f1PueMJIIQ8sz9vv0+z8w+u3eH6uquVSu8a5WoKkMMMcQQdwXmUDdgiCGG+H8PQ8ExxBBD3GUMBccQQwxxlzEUHEMMMcRdxlBwDDHEEHcZQ8ExxBBD3GXcI4JDRB4jIjeKyM0i8vJ74hpDDDHEoYP8pnkcImKBnwHnAluBHwJ/oqrX/0YvNMQQQxwy3BMax1nAzaq6UVUL4BPA794D1xliiCEOEe4JwbEGuG3J963VtiGGGOL/I3CH6sIich5wHsDIyMh9TzrppEPVlCGG+P8tNm3axN69e+WuHndPCI5twFFLvq+tth0EVX0v8F6ADRs26BVXXHEPNGWIIYb4RdiwYcOvddw9Yar8EFgvIseKSA48Gfj8PXCdIYYY4hDhN65xqKoXkecDXwEs8EFVve43fZ0hhhji0OEe8XGo6peAL90T5x5iiCEOPYbM0SGGGOIuYyg4hhhiiLuMoeAYYogh7jKGgmOIIYa4yxgKjiGGGOIu45AxR2+P26faye03yuJXYenfWv0tBx2jCydZus/CpoVj0GrbAnfudi3R219laZvk9jtW+y691p00aOkxB11cq//l4Gvp4r4L96pLj7+TZiw28nan1ztp+52dQO78fHeZY7j0FIt3dvvncccNd36GX6sBQ/zGcRgJDq0EQhIAqkuFRxq2Cgv7pHGoaUcElWpI6YK0qA4dDJSY9kOAmD51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6H7g8u5zTVY87znIiYk5aFfUn7vh9gPfJgyKv01x9Aylmanx9Q119G77qdct2sXp73nPaizGO8pd+/hxhf+JSOXXEKIhuKIo9B1E9T37sV9+kJ2f+sS8naLlX/w+2ijgUhOILmPlwaMhvhvhlY+g0P57773va/GEDXEqKWqhqja+9ktevnKZbp9pKY/XXuU7rrgAxq3bNe4eatufs1rdeP4mF61fEyvffu/aOy0NfqoWniN7XmNM3s17tmpcdcOjTt3abx1s+75qxfojpG6/uTItRpu26naDxpj1BhLjdFrjOn6IXr1vkjbQtRi46268Y/+UDeOjepPH/cYjft3aeyXGoug8cCMXnm/++mm8THdcs5DdOPfvULjlq0aN2/Rm5/yZN00NqpbRkb1W0/6E9XZOdVuV7d+8tP6gxWrdHe9rtefcYbeeN5ztbj6et33yQv11mc+Ta86YrlePT2lM1/4ksZeX9X7qp268E9D1OC9Ru81Fj2N+/fq9vNfpVctX6E3/P7vaziwU2MsNJaltq+/UW967BN0W6Op1515ms5d9DmNO3Zq3LZNd7z+9XrjipW6tTmit77ilRoPHFAteupn9uh1L3uJXrNsSn+09gjd/Y63adx2m8adO3XmU5/Ua04/RXc2GnrL7z1Juzdt1tjvqrbndMvHPqo/XL1cfzI9rZue+RyNt23TuHOf9n90jd7wsIfptmZdbz71ZD1w2WUaez2NrTm96rWv0Z8uX6Zbmg396SMfocVPrtZ421bd8fa3642rV+v2Zl2/d+QKLbfdVj2joGUM6jVo1CHuLu573/uq/hpj9rBwjqY5PkUcjCriPabfYbLfZzarM/2qV7LiT/8YXbkMVkwx8duPpXvyqbiojLTmwBeVhxVivUkYnSROLSNOTyETY5AZ5
},
"metadata": {
"needs_background": "light"
}
}
2021-08-25 16:41:07 +08:00
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 146
},
"id": "k3s27QIGQCnT",
"outputId": "c945a860-4358-4939-9ac6-c5d712b2c7d6"
}
}
]
}