mirror of https://github.com/NVlabs/SegFormer.git
1417 lines
1.3 MiB
Plaintext
1417 lines
1.3 MiB
Plaintext
|
{
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 0,
|
|||
|
"metadata": {
|
|||
|
"colab": {
|
|||
|
"name": "MMSegmentation Tutorial.ipynb",
|
|||
|
"provenance": [],
|
|||
|
"collapsed_sections": [],
|
|||
|
"include_colab_link": true
|
|||
|
},
|
|||
|
"kernelspec": {
|
|||
|
"name": "python3",
|
|||
|
"display_name": "Python 3"
|
|||
|
},
|
|||
|
"accelerator": "GPU",
|
|||
|
"widgets": {
|
|||
|
"application/vnd.jupyter.widget-state+json": {
|
|||
|
"40a3c0b2c7a44085b69b9c741df20b3e": {
|
|||
|
"model_module": "@jupyter-widgets/controls",
|
|||
|
"model_name": "HBoxModel",
|
|||
|
"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_ec96fb4251ea4b8ea268a2bc62b9c75b",
|
|||
|
"_model_module": "@jupyter-widgets/controls",
|
|||
|
"children": [
|
|||
|
"IPY_MODEL_dae4b284c5a944639991d29f4e79fac5",
|
|||
|
"IPY_MODEL_c78567afd0a6418781118ac9f4ecdea9"
|
|||
|
]
|
|||
|
}
|
|||
|
},
|
|||
|
"ec96fb4251ea4b8ea268a2bc62b9c75b": {
|
|||
|
"model_module": "@jupyter-widgets/base",
|
|||
|
"model_name": "LayoutModel",
|
|||
|
"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
|
|||
|
}
|
|||
|
},
|
|||
|
"dae4b284c5a944639991d29f4e79fac5": {
|
|||
|
"model_module": "@jupyter-widgets/controls",
|
|||
|
"model_name": "FloatProgressModel",
|
|||
|
"state": {
|
|||
|
"_view_name": "ProgressView",
|
|||
|
"style": "IPY_MODEL_32b7d27a143c41b5bb90f1d8e66a1c67",
|
|||
|
"_dom_classes": [],
|
|||
|
"description": "100%",
|
|||
|
"_model_name": "FloatProgressModel",
|
|||
|
"bar_style": "success",
|
|||
|
"max": 102567401,
|
|||
|
"_view_module": "@jupyter-widgets/controls",
|
|||
|
"_model_module_version": "1.5.0",
|
|||
|
"value": 102567401,
|
|||
|
"_view_count": null,
|
|||
|
"_view_module_version": "1.5.0",
|
|||
|
"orientation": "horizontal",
|
|||
|
"min": 0,
|
|||
|
"description_tooltip": null,
|
|||
|
"_model_module": "@jupyter-widgets/controls",
|
|||
|
"layout": "IPY_MODEL_55d75951f51c4ab89e32045c3d6db8a4"
|
|||
|
}
|
|||
|
},
|
|||
|
"c78567afd0a6418781118ac9f4ecdea9": {
|
|||
|
"model_module": "@jupyter-widgets/controls",
|
|||
|
"model_name": "HTMLModel",
|
|||
|
"state": {
|
|||
|
"_view_name": "HTMLView",
|
|||
|
"style": "IPY_MODEL_9d29e2d02731416d9852e9c7c08d1665",
|
|||
|
"_dom_classes": [],
|
|||
|
"description": "",
|
|||
|
"_model_name": "HTMLModel",
|
|||
|
"placeholder": "",
|
|||
|
"_view_module": "@jupyter-widgets/controls",
|
|||
|
"_model_module_version": "1.5.0",
|
|||
|
"value": " 97.8M/97.8M [00:10<00:00, 9.75MB/s]",
|
|||
|
"_view_count": null,
|
|||
|
"_view_module_version": "1.5.0",
|
|||
|
"description_tooltip": null,
|
|||
|
"_model_module": "@jupyter-widgets/controls",
|
|||
|
"layout": "IPY_MODEL_1bb2b93526cd421aa5d5b86d678932ab"
|
|||
|
}
|
|||
|
},
|
|||
|
"32b7d27a143c41b5bb90f1d8e66a1c67": {
|
|||
|
"model_module": "@jupyter-widgets/controls",
|
|||
|
"model_name": "ProgressStyleModel",
|
|||
|
"state": {
|
|||
|
"_view_name": "StyleView",
|
|||
|
"_model_name": "ProgressStyleModel",
|
|||
|
"description_width": "initial",
|
|||
|
"_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"
|
|||
|
}
|
|||
|
},
|
|||
|
"55d75951f51c4ab89e32045c3d6db8a4": {
|
|||
|
"model_module": "@jupyter-widgets/base",
|
|||
|
"model_name": "LayoutModel",
|
|||
|
"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
|
|||
|
}
|
|||
|
},
|
|||
|
"9d29e2d02731416d9852e9c7c08d1665": {
|
|||
|
"model_module": "@jupyter-widgets/controls",
|
|||
|
"model_name": "DescriptionStyleModel",
|
|||
|
"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"
|
|||
|
}
|
|||
|
},
|
|||
|
"1bb2b93526cd421aa5d5b86d678932ab": {
|
|||
|
"model_module": "@jupyter-widgets/base",
|
|||
|
"model_name": "LayoutModel",
|
|||
|
"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
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
},
|
|||
|
"pycharm": {
|
|||
|
"stem_cell": {
|
|||
|
"cell_type": "raw",
|
|||
|
"source": [],
|
|||
|
"metadata": {
|
|||
|
"collapsed": false
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
},
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "view-in-github",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"<a href=\"https://colab.research.google.com/github/open-mmlab/mmsegmentation/blob/master/demo/MMSegmentation_Tutorial.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "FVmnaxFJvsb8",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# MMSegmentation Tutorial\n",
|
|||
|
"Welcome to MMSegmentation! \n",
|
|||
|
"\n",
|
|||
|
"In this tutorial, we demo\n",
|
|||
|
"* How to do inference with MMSeg trained weight\n",
|
|||
|
"* How to train on your own dataset and visualize the results. "
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "QS8YHrEhbpas",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"## Install MMSegmentation\n",
|
|||
|
"This step may take several minutes. \n",
|
|||
|
"\n",
|
|||
|
"We use PyTorch 1.5.0 and CUDA 10.1 for this tutorial. You may install other versions by change the version number in pip install command. "
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "UWyLrLYaNEaL",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 170
|
|||
|
},
|
|||
|
"outputId": "35b19c63-d6f3-49e1-dcaa-aed3ecd85ed7"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# Check nvcc version\n",
|
|||
|
"!nvcc -V\n",
|
|||
|
"# Check GCC version\n",
|
|||
|
"!gcc --version"
|
|||
|
],
|
|||
|
"execution_count": 1,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"nvcc: NVIDIA (R) Cuda compiler driver\n",
|
|||
|
"Copyright (c) 2005-2019 NVIDIA Corporation\n",
|
|||
|
"Built on Sun_Jul_28_19:07:16_PDT_2019\n",
|
|||
|
"Cuda compilation tools, release 10.1, V10.1.243\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"
|
|||
|
],
|
|||
|
"name": "stdout"
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "Ki3WUBjKbutg",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 340
|
|||
|
},
|
|||
|
"outputId": "69f42fab-3f44-44d0-bd62-b73836f90a3d"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# Install PyTorch\n",
|
|||
|
"!pip install -U torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html\n",
|
|||
|
"# Install MMCV\n",
|
|||
|
"!pip install mmcv-full==latest+torch1.5.0+cu101 -f https://download.openmmlab.com/mmcv/dist/index.html"
|
|||
|
],
|
|||
|
"execution_count": 2,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Looking in links: https://download.pytorch.org/whl/torch_stable.html\n",
|
|||
|
"Requirement already up-to-date: torch==1.5.0+cu101 in /usr/local/lib/python3.6/dist-packages (1.5.0+cu101)\n",
|
|||
|
"Requirement already up-to-date: torchvision==0.6.0+cu101 in /usr/local/lib/python3.6/dist-packages (0.6.0+cu101)\n",
|
|||
|
"Requirement already satisfied, skipping upgrade: future in /usr/local/lib/python3.6/dist-packages (from torch==1.5.0+cu101) (0.16.0)\n",
|
|||
|
"Requirement already satisfied, skipping upgrade: numpy in /usr/local/lib/python3.6/dist-packages (from torch==1.5.0+cu101) (1.18.5)\n",
|
|||
|
"Requirement already satisfied, skipping upgrade: pillow>=4.1.1 in /usr/local/lib/python3.6/dist-packages (from torchvision==0.6.0+cu101) (7.0.0)\n",
|
|||
|
"Looking in links: https://download.openmmlab.com/mmcv/dist/index.html\n",
|
|||
|
"Collecting mmcv-full==latest+torch1.5.0+cu101\n",
|
|||
|
" Using cached https://download.openmmlab.com/mmcv/dist/latest/torch1.5.0/cu101/mmcv_full-latest%2Btorch1.5.0%2Bcu101-cp36-cp36m-manylinux1_x86_64.whl\n",
|
|||
|
"Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from mmcv-full==latest+torch1.5.0+cu101) (1.18.5)\n",
|
|||
|
"Requirement already satisfied: addict in /usr/local/lib/python3.6/dist-packages (from mmcv-full==latest+torch1.5.0+cu101) (2.2.1)\n",
|
|||
|
"Requirement already satisfied: yapf in /usr/local/lib/python3.6/dist-packages (from mmcv-full==latest+torch1.5.0+cu101) (0.30.0)\n",
|
|||
|
"Requirement already satisfied: pyyaml in /usr/local/lib/python3.6/dist-packages (from mmcv-full==latest+torch1.5.0+cu101) (3.13)\n",
|
|||
|
"Requirement already satisfied: opencv-python>=3 in /usr/local/lib/python3.6/dist-packages (from mmcv-full==latest+torch1.5.0+cu101) (4.1.2.30)\n",
|
|||
|
"Installing collected packages: mmcv-full\n",
|
|||
|
" Found existing installation: mmcv-full 1.0.0\n",
|
|||
|
" Uninstalling mmcv-full-1.0.0:\n",
|
|||
|
" Successfully uninstalled mmcv-full-1.0.0\n",
|
|||
|
"Successfully installed mmcv-full-1.0.0\n"
|
|||
|
],
|
|||
|
"name": "stdout"
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "nR-hHRvbNJJZ",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 374
|
|||
|
},
|
|||
|
"outputId": "ca6d9c48-0034-47cf-97b5-f31f529cc31c"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"!rm -rf mmsegmentation\n",
|
|||
|
"!git clone https://github.com/open-mmlab/mmsegmentation.git \n",
|
|||
|
"%cd mmsegmentation\n",
|
|||
|
"!pip install -e ."
|
|||
|
],
|
|||
|
"execution_count": 3,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Cloning into 'mmsegmentation'...\n",
|
|||
|
"remote: Enumerating objects: 485, done.\u001b[K\n",
|
|||
|
"remote: Counting objects: 100% (485/485), done.\u001b[K\n",
|
|||
|
"remote: Compressing objects: 100% (303/303), done.\u001b[K\n",
|
|||
|
"remote: Total 649 (delta 280), reused 317 (delta 171), pack-reused 164\u001b[K\n",
|
|||
|
"Receiving objects: 100% (649/649), 1.96 MiB | 3.99 MiB/s, done.\n",
|
|||
|
"Resolving deltas: 100% (364/364), done.\n",
|
|||
|
"/content/mmsegmentation\n",
|
|||
|
"Obtaining file:///content/mmsegmentation\n",
|
|||
|
"Requirement already satisfied: matplotlib in /usr/local/lib/python3.6/dist-packages (from mmseg==0.5.0+b2724da) (3.2.2)\n",
|
|||
|
"Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from mmseg==0.5.0+b2724da) (1.18.5)\n",
|
|||
|
"Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->mmseg==0.5.0+b2724da) (2.4.7)\n",
|
|||
|
"Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->mmseg==0.5.0+b2724da) (2.8.1)\n",
|
|||
|
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib->mmseg==0.5.0+b2724da) (1.2.0)\n",
|
|||
|
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib->mmseg==0.5.0+b2724da) (0.10.0)\n",
|
|||
|
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.1->matplotlib->mmseg==0.5.0+b2724da) (1.12.0)\n",
|
|||
|
"Installing collected packages: mmseg\n",
|
|||
|
" Found existing installation: mmseg 0.5.0+b2724da\n",
|
|||
|
" Can't uninstall 'mmseg'. No files were found to uninstall.\n",
|
|||
|
" Running setup.py develop for mmseg\n",
|
|||
|
"Successfully installed mmseg\n"
|
|||
|
],
|
|||
|
"name": "stdout"
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "mAE_h7XhPT7d",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 51
|
|||
|
},
|
|||
|
"outputId": "912ec9be-4103-40b8-91cc-4d31e9415f60"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# Check Pytorch installation\n",
|
|||
|
"import torch, torchvision\n",
|
|||
|
"print(torch.__version__, torch.cuda.is_available())\n",
|
|||
|
"\n",
|
|||
|
"# Check MMSegmentation installation\n",
|
|||
|
"import mmseg\n",
|
|||
|
"print(mmseg.__version__)"
|
|||
|
],
|
|||
|
"execution_count": 4,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"1.5.0+cu101 True\n",
|
|||
|
"0.5.0+b2724da\n"
|
|||
|
],
|
|||
|
"name": "stdout"
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "eUcuC3dUv32I",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"## Run Inference with MMSeg trained weight"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "2hd41IGaiNet",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 204
|
|||
|
},
|
|||
|
"outputId": "2834674e-deef-49d7-cd4c-db8dd1ae9733"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"!mkdir checkpoints\n",
|
|||
|
"!wget https://open-mmlab.s3.ap-northeast-2.amazonaws.com/mmsegmentation/models/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth -P checkpoints"
|
|||
|
],
|
|||
|
"execution_count": 5,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"--2020-07-09 19:13:21-- https://open-mmlab.s3.ap-northeast-2.amazonaws.com/mmsegmentation/models/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth\n",
|
|||
|
"Resolving open-mmlab.s3.ap-northeast-2.amazonaws.com (open-mmlab.s3.ap-northeast-2.amazonaws.com)... 52.219.56.140\n",
|
|||
|
"Connecting to open-mmlab.s3.ap-northeast-2.amazonaws.com (open-mmlab.s3.ap-northeast-2.amazonaws.com)|52.219.56.140|:443... connected.\n",
|
|||
|
"HTTP request sent, awaiting response... 200 OK\n",
|
|||
|
"Length: 196205945 (187M) [application/x-www-form-urlencoded]\n",
|
|||
|
"Saving to: ‘checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth’\n",
|
|||
|
"\n",
|
|||
|
"pspnet_r50-d8_512x1 100%[===================>] 187.12M 11.8MB/s in 18s \n",
|
|||
|
"\n",
|
|||
|
"2020-07-09 19:13:40 (10.4 MB/s) - ‘checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth’ saved [196205945/196205945]\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"name": "stdout"
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "H8Fxg8i-wHJE",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {}
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"from mmseg.apis import inference_segmentor, init_segmentor, show_result_pyplot\n",
|
|||
|
"from mmseg.core.evaluation import get_palette"
|
|||
|
],
|
|||
|
"execution_count": 6,
|
|||
|
"outputs": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "umk8sJ0Xuace",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {}
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"config_file = 'configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py'\n",
|
|||
|
"checkpoint_file = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'"
|
|||
|
],
|
|||
|
"execution_count": 7,
|
|||
|
"outputs": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "nWlQFuTgudxu",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {}
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# build the model from a config file and a checkpoint file\n",
|
|||
|
"model = init_segmentor(config_file, checkpoint_file, device='cuda:0')"
|
|||
|
],
|
|||
|
"execution_count": 8,
|
|||
|
"outputs": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "izFv6pSRujk9",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {}
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# test a single image\n",
|
|||
|
"img = 'demo/demo.png'\n",
|
|||
|
"result = inference_segmentor(model, img)"
|
|||
|
],
|
|||
|
"execution_count": 9,
|
|||
|
"outputs": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "bDcs9udgunQK",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 504
|
|||
|
},
|
|||
|
"outputId": "8221fdb1-92af-4d7c-e65b-c7adf0f5a8af"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# show the results\n",
|
|||
|
"show_result_pyplot(model, img, result, get_palette('cityscapes'))"
|
|||
|
],
|
|||
|
"execution_count": 10,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"/content/mmsegmentation/mmseg/models/segmentors/base.py:265: UserWarning: show==False and out_file is not specified, only result image will be returned\n",
|
|||
|
" warnings.warn('show==False and out_file is not specified, only '\n"
|
|||
|
],
|
|||
|
"name": "stderr"
|
|||
|
},
|
|||
|
{
|
|||
|
"output_type": "display_data",
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA20AAAHFCAYAAABhIhFgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9W49sS3Lf94vMtVZVdffe+1zmzI0URVKiLJkWDBiGZfhBMiDJ8ovhV9sfQE/+AH7yB5EBPRqG/SLAgAwZfrJhywRhQTKoi6nRcIYzHJ7bPvvS3VW1Lpnhh4jMlVXdvc8h54x4JFUAe3d31Vq5c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KSkZUFSInYR7aL10YVoUNBW2VIgBkK/QViYp4mcMkGMhWS3KGrd2kqQYHNRx7AwN2dOwbxd1Vrpc7W+k02bCuRlYcmZGJINtYTKmEQCmhOCCwdZQfzqWgtIEoIUQK51SWZnWrkoEQ52SyNV0Q2CRAO6V1dbYjwyHifevvqC3c0zdtfXSBCm48TnH3/Ms2+9z3vPn9P7nG22G8I8Mx1HpiUQ48aYGY3n1ZezhMDuekfKsGRlGQ8GZJeMhg7I1aqc6xYIEMuWSGz7juvlNVG+y6xlrdr7dwi5WLvqOjIRbZ+d+/BOyUZe2eVbuj6whOCWh6dJgIiQ/N74rwhwg1NwJs3Prw7HGqF39t7noM5mqZkHafa9CDH2iBtWiif2yxTsnLUaugQxPqMZMCB30wckzdVTGyiWf4/vL4DB11zfdbx48T7DsOHzL77
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1080x720 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"tags": [],
|
|||
|
"needs_background": "light"
|
|||
|
}
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "Ta51clKX4cwM",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"## Train a semantic segmentation model on a new dataset\n",
|
|||
|
"\n",
|
|||
|
"To train on a customized dataset, the following steps are neccessary. \n",
|
|||
|
"1. Add a new dataset class. \n",
|
|||
|
"2. Create a config file accordingly. \n",
|
|||
|
"3. Perform training and evaluation. "
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "AcZg6x_K5Zs3",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"### Add a new dataset\n",
|
|||
|
"\n",
|
|||
|
"Datasets in MMSegmentation require image and semantic segmentation maps to be placed in folders with the same perfix. To support a new dataset, we may need to modify the original file structure. \n",
|
|||
|
"\n",
|
|||
|
"In this tutorial, we give an example of converting the dataset. You may refer to [docs](https://github.com/open-mmlab/mmsegmentation/docs/tutorials/new_dataset.md) for details about dataset reorganization. \n",
|
|||
|
"\n",
|
|||
|
"We use [Standord Background Dataset](http://dags.stanford.edu/projects/scenedataset.html) as an example. The dataset contains 715 images chosen from existing public datasets [LabelMe](http://labelme.csail.mit.edu), [MSRC](http://research.microsoft.com/en-us/projects/objectclassrecognition), [PASCAL VOC](http://pascallin.ecs.soton.ac.uk/challenges/VOC) and [Geometric Context](http://www.cs.illinois.edu/homes/dhoiem/). Images from these datasets are mainly outdoor scenes, each containing approximately 320-by-240 pixels. \n",
|
|||
|
"In this tutorial, we use the region annotations as labels. There are 8 classes in total, i.e. sky, tree, road, grass, water, building, mountain, and foreground object. "
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "TFIt7MHq5Wls",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 204
|
|||
|
},
|
|||
|
"outputId": "5e56d5dc-4f1c-4d7c-f833-51cfdbf8d481"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# download and unzip\n",
|
|||
|
"!wget http://dags.stanford.edu/data/iccv09Data.tar.gz -O standford_background.tar.gz\n",
|
|||
|
"!tar xf standford_background.tar.gz"
|
|||
|
],
|
|||
|
"execution_count": 11,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"--2020-07-09 19:13:50-- http://dags.stanford.edu/data/iccv09Data.tar.gz\n",
|
|||
|
"Resolving dags.stanford.edu (dags.stanford.edu)... 171.64.68.10\n",
|
|||
|
"Connecting to dags.stanford.edu (dags.stanford.edu)|171.64.68.10|:80... connected.\n",
|
|||
|
"HTTP request sent, awaiting response... 200 OK\n",
|
|||
|
"Length: 14727974 (14M) [application/x-gzip]\n",
|
|||
|
"Saving to: ‘standford_background.tar.gz’\n",
|
|||
|
"\n",
|
|||
|
"standford_backgroun 100%[===================>] 14.04M 3.22MB/s in 4.4s \n",
|
|||
|
"\n",
|
|||
|
"2020-07-09 19:13:55 (3.22 MB/s) - ‘standford_background.tar.gz’ saved [14727974/14727974]\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"name": "stdout"
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "78LIci7F9WWI",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 377
|
|||
|
},
|
|||
|
"outputId": "a7f339c7-a071-40db-f30d-44028dd2ce1c"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# Let's take a look at the dataset\n",
|
|||
|
"import mmcv\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"\n",
|
|||
|
"img = mmcv.imread('iccv09Data/images/6000124.jpg')\n",
|
|||
|
"plt.figure(figsize=(8, 6))\n",
|
|||
|
"plt.imshow(mmcv.bgr2rgb(img))\n",
|
|||
|
"plt.show()"
|
|||
|
],
|
|||
|
"execution_count": 12,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "display_data",
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAdsAAAFoCAYAAAAfJFHvAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9yY4023bf99tdNJlZ9XWnuSIPKV4YMic0bMC2PDPggQDPPLX9ABr5AfwsGnjsJxDgZ9BUMm2KtsXbUTzna6oqM6PZrQdr78iouudSguEDXgq1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1C07LtotTFkihoF13elhmuEINemjCaVGr2hwSiyKihlQclvC+CGHts5nLGgVQVbsJ1DNfZHC5zHnATU6twJW2YYxoGh64kps6yeh/MZTSSlLOdvIRXIBQoKbSy5ZAG6nClyqZstMkrTWUffdfR9L8fSqtrFgjEW5zphn6p9UPU+l1IIywI5M/QOA/Q1EKgPijAa7eLkCmmZVFWUeCLo+tmd3I4qzUocgCx7I5VMzJmYMqGxdb9j/FRg+y+Af6SU+jkCsv898D/+ro33ANXAr4Fi13XPgLht00DRWourlNM+uk0pEa/pGdi27zZwUUptlEEzsA1gG9i137fjtWhz86xz3sCk3di23z1da62lqw9Ri0hfRuMt8t2fSwNeFyyNqrper1uU3yLoZVnIWSLUeZ6JMQq4xEjKGV3ndFmWbX7311BKoe975nlmXVfWdcU5x/F45Hg8bud0urunH4+YSj12Xcc4jvR9z+Vy2a6j7/ttrs7
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 576x432 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"tags": [],
|
|||
|
"needs_background": "light"
|
|||
|
}
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "L5mNQuc2GsVE",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"We need to convert the annotation into semantic map format as an image."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "WnGZfribFHCx",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {}
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"import os.path as osp\n",
|
|||
|
"import numpy as np\n",
|
|||
|
"from PIL import Image\n",
|
|||
|
"# convert dataset annotation to semantic segmentation map\n",
|
|||
|
"data_root = 'iccv09Data'\n",
|
|||
|
"img_dir = 'images'\n",
|
|||
|
"ann_dir = 'labels'\n",
|
|||
|
"# define class and plaette for better visualization\n",
|
|||
|
"classes = ('sky', 'tree', 'road', 'grass', 'water', 'bldg', 'mntn', 'fg obj')\n",
|
|||
|
"palette = [[128, 128, 128], [129, 127, 38], [120, 69, 125], [53, 125, 34], \n",
|
|||
|
" [0, 11, 123], [118, 20, 12], [122, 81, 25], [241, 134, 51]]\n",
|
|||
|
"for file in mmcv.scandir(osp.join(data_root, ann_dir), suffix='.regions.txt'):\n",
|
|||
|
" seg_map = np.loadtxt(osp.join(data_root, ann_dir, file)).astype(np.uint8)\n",
|
|||
|
" seg_img = Image.fromarray(seg_map).convert('P')\n",
|
|||
|
" seg_img.putpalette(np.array(palette, dtype=np.uint8))\n",
|
|||
|
" seg_img.save(osp.join(data_root, ann_dir, file.replace('.regions.txt', \n",
|
|||
|
" '.png')))"
|
|||
|
],
|
|||
|
"execution_count": 13,
|
|||
|
"outputs": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "5MCSS9ABfSks",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 377
|
|||
|
},
|
|||
|
"outputId": "d093e054-8db3-40e5-a800-061de844597f"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# Let's take a look at the segmentation map we got\n",
|
|||
|
"import matplotlib.patches as mpatches\n",
|
|||
|
"img = Image.open('iccv09Data/labels/6000124.png')\n",
|
|||
|
"plt.figure(figsize=(8, 6))\n",
|
|||
|
"im = plt.imshow(np.array(img.convert('RGB')))\n",
|
|||
|
"\n",
|
|||
|
"# create a patch (proxy artist) for every color \n",
|
|||
|
"patches = [mpatches.Patch(color=np.array(palette[i])/255., \n",
|
|||
|
" label=classes[i]) for i in range(8)]\n",
|
|||
|
"# put those patched as legend-handles into the legend\n",
|
|||
|
"plt.legend(handles=patches, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., \n",
|
|||
|
" fontsize='large')\n",
|
|||
|
"\n",
|
|||
|
"plt.show()"
|
|||
|
],
|
|||
|
"execution_count": 14,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "display_data",
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAj4AAAFoCAYAAABXDfHbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzdeXhU5dk/8O8ze2ay73tCEvYlYFgEBAUrarWvUBQ3iksVtbW0pbba0vatb7V0ubRVa+tWtSoWlFrx54JWi2hV9n0LIZAQsu/JZPY5z++PhBAgIducWZLv57rmInOW59wTJjP3eVYhpQQRERHRcKAJdABERERE/sLEh4iIiIYNJj5EREQ0bDDxISIiomGDiQ8RERENG0x8iIiIaNhQLfERQlwlhCgUQhwTQjyk1nWIiIiI+kqoMY+PEEIL4CiAKwCcArAdwM1SykM+vxgRERFRH6lV4zMdwDEp5XEppQvAWgDXqXQtIiIioj7RqVRuGoCyLs9PAZjR9QAhxHIAywFArxcFCfEGlUIhIuo/KQGlzh3oMCiEVHuUOillgq/L3blzZ6JOp3sBwASwb25vpBCi2ev1vqQoyl8LCgpc5x6gVuLTKynlcwCeA4C0VJO8Z3lWoEIhIjqPdCmwvVgFeAMdCYWK39dZS9UoV6fTvZCcnDw2ISGhUaPRcJ2pC5BSwuVy6SsqKr7X0tJyEYDbzj1GrcyxHEBGl+fpHduIiIKelBLg1wsFjwkJCQktTHp6J4SA0Wh0Z2VlNQO4pLtj1Krx2Q5gpBBiBNoTnpsA3KLStYiIfMpb7IBzczNreyhYaJj09E/H70vb3T5VEh8ppUcIcT+ADzsu/KKU8qAa1yIi8jmvBBxKoKMgIhWo1sdHSvk+gPfVKp+ISA1KsweKlVU9RIOxcuXK1OLiYuOGDRtOBDqWcwWsczM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774osvxgDAkiVLmkpKSkxPP/10rNPpFE6nU2zevNm8a9cu1fr4MPEhoqDhPeGA7dVq1vbQoM2dGY+lN2Rc8BijQYPv3ZWLnCyzn6LynbCwaFXnbOhP+T/+8Y+rHnvssZSIiIjJa9asOW9E1rJly5p+8IMfVN5yyy054eHhU8aPHz/+gw8+iAKAmJgY5YMPPjj65ptvxiYnJ09KSkrKf/DBB9MdDodqGamQMvAfMGmpJnnP8qxAh0FEAeYpssP5UWOgwxiwby/NQnLimRvV19eX4QSbUvxu3px45GZbkJTQt0qDN94+haLjbYO+7u/rrDullFMHXdA59u7dW5Kfn1/n63KHur1798bn5+dnn7udfXyIKCgoTZ72dbWIBsigF4iLNWLyhGiYw7R9Pi8m2oCYKBcam929H0whj01dRBQUnJ82wb0lJGa8pyCVnGTCnbdm9SvpAYArLkvEgnmJKkVFwYaJDxERhbyvXZqAhV9PHfD5WRlm3HN7NgwGfi0OdfwfJqKAkm4Fru2tkC2ctIcGzmLWISJ84L039HoNYqMNmDU9FkkJPQ5QoiGAfXyIKLDcEu7trUDgx1lQiNHrBMzm9mYtXwxL12gEZk+PQ1OTG9W1zkGXR8GJiQ8REYWknBEWLL524M1bNDyxqYuIiEKSACCE6Hz4yuwZsbhmQbLPyqPgwsSHiAJGqXfDc9TOZi7qt9xsC7Iz1Zl4MDrKgKz0MORPiOLMzkMQEx8iChjvKSdcX7QEOgwKQdMLYlCQf94kwT4TE23ANVckITpSD62WyY+/FRYWGoQQBW637+dWYh8fIiKiHnx7aTY2f1GHr3act75mQP36+tX5tha7at/h5sgwzy/W/3SvWuUHEhMfIgoI52dN8Ja7Ah0GhZDcERYU5EcDAJL
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 576x432 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"tags": [],
|
|||
|
"needs_background": "light"
|
|||
|
}
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "WbeLYCp2k5hl",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {}
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"# split train/val set randomly\n",
|
|||
|
"split_dir = 'splits'\n",
|
|||
|
"mmcv.mkdir_or_exist(osp.join(data_root, split_dir))\n",
|
|||
|
"filename_list = [osp.splitext(filename)[0] for filename in mmcv.scandir(\n",
|
|||
|
" osp.join(data_root, ann_dir), suffix='.png')]\n",
|
|||
|
"with open(osp.join(data_root, split_dir, 'train.txt'), 'w') as f:\n",
|
|||
|
" # select first 4/5 as train set\n",
|
|||
|
" train_length = int(len(filename_list)*4/5)\n",
|
|||
|
" f.writelines(line + '\\n' for line in filename_list[:train_length])\n",
|
|||
|
"with open(osp.join(data_root, split_dir, 'val.txt'), 'w') as f:\n",
|
|||
|
" # select last 1/5 as train set\n",
|
|||
|
" f.writelines(line + '\\n' for line in filename_list[train_length:])"
|
|||
|
],
|
|||
|
"execution_count": 15,
|
|||
|
"outputs": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "HchvmGYB_rrO",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"After downloading the data, we need to implement `load_annotations` function in the new dataset class `StandfordBackgroundDataset`."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "LbsWOw62_o-X",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {}
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"from mmseg.datasets.builder import DATASETS\n",
|
|||
|
"from mmseg.datasets.custom import CustomDataset\n",
|
|||
|
"\n",
|
|||
|
"@DATASETS.register_module()\n",
|
|||
|
"class StandfordBackgroundDataset(CustomDataset):\n",
|
|||
|
" CLASSES = classes\n",
|
|||
|
" PALETTE = palette\n",
|
|||
|
" def __init__(self, split, **kwargs):\n",
|
|||
|
" super().__init__(img_suffix='.jpg', seg_map_suffix='.png', \n",
|
|||
|
" split=split, **kwargs)\n",
|
|||
|
" assert osp.exists(self.img_dir) and self.split is not None\n",
|
|||
|
"\n",
|
|||
|
" "
|
|||
|
],
|
|||
|
"execution_count": 16,
|
|||
|
"outputs": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "yUVtmn3Iq3WA",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"### Create a config file\n",
|
|||
|
"In the next step, we need to modify the config for the training. To accelerate the process, we finetune the model from trained weights."
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "Wwnj9tRzqX_A",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {}
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"from mmcv import Config\n",
|
|||
|
"cfg = Config.fromfile('configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py')"
|
|||
|
],
|
|||
|
"execution_count": 17,
|
|||
|
"outputs": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "1y2oV5w97jQo",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"Since the given config is used to train PSPNet on cityscapes dataset, we need to modify it accordingly for our new dataset. "
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "eyKnYC1Z7iCV",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 1000
|
|||
|
},
|
|||
|
"outputId": "a25241e2-431c-4944-b0b8-b9c792d5aadd"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"from mmseg.apis import set_random_seed\n",
|
|||
|
"\n",
|
|||
|
"# Since we use ony one GPU, BN is used instead of SyncBN\n",
|
|||
|
"cfg.norm_cfg = dict(type='BN', requires_grad=True)\n",
|
|||
|
"cfg.model.backbone.norm_cfg = cfg.norm_cfg\n",
|
|||
|
"cfg.model.decode_head.norm_cfg = cfg.norm_cfg\n",
|
|||
|
"cfg.model.auxiliary_head.norm_cfg = cfg.norm_cfg\n",
|
|||
|
"# modify num classes of the model in decode/auxiliary head\n",
|
|||
|
"cfg.model.decode_head.num_classes = 8\n",
|
|||
|
"cfg.model.auxiliary_head.num_classes = 8\n",
|
|||
|
"\n",
|
|||
|
"# Modify dataset type and path\n",
|
|||
|
"cfg.dataset_type = 'StandfordBackgroundDataset'\n",
|
|||
|
"cfg.data_root = data_root\n",
|
|||
|
"\n",
|
|||
|
"cfg.data.samples_per_gpu = 8\n",
|
|||
|
"cfg.data.workers_per_gpu=8\n",
|
|||
|
"\n",
|
|||
|
"cfg.img_norm_cfg = dict(\n",
|
|||
|
" mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)\n",
|
|||
|
"cfg.crop_size = (256, 256)\n",
|
|||
|
"cfg.train_pipeline = [\n",
|
|||
|
" dict(type='LoadImageFromFile'),\n",
|
|||
|
" dict(type='LoadAnnotations'),\n",
|
|||
|
" dict(type='Resize', img_scale=(320, 240), ratio_range=(0.5, 2.0)),\n",
|
|||
|
" dict(type='RandomCrop', crop_size=cfg.crop_size, cat_max_ratio=0.75),\n",
|
|||
|
" dict(type='RandomFlip', flip_ratio=0.5),\n",
|
|||
|
" dict(type='PhotoMetricDistortion'),\n",
|
|||
|
" dict(type='Normalize', **cfg.img_norm_cfg),\n",
|
|||
|
" dict(type='Pad', size=cfg.crop_size, pad_val=0, seg_pad_val=255),\n",
|
|||
|
" dict(type='DefaultFormatBundle'),\n",
|
|||
|
" dict(type='Collect', keys=['img', 'gt_semantic_seg']),\n",
|
|||
|
"]\n",
|
|||
|
"\n",
|
|||
|
"cfg.test_pipeline = [\n",
|
|||
|
" dict(type='LoadImageFromFile'),\n",
|
|||
|
" dict(\n",
|
|||
|
" type='MultiScaleFlipAug',\n",
|
|||
|
" img_scale=(320, 240),\n",
|
|||
|
" # img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75],\n",
|
|||
|
" flip=False,\n",
|
|||
|
" transforms=[\n",
|
|||
|
" dict(type='Resize', keep_ratio=True),\n",
|
|||
|
" dict(type='RandomFlip'),\n",
|
|||
|
" dict(type='Normalize', **cfg.img_norm_cfg),\n",
|
|||
|
" dict(type='ImageToTensor', keys=['img']),\n",
|
|||
|
" dict(type='Collect', keys=['img']),\n",
|
|||
|
" ])\n",
|
|||
|
"]\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"cfg.data.train.type = cfg.dataset_type\n",
|
|||
|
"cfg.data.train.data_root = cfg.data_root\n",
|
|||
|
"cfg.data.train.img_dir = img_dir\n",
|
|||
|
"cfg.data.train.ann_dir = ann_dir\n",
|
|||
|
"cfg.data.train.pipeline = cfg.train_pipeline\n",
|
|||
|
"cfg.data.train.split = 'splits/train.txt'\n",
|
|||
|
"\n",
|
|||
|
"cfg.data.val.type = cfg.dataset_type\n",
|
|||
|
"cfg.data.val.data_root = cfg.data_root\n",
|
|||
|
"cfg.data.val.img_dir = img_dir\n",
|
|||
|
"cfg.data.val.ann_dir = ann_dir\n",
|
|||
|
"cfg.data.val.pipeline = cfg.test_pipeline\n",
|
|||
|
"cfg.data.val.split = 'splits/val.txt'\n",
|
|||
|
"\n",
|
|||
|
"cfg.data.test.type = cfg.dataset_type\n",
|
|||
|
"cfg.data.test.data_root = cfg.data_root\n",
|
|||
|
"cfg.data.test.img_dir = img_dir\n",
|
|||
|
"cfg.data.test.ann_dir = ann_dir\n",
|
|||
|
"cfg.data.test.pipeline = cfg.test_pipeline\n",
|
|||
|
"cfg.data.test.split = 'splits/val.txt'\n",
|
|||
|
"\n",
|
|||
|
"# We can still use the pre-trained Mask RCNN model though we do not need to\n",
|
|||
|
"# use the mask branch\n",
|
|||
|
"cfg.load_from = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'\n",
|
|||
|
"\n",
|
|||
|
"# Set up working dir to save files and logs.\n",
|
|||
|
"cfg.work_dir = './work_dirs/tutorial'\n",
|
|||
|
"\n",
|
|||
|
"cfg.total_iters = 200\n",
|
|||
|
"cfg.log_config.interval = 10\n",
|
|||
|
"cfg.evaluation.interval = 200\n",
|
|||
|
"cfg.checkpoint_config.interval = 200\n",
|
|||
|
"\n",
|
|||
|
"# Set seed to facitate reproducing the result\n",
|
|||
|
"cfg.seed = 0\n",
|
|||
|
"set_random_seed(0, deterministic=False)\n",
|
|||
|
"cfg.gpu_ids = range(1)\n",
|
|||
|
"\n",
|
|||
|
"# Let's have a look at the final config used for training\n",
|
|||
|
"print(f'Config:\\n{cfg.pretty_text}')"
|
|||
|
],
|
|||
|
"execution_count": 18,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Config:\n",
|
|||
|
"norm_cfg = dict(type='BN', requires_grad=True)\n",
|
|||
|
"model = dict(\n",
|
|||
|
" type='EncoderDecoder',\n",
|
|||
|
" pretrained='open-mmlab://resnet50_v1c',\n",
|
|||
|
" backbone=dict(\n",
|
|||
|
" type='ResNetV1c',\n",
|
|||
|
" depth=50,\n",
|
|||
|
" num_stages=4,\n",
|
|||
|
" out_indices=(0, 1, 2, 3),\n",
|
|||
|
" dilations=(1, 1, 2, 4),\n",
|
|||
|
" strides=(1, 2, 1, 1),\n",
|
|||
|
" norm_cfg=dict(type='BN', requires_grad=True),\n",
|
|||
|
" norm_eval=False,\n",
|
|||
|
" style='pytorch',\n",
|
|||
|
" contract_dilation=True),\n",
|
|||
|
" decode_head=dict(\n",
|
|||
|
" type='PSPHead',\n",
|
|||
|
" in_channels=2048,\n",
|
|||
|
" in_index=3,\n",
|
|||
|
" channels=512,\n",
|
|||
|
" pool_scales=(1, 2, 3, 6),\n",
|
|||
|
" dropout_ratio=0.1,\n",
|
|||
|
" num_classes=8,\n",
|
|||
|
" norm_cfg=dict(type='BN', requires_grad=True),\n",
|
|||
|
" align_corners=False,\n",
|
|||
|
" loss_decode=dict(\n",
|
|||
|
" type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)),\n",
|
|||
|
" auxiliary_head=dict(\n",
|
|||
|
" type='FCNHead',\n",
|
|||
|
" in_channels=1024,\n",
|
|||
|
" in_index=2,\n",
|
|||
|
" channels=256,\n",
|
|||
|
" num_convs=1,\n",
|
|||
|
" concat_input=False,\n",
|
|||
|
" dropout_ratio=0.1,\n",
|
|||
|
" num_classes=8,\n",
|
|||
|
" norm_cfg=dict(type='BN', requires_grad=True),\n",
|
|||
|
" align_corners=False,\n",
|
|||
|
" loss_decode=dict(\n",
|
|||
|
" type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)))\n",
|
|||
|
"train_cfg = dict()\n",
|
|||
|
"test_cfg = dict(mode='whole')\n",
|
|||
|
"dataset_type = 'StandfordBackgroundDataset'\n",
|
|||
|
"data_root = 'iccv09Data'\n",
|
|||
|
"img_norm_cfg = dict(\n",
|
|||
|
" mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)\n",
|
|||
|
"crop_size = (256, 256)\n",
|
|||
|
"train_pipeline = [\n",
|
|||
|
" dict(type='LoadImageFromFile'),\n",
|
|||
|
" dict(type='LoadAnnotations'),\n",
|
|||
|
" dict(type='Resize', img_scale=(320, 240), ratio_range=(0.5, 2.0)),\n",
|
|||
|
" dict(type='RandomCrop', crop_size=(256, 256), cat_max_ratio=0.75),\n",
|
|||
|
" dict(type='RandomFlip', flip_ratio=0.5),\n",
|
|||
|
" dict(type='PhotoMetricDistortion'),\n",
|
|||
|
" dict(\n",
|
|||
|
" type='Normalize',\n",
|
|||
|
" mean=[123.675, 116.28, 103.53],\n",
|
|||
|
" std=[58.395, 57.12, 57.375],\n",
|
|||
|
" to_rgb=True),\n",
|
|||
|
" dict(type='Pad', size=(256, 256), pad_val=0, seg_pad_val=255),\n",
|
|||
|
" dict(type='DefaultFormatBundle'),\n",
|
|||
|
" dict(type='Collect', keys=['img', 'gt_semantic_seg'])\n",
|
|||
|
"]\n",
|
|||
|
"test_pipeline = [\n",
|
|||
|
" dict(type='LoadImageFromFile'),\n",
|
|||
|
" dict(\n",
|
|||
|
" type='MultiScaleFlipAug',\n",
|
|||
|
" img_scale=(320, 240),\n",
|
|||
|
" flip=False,\n",
|
|||
|
" transforms=[\n",
|
|||
|
" dict(type='Resize', keep_ratio=True),\n",
|
|||
|
" dict(type='RandomFlip'),\n",
|
|||
|
" dict(\n",
|
|||
|
" type='Normalize',\n",
|
|||
|
" mean=[123.675, 116.28, 103.53],\n",
|
|||
|
" std=[58.395, 57.12, 57.375],\n",
|
|||
|
" to_rgb=True),\n",
|
|||
|
" dict(type='ImageToTensor', keys=['img']),\n",
|
|||
|
" dict(type='Collect', keys=['img'])\n",
|
|||
|
" ])\n",
|
|||
|
"]\n",
|
|||
|
"data = dict(\n",
|
|||
|
" samples_per_gpu=8,\n",
|
|||
|
" workers_per_gpu=8,\n",
|
|||
|
" train=dict(\n",
|
|||
|
" type='StandfordBackgroundDataset',\n",
|
|||
|
" data_root='iccv09Data',\n",
|
|||
|
" img_dir='images',\n",
|
|||
|
" ann_dir='labels',\n",
|
|||
|
" pipeline=[\n",
|
|||
|
" dict(type='LoadImageFromFile'),\n",
|
|||
|
" dict(type='LoadAnnotations'),\n",
|
|||
|
" dict(type='Resize', img_scale=(320, 240), ratio_range=(0.5, 2.0)),\n",
|
|||
|
" dict(type='RandomCrop', crop_size=(256, 256), cat_max_ratio=0.75),\n",
|
|||
|
" dict(type='RandomFlip', flip_ratio=0.5),\n",
|
|||
|
" dict(type='PhotoMetricDistortion'),\n",
|
|||
|
" dict(\n",
|
|||
|
" type='Normalize',\n",
|
|||
|
" mean=[123.675, 116.28, 103.53],\n",
|
|||
|
" std=[58.395, 57.12, 57.375],\n",
|
|||
|
" to_rgb=True),\n",
|
|||
|
" dict(type='Pad', size=(256, 256), pad_val=0, seg_pad_val=255),\n",
|
|||
|
" dict(type='DefaultFormatBundle'),\n",
|
|||
|
" dict(type='Collect', keys=['img', 'gt_semantic_seg'])\n",
|
|||
|
" ],\n",
|
|||
|
" split='splits/train.txt'),\n",
|
|||
|
" val=dict(\n",
|
|||
|
" type='StandfordBackgroundDataset',\n",
|
|||
|
" data_root='iccv09Data',\n",
|
|||
|
" img_dir='images',\n",
|
|||
|
" ann_dir='labels',\n",
|
|||
|
" pipeline=[\n",
|
|||
|
" dict(type='LoadImageFromFile'),\n",
|
|||
|
" dict(\n",
|
|||
|
" type='MultiScaleFlipAug',\n",
|
|||
|
" img_scale=(320, 240),\n",
|
|||
|
" flip=False,\n",
|
|||
|
" transforms=[\n",
|
|||
|
" dict(type='Resize', keep_ratio=True),\n",
|
|||
|
" dict(type='RandomFlip'),\n",
|
|||
|
" dict(\n",
|
|||
|
" type='Normalize',\n",
|
|||
|
" mean=[123.675, 116.28, 103.53],\n",
|
|||
|
" std=[58.395, 57.12, 57.375],\n",
|
|||
|
" to_rgb=True),\n",
|
|||
|
" dict(type='ImageToTensor', keys=['img']),\n",
|
|||
|
" dict(type='Collect', keys=['img'])\n",
|
|||
|
" ])\n",
|
|||
|
" ],\n",
|
|||
|
" split='splits/val.txt'),\n",
|
|||
|
" test=dict(\n",
|
|||
|
" type='StandfordBackgroundDataset',\n",
|
|||
|
" data_root='iccv09Data',\n",
|
|||
|
" img_dir='images',\n",
|
|||
|
" ann_dir='labels',\n",
|
|||
|
" pipeline=[\n",
|
|||
|
" dict(type='LoadImageFromFile'),\n",
|
|||
|
" dict(\n",
|
|||
|
" type='MultiScaleFlipAug',\n",
|
|||
|
" img_scale=(320, 240),\n",
|
|||
|
" flip=False,\n",
|
|||
|
" transforms=[\n",
|
|||
|
" dict(type='Resize', keep_ratio=True),\n",
|
|||
|
" dict(type='RandomFlip'),\n",
|
|||
|
" dict(\n",
|
|||
|
" type='Normalize',\n",
|
|||
|
" mean=[123.675, 116.28, 103.53],\n",
|
|||
|
" std=[58.395, 57.12, 57.375],\n",
|
|||
|
" to_rgb=True),\n",
|
|||
|
" dict(type='ImageToTensor', keys=['img']),\n",
|
|||
|
" dict(type='Collect', keys=['img'])\n",
|
|||
|
" ])\n",
|
|||
|
" ],\n",
|
|||
|
" split='splits/val.txt'))\n",
|
|||
|
"log_config = dict(\n",
|
|||
|
" interval=10, hooks=[dict(type='TextLoggerHook', by_epoch=False)])\n",
|
|||
|
"dist_params = dict(backend='nccl')\n",
|
|||
|
"log_level = 'INFO'\n",
|
|||
|
"load_from = 'checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth'\n",
|
|||
|
"resume_from = None\n",
|
|||
|
"workflow = [('train', 1)]\n",
|
|||
|
"cudnn_benchmark = True\n",
|
|||
|
"optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005)\n",
|
|||
|
"optimizer_config = dict()\n",
|
|||
|
"lr_config = dict(policy='poly', power=0.9, min_lr=0.0001, by_epoch=False)\n",
|
|||
|
"total_iters = 200\n",
|
|||
|
"checkpoint_config = dict(by_epoch=False, interval=200)\n",
|
|||
|
"evaluation = dict(interval=200, metric='mIoU')\n",
|
|||
|
"work_dir = './work_dirs/tutorial'\n",
|
|||
|
"seed = 0\n",
|
|||
|
"gpu_ids = range(0, 1)\n",
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"name": "stdout"
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "QWuH14LYF2gQ",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"### Train and Evaluation"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "jYKoSfdMF12B",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 953,
|
|||
|
"referenced_widgets": [
|
|||
|
"40a3c0b2c7a44085b69b9c741df20b3e",
|
|||
|
"ec96fb4251ea4b8ea268a2bc62b9c75b",
|
|||
|
"dae4b284c5a944639991d29f4e79fac5",
|
|||
|
"c78567afd0a6418781118ac9f4ecdea9",
|
|||
|
"32b7d27a143c41b5bb90f1d8e66a1c67",
|
|||
|
"55d75951f51c4ab89e32045c3d6db8a4",
|
|||
|
"9d29e2d02731416d9852e9c7c08d1665",
|
|||
|
"1bb2b93526cd421aa5d5b86d678932ab"
|
|||
|
]
|
|||
|
},
|
|||
|
"outputId": "1c0b5a11-434b-4c96-a4aa-9d685fff0856"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"from mmseg.datasets import build_dataset\n",
|
|||
|
"from mmseg.models import build_segmentor\n",
|
|||
|
"from mmseg.apis import train_segmentor\n",
|
|||
|
"\n",
|
|||
|
"\n",
|
|||
|
"# Build the dataset\n",
|
|||
|
"datasets = [build_dataset(cfg.data.train)]\n",
|
|||
|
"\n",
|
|||
|
"# Build the detector\n",
|
|||
|
"model = build_segmentor(\n",
|
|||
|
" cfg.model, train_cfg=cfg.train_cfg, test_cfg=cfg.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_segmentor(model, datasets, cfg, distributed=False, validate=True, \n",
|
|||
|
" meta=dict())"
|
|||
|
],
|
|||
|
"execution_count": 19,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"2020-07-09 19:14:27,264 - mmseg - INFO - Loaded 572 images\n",
|
|||
|
"Downloading: \"https://open-mmlab.s3.ap-northeast-2.amazonaws.com/pretrain/third_party/resnet50_v1c-2cccc1ad.pth\" to /root/.cache/torch/checkpoints/resnet50_v1c-2cccc1ad.pth\n"
|
|||
|
],
|
|||
|
"name": "stderr"
|
|||
|
},
|
|||
|
{
|
|||
|
"output_type": "display_data",
|
|||
|
"data": {
|
|||
|
"application/vnd.jupyter.widget-view+json": {
|
|||
|
"model_id": "40a3c0b2c7a44085b69b9c741df20b3e",
|
|||
|
"version_minor": 0,
|
|||
|
"version_major": 2
|
|||
|
},
|
|||
|
"text/plain": [
|
|||
|
"HBox(children=(FloatProgress(value=0.0, max=102567401.0), HTML(value='')))"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"tags": []
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"2020-07-09 19:14:39,770 - mmseg - WARNING - The model and loaded state dict do not match exactly\n",
|
|||
|
"\n",
|
|||
|
"unexpected key in source state_dict: fc.weight, fc.bias\n",
|
|||
|
"\n",
|
|||
|
"2020-07-09 19:14:39,836 - mmseg - INFO - Loaded 143 images\n",
|
|||
|
"2020-07-09 19:14:39,837 - mmseg - INFO - load checkpoint from checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth\n"
|
|||
|
],
|
|||
|
"name": "stderr"
|
|||
|
},
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"\n"
|
|||
|
],
|
|||
|
"name": "stdout"
|
|||
|
},
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"2020-07-09 19:14:39,990 - mmseg - WARNING - The model and loaded state dict do not match exactly\n",
|
|||
|
"\n",
|
|||
|
"size mismatch for decode_head.conv_seg.weight: copying a param with shape torch.Size([19, 512, 1, 1]) from checkpoint, the shape in current model is torch.Size([8, 512, 1, 1]).\n",
|
|||
|
"size mismatch for decode_head.conv_seg.bias: copying a param with shape torch.Size([19]) from checkpoint, the shape in current model is torch.Size([8]).\n",
|
|||
|
"size mismatch for auxiliary_head.conv_seg.weight: copying a param with shape torch.Size([19, 256, 1, 1]) from checkpoint, the shape in current model is torch.Size([8, 256, 1, 1]).\n",
|
|||
|
"size mismatch for auxiliary_head.conv_seg.bias: copying a param with shape torch.Size([19]) from checkpoint, the shape in current model is torch.Size([8]).\n",
|
|||
|
"2020-07-09 19:14:39,994 - mmseg - INFO - Start running, host: root@71c6cf9b06c5, work_dir: /content/mmsegmentation/work_dirs/tutorial\n",
|
|||
|
"2020-07-09 19:14:39,995 - mmseg - INFO - workflow: [('train', 1)], max: 200 iters\n",
|
|||
|
"2020-07-09 19:14:54,192 - mmseg - INFO - Iter [10/200]\tlr: 9.598e-03, eta: 0:04:21, time: 1.379, data_time: 0.002, memory: 3772, decode.loss_seg: 1.5616, decode.acc_seg: 46.9241, aux.loss_seg: 0.6853, aux.acc_seg: 38.7292, loss: 2.2469\n",
|
|||
|
"2020-07-09 19:15:07,556 - mmseg - INFO - Iter [20/200]\tlr: 9.149e-03, eta: 0:04:04, time: 1.336, data_time: 0.016, memory: 3772, decode.loss_seg: 0.8215, decode.acc_seg: 68.8879, aux.loss_seg: 0.5371, aux.acc_seg: 67.9098, loss: 1.3586\n",
|
|||
|
"2020-07-09 19:15:20,914 - mmseg - INFO - Iter [30/200]\tlr: 8.698e-03, eta: 0:03:49, time: 1.336, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5890, decode.acc_seg: 66.6747, aux.loss_seg: 0.3591, aux.acc_seg: 65.8590, loss: 0.9481\n",
|
|||
|
"2020-07-09 19:15:34,235 - mmseg - INFO - Iter [40/200]\tlr: 8.244e-03, eta: 0:03:35, time: 1.332, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5888, decode.acc_seg: 71.6006, aux.loss_seg: 0.3192, aux.acc_seg: 66.5800, loss: 0.9079\n",
|
|||
|
"2020-07-09 19:15:47,580 - mmseg - INFO - Iter [50/200]\tlr: 7.788e-03, eta: 0:03:21, time: 1.335, data_time: 0.016, memory: 3772, decode.loss_seg: 0.7011, decode.acc_seg: 65.8105, aux.loss_seg: 0.3223, aux.acc_seg: 62.9866, loss: 1.0235\n",
|
|||
|
"2020-07-09 19:16:00,900 - mmseg - INFO - Iter [60/200]\tlr: 7.328e-03, eta: 0:03:07, time: 1.332, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5531, decode.acc_seg: 66.3968, aux.loss_seg: 0.2624, aux.acc_seg: 63.4624, loss: 0.8156\n",
|
|||
|
"2020-07-09 19:16:14,199 - mmseg - INFO - Iter [70/200]\tlr: 6.865e-03, eta: 0:02:54, time: 1.330, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5888, decode.acc_seg: 66.5814, aux.loss_seg: 0.2905, aux.acc_seg: 62.6161, loss: 0.8792\n",
|
|||
|
"2020-07-09 19:16:28,148 - mmseg - INFO - Iter [80/200]\tlr: 6.398e-03, eta: 0:02:41, time: 1.395, data_time: 0.016, memory: 3772, decode.loss_seg: 0.4988, decode.acc_seg: 69.7736, aux.loss_seg: 0.2388, aux.acc_seg: 68.5068, loss: 0.7376\n",
|
|||
|
"2020-07-09 19:16:41,440 - mmseg - INFO - Iter [90/200]\tlr: 5.928e-03, eta: 0:02:27, time: 1.330, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5177, decode.acc_seg: 72.9874, aux.loss_seg: 0.2512, aux.acc_seg: 71.1549, loss: 0.7690\n",
|
|||
|
"2020-07-09 19:16:54,703 - mmseg - INFO - Iter [100/200]\tlr: 5.453e-03, eta: 0:02:14, time: 1.326, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5794, decode.acc_seg: 65.9114, aux.loss_seg: 0.2557, aux.acc_seg: 65.2695, loss: 0.8351\n",
|
|||
|
"2020-07-09 19:17:07,972 - mmseg - INFO - Iter [110/200]\tlr: 4.974e-03, eta: 0:02:00, time: 1.327, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5395, decode.acc_seg: 69.2955, aux.loss_seg: 0.2443, aux.acc_seg: 68.5840, loss: 0.7838\n",
|
|||
|
"2020-07-09 19:17:21,227 - mmseg - INFO - Iter [120/200]\tlr: 4.489e-03, eta: 0:01:47, time: 1.326, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5568, decode.acc_seg: 70.1717, aux.loss_seg: 0.2490, aux.acc_seg: 69.4707, loss: 0.8058\n",
|
|||
|
"2020-07-09 19:17:34,513 - mmseg - INFO - Iter [130/200]\tlr: 3.998e-03, eta: 0:01:33, time: 1.328, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5222, decode.acc_seg: 72.1791, aux.loss_seg: 0.2446, aux.acc_seg: 71.0046, loss: 0.7668\n",
|
|||
|
"2020-07-09 19:17:47,812 - mmseg - INFO - Iter [140/200]\tlr: 3.500e-03, eta: 0:01:20, time: 1.330, data_time: 0.016, memory: 3772, decode.loss_seg: 0.5178, decode.acc_seg: 72.7657, aux.loss_seg: 0.2552, aux.acc_seg: 70.8837, loss: 0.7730\n",
|
|||
|
"2020-07-09 19:18:01,667 - mmseg - INFO - Iter [150/200]\tlr: 2.994e-03, eta: 0:01:07, time: 1.386, data_time: 0.016, memory: 3772, decode.loss_seg: 0.4719, decode.acc_seg: 72.4819, aux.loss_seg: 0.2263, aux.acc_seg: 69.9169, loss: 0.6982\n",
|
|||
|
"2020-07-09 19:18:14,904 - mmseg - INFO - Iter [160/200]\tlr: 2.478e-03, eta: 0:00:53, time: 1.324, data_time: 0.016, memory: 3772, decode.loss_seg: 0.4494, decode.acc_seg: 75.4808, aux.loss_seg: 0.2228, aux.acc_seg: 73.2249, loss: 0.6723\n",
|
|||
|
"2020-07-09 19:18:28,151 - mmseg - INFO - Iter [170/200]\tlr: 1.949e-03, eta: 0:00:40, time: 1.325, data_time: 0.016, memory: 3772, decode.loss_seg: 0.4412, decode.acc_seg: 72.4503, aux.loss_seg: 0.2177, aux.acc_seg: 69.9681, loss: 0.6589\n",
|
|||
|
"2020-07-09 19:18:41,413 - mmseg - INFO - Iter [180/200]\tlr: 1.402e-03, eta: 0:00:26, time: 1.326, data_time: 0.016, memory: 3772, decode.loss_seg: 0.4127, decode.acc_seg: 74.4395, aux.loss_seg: 0.1955, aux.acc_seg: 72.5129, loss: 0.6082\n",
|
|||
|
"2020-07-09 19:18:54,678 - mmseg - INFO - Iter [190/200]\tlr: 8.277e-04, eta: 0:00:13, time: 1.326, data_time: 0.016, memory: 3772, decode.loss_seg: 0.4733, decode.acc_seg: 74.7937, aux.loss_seg: 0.2285, aux.acc_seg: 72.0337, loss: 0.7019\n",
|
|||
|
"2020-07-09 19:19:07,808 - mmseg - INFO - Saving checkpoint at 200 iterations\n"
|
|||
|
],
|
|||
|
"name": "stderr"
|
|||
|
},
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 143/143, 10.9 task/s, elapsed: 13s, ETA: 0s"
|
|||
|
],
|
|||
|
"name": "stdout"
|
|||
|
},
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"2020-07-09 19:19:22,647 - mmseg - INFO - per class results:\n",
|
|||
|
"Class IoU Acc\n",
|
|||
|
"sky 88.67 94.28\n",
|
|||
|
"tree 68.95 86.73\n",
|
|||
|
"road 86.23 94.42\n",
|
|||
|
"grass 70.01 91.35\n",
|
|||
|
"water 62.08 68.32\n",
|
|||
|
"bldg 81.11 88.89\n",
|
|||
|
"mntn 0.00 0.00\n",
|
|||
|
"fg obj 70.39 82.49\n",
|
|||
|
"Summary:\n",
|
|||
|
"Scope mIoU mAcc aAcc\n",
|
|||
|
"global 65.93 75.81 87.48\n",
|
|||
|
"\n",
|
|||
|
"2020-07-09 19:19:22,660 - mmseg - INFO - Iter [200/200]\tlr: 1.841e-04, mIoU: 0.6593, mAcc: 0.7581, aAcc: 0.8748\n"
|
|||
|
],
|
|||
|
"name": "stderr"
|
|||
|
}
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {
|
|||
|
"id": "DEkWOP-NMbc_",
|
|||
|
"colab_type": "text"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"Inference with trained model"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"metadata": {
|
|||
|
"id": "ekG__UfaH_OU",
|
|||
|
"colab_type": "code",
|
|||
|
"colab": {
|
|||
|
"base_uri": "https://localhost:8080/",
|
|||
|
"height": 645
|
|||
|
},
|
|||
|
"outputId": "ac1eb835-19ed-48e6-8f77-e6d325b915c4"
|
|||
|
},
|
|||
|
"source": [
|
|||
|
"img = mmcv.imread('iccv09Data/images/6000124.jpg')\n",
|
|||
|
"\n",
|
|||
|
"model.cfg = cfg\n",
|
|||
|
"result = inference_segmentor(model, img)\n",
|
|||
|
"plt.figure(figsize=(8, 6))\n",
|
|||
|
"show_result_pyplot(model, img, result, palette)"
|
|||
|
],
|
|||
|
"execution_count": 20,
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"/content/mmsegmentation/mmseg/models/segmentors/base.py:265: UserWarning: show==False and out_file is not specified, only result image will be returned\n",
|
|||
|
" warnings.warn('show==False and out_file is not specified, only '\n"
|
|||
|
],
|
|||
|
"name": "stderr"
|
|||
|
},
|
|||
|
{
|
|||
|
"output_type": "display_data",
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 576x432 with 0 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"tags": []
|
|||
|
}
|
|||
|
},
|
|||
|
{
|
|||
|
"output_type": "display_data",
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAv0AAAJBCAYAAADVzgoaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9t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7Pk4D1C5wAeD9/WH0OQ4HkA3SXHnphIBKhbsiE3P6b66zJri/3XHcjgXAXOfpc+jGcBNABar05js/NDNyK980B6NN0sHQ3XgmjSds3YsqZm9orYdB2mIXbTXwaQwaWBxlPm0snOcxBnRONPLKYcaZdUuhTYPWR+84uu3CcI4ECE/4GMPGQcDo/WrSoPRIV6WMVWYqAHX5dl2nA2sbiwgwhwMmN4J0NlzOTo/3bwBshyk96XDwcQuDiAb2nAPjutBcDAoA6MTj/Ruus+E8z5Q/zh9zjAC73EEiDRqBJLIuhWAOLTqhggctOmXxYdt3wR/FadVctkyJfqnXE/rHF2mVZbM4caDAkJH60wFgjoPttgCgAYaKboL67heNEefRC/C1Mx0IF33hYD/1Df9f6FMoYoDUf7vtwfWlA1DYOJrO8Pon0AB0et/EHYEqmG36vwERp3vxyLI/vqIgjm7pIKP9o6qma0vPOQ4hExD4S3ZrOF2qpuL88UeKTiZOgP+e/nwjJok+CES8523FPVJ2QlvvkFK3OQENkEtrOUdAyJbeTWZKeWb6jgdpYnqoQaBoE1Yn+8j5ntMcBcPW3nAnAGVRrAp/5nTDkbxZnX2qBdcUfBYYUNXGhCQHp8F0ZHOHsn2jxIf8+yPg+f+yLA7
|
|||
|
"text/plain": [
|
|||
|
"<Figure size 1080x720 with 1 Axes>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {
|
|||
|
"tags": [],
|
|||
|
"needs_background": "light"
|
|||
|
}
|
|||
|
}
|
|||
|
]
|
|||
|
}
|
|||
|
]
|
|||
|
}
|