From a9f034366031ab731703464597f3177d895efb36 Mon Sep 17 00:00:00 2001 From: zhangwenwen Date: Wed, 12 May 2021 21:51:09 +0800 Subject: [PATCH] update --- notebooks/ade20k_starter.ipynb | 21 +++---- notebooks/dataset | 1 + notebooks/mask_generation.ipynb | 106 ++++++++++++++++++++++++++++++++ notebooks/utils | 1 + 4 files changed, 117 insertions(+), 12 deletions(-) create mode 120000 notebooks/dataset create mode 100644 notebooks/mask_generation.ipynb create mode 120000 notebooks/utils diff --git a/notebooks/ade20k_starter.ipynb b/notebooks/ade20k_starter.ipynb index 6d71957..da568d2 100644 --- a/notebooks/ade20k_starter.ipynb +++ b/notebooks/ade20k_starter.ipynb @@ -10,26 +10,23 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "ln: failed to create symbolic link './utils': File exists\n", - "ln: failed to create symbolic link './dataset': File exists\n", - "--2021-02-28 10:56:34-- http://groups.csail.mit.edu/vision/datasets/ADE20K/toolkit/index_ade20k.pkl\n", - "Resolving groups.csail.mit.edu (groups.csail.mit.edu)... 128.30.2.44\n", - "Connecting to groups.csail.mit.edu (groups.csail.mit.edu)|128.30.2.44|:80... connected.\n", + "ln: ./utils: File exists\n", + "ln: ./dataset: File exists\n", + "--2021-05-12 21:27:23-- http://groups.csail.mit.edu/vision/datasets/ADE20K/toolkit/index_ade20k.pkl\n", + "Resolving groups.csail.mit.edu... 128.30.2.44\n", + "Connecting to groups.csail.mit.edu|128.30.2.44|:80... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 817537016 (780M)\n", - "Saving to: ‘index_ade20k.pkl’\n", + "Saving to: 'index_ade20k.pkl'\n", "\n", - "index_ade20k.pkl 100%[===================>] 779.66M 65.8MB/s in 12s \n", - "\n", - "2021-02-28 10:57:44 (63.1 MB/s) - ‘index_ade20k.pkl’ saved [817537016/817537016]\n", - "\n" + "index_ade20k.pkl 0%[ ] 5.75M 12.6KB/s eta 13h 54m^C\n" ] } ], @@ -322,7 +319,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/notebooks/dataset b/notebooks/dataset new file mode 120000 index 0000000..0527662 --- /dev/null +++ b/notebooks/dataset @@ -0,0 +1 @@ +../dataset/ \ No newline at end of file diff --git a/notebooks/mask_generation.ipynb b/notebooks/mask_generation.ipynb new file mode 100644 index 0000000..a4c3ba8 --- /dev/null +++ b/notebooks/mask_generation.ipynb @@ -0,0 +1,106 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The autoreload extension is already loaded. To reload it, use:\n", + " %reload_ext autoreload\n" + ] + } + ], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2\n", + "import IPython.display\n", + "import matplotlib.pyplot as plt\n", + "import cv2\n", + "import numpy as np\n", + "import pickle as pkl\n", + "from utils import utils_ade20k\n", + "import os" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "DATASET_PATH = '../dataset/ADE20K_2021_17_01/images/ADE/training/urban/street'" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'partclass_mask'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mimshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconcatenate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mseg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mseg_mask\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'off'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 15\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'partclass_mask'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 16\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'partclass_mask'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtitle\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Parts'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyError\u001b[0m: 'partclass_mask'" + ] + } + ], + "source": [ + "root_path = DATASET_PATH\n", + "info = {}\n", + "info['img_name']=os.path.join(DATASET_PATH,'ADE_train_00016869.jpg')\n", + "info['segm_name']=os.path.join(DATASET_PATH,'ADE_train_00016869_seg.png')\n", + "img = cv2.imread(info['img_name'])[:,:,::-1]\n", + "seg = cv2.imread(info['segm_name'])[:,:,::-1]\n", + "seg_mask = seg.copy()\n", + "\n", + "# The 0 index in seg_mask corresponds to background (not annotated) pixels\n", + "#seg_mask[info['class_mask'] != obj_id+1] *= 0\n", + "plt.figure(figsize=(15,5))\n", + "\n", + "plt.imshow(np.concatenate([img, seg, seg_mask], 1))\n", + "plt.axis('off')\n", + "if len(info['partclass_mask']):\n", + " plt.figure(figsize=(5*len(info['partclass_mask']), 5))\n", + " plt.title('Parts')\n", + " plt.imshow(np.concatenate(info['partclass_mask'],1))\n", + " plt.axis('off')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/notebooks/utils b/notebooks/utils new file mode 120000 index 0000000..19985ba --- /dev/null +++ b/notebooks/utils @@ -0,0 +1 @@ +../utils/ \ No newline at end of file