Skip to content

Commit

Permalink
add HKU-IS dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyajie committed Sep 27, 2021
1 parent 13e3db9 commit 5581198
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 2 deletions.
17 changes: 17 additions & 0 deletions docs/dataset_prepare.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ mmsegmentation
│ │ │ ├── validation
│ │ ├── annotations
│ │ │ ├── validation
| ├── HKU-IS
│ │ ├── images
│ │ │ ├── validation
│ │ ├── annotations
│ │ │ ├── validation
```

### Cityscapes
Expand Down Expand Up @@ -304,3 +309,15 @@ To convert ECSSD dataset to MMSegmentation format, you should run the following
```shell
python tools/convert_datasets/ecssd.py /path/to/images.zip /path/to/ground_truth_mask.zip
```

### HKU-IS

In salient object detection (SOD), HKU-IS is used for evaluation.

First,download [HKU-IS.rar](https://sites.google.com/site/ligb86/mdfsaliency/).

To convert HKU-IS dataset to MMSegmentation format, you should run the following command:

```shell
python tools/convert_datasets/hku_is.py /path/to/HKU-IS.rar
```
17 changes: 17 additions & 0 deletions docs_zh-CN/dataset_prepare.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ mmsegmentation
│ │ │ ├── validation
│ │ ├── annotations
│ │ │ ├── validation
| ├── HKU-IS
│ │ ├── images
│ │ │ ├── validation
│ │ ├── annotations
│ │ │ ├── validation
```

### Cityscapes
Expand Down Expand Up @@ -246,3 +251,15 @@ python tools/convert_datasets/dut_omron.py /path/to/DUT-OMRON-image.zip /path/to
```shell
python tools/convert_datasets/ecssd.py /path/to/images.zip /path/to/ground_truth_mask.zip
```

### HKU-IS

显著性检测(SOD)任务中 HKU-IS 仅作为测试集。

首先,下载 [HKU-IS.rar](https://sites.google.com/site/ligb86/mdfsaliency/)

为了将 HKU-IS 数据集转换成 MMSegmentation 格式,您需要运行如下命令:

```shell
python tools/convert_datasets/hku_is.py /path/to/HKU-IS.rar
```
4 changes: 3 additions & 1 deletion mmseg/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .dut_omron import DUTOMRONDataset
from .duts import DUTSDataset
from .ecssd import ECSSDDataset
from .hku_is import HKUISDataset
from .hrf import HRFDataset
from .night_driving import NightDrivingDataset
from .pascal_context import PascalContextDataset, PascalContextDataset59
Expand All @@ -23,5 +24,6 @@
'PascalVOCDataset', 'ADE20KDataset', 'PascalContextDataset',
'PascalContextDataset59', 'ChaseDB1Dataset', 'DRIVEDataset', 'HRFDataset',
'STAREDataset', 'DarkZurichDataset', 'NightDrivingDataset',
'COCOStuffDataset', 'DUTSDataset', 'DUTOMRONDataset', 'ECSSDDataset'
'COCOStuffDataset', 'DUTSDataset', 'DUTOMRONDataset', 'ECSSDDataset',
'HKUISDataset'
]
27 changes: 27 additions & 0 deletions mmseg/datasets/hku_is.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp

from .builder import DATASETS
from .custom import CustomDataset


@DATASETS.register_module()
class HKUISDataset(CustomDataset):
"""HKU-IS dataset.
In saliency map annotation for HKU-IS, 0 stands for background.
``reduce_zero_label`` is fixed to False. The ``img_suffix`` is fixed to
'.png' and ``seg_map_suffix`` is fixed to '.png'.
"""

CLASSES = ('background', 'foreground')

PALETTE = [[120, 120, 120], [6, 230, 230]]

def __init__(self, **kwargs):
super(HKUISDataset, self).__init__(
img_suffix='.png',
seg_map_suffix='.png',
reduce_zero_label=False,
**kwargs)
assert osp.exists(self.img_dir)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ line_length = 79
multi_line_output = 0
known_standard_library = setuptools
known_first_party = mmseg
known_third_party = PIL,cityscapesscripts,cv2,detail,matplotlib,mmcv,numpy,onnxruntime,packaging,prettytable,pytest,pytorch_sphinx_theme,requests,scipy,seaborn,torch,ts
known_third_party = PIL,cityscapesscripts,cv2,detail,matplotlib,mmcv,numpy,onnxruntime,packaging,prettytable,pytest,pytorch_sphinx_theme,rarfile,requests,scipy,seaborn,torch,ts
no_lines_before = STDLIB,LOCALFOLDER
default_section = THIRDPARTY
67 changes: 67 additions & 0 deletions tools/convert_datasets/hku_is.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import os
import os.path as osp
import shutil
import tempfile

import mmcv
import rarfile

HKU_IS_LEN = 4447


def parse_args():
parser = argparse.ArgumentParser(
description='Convert HKU-IS dataset to mmsegmentation format')
parser.add_argument('hkuis_path', help='the path of HKU-IS.rar')
parser.add_argument('--tmp_dir', help='path of the temporary directory')
parser.add_argument('-o', '--out_dir', help='output path')
args = parser.parse_args()
return args


def main():
args = parse_args()
if args.out_dir is None:
out_dir = osp.join('data', 'HKU-IS')
else:
out_dir = args.out_dir

print('Making directories...')
mmcv.mkdir_or_exist(out_dir)
mmcv.mkdir_or_exist(osp.join(out_dir, 'images'))
mmcv.mkdir_or_exist(osp.join(out_dir, 'images', 'validation'))
mmcv.mkdir_or_exist(osp.join(out_dir, 'annotations'))
mmcv.mkdir_or_exist(osp.join(out_dir, 'annotations', 'validation'))

print('Generating images...')
with tempfile.TemporaryDirectory(dir=args.tmp_dir) as tmp_dir:
rar_file = rarfile.RarFile(args.hkuis_path)
rar_file.extractall(tmp_dir)

image_dir = osp.join(tmp_dir, 'HKU-IS', 'imgs')
mask_dir = osp.join(tmp_dir, 'HKU-IS', 'gt')

assert len(os.listdir(image_dir)) == HKU_IS_LEN \
and len(os.listdir(mask_dir)) == \
HKU_IS_LEN, 'len(HKU-IS) != {}'.format(HKU_IS_LEN)

for filename in sorted(os.listdir(image_dir)):
shutil.copy(
osp.join(image_dir, filename),
osp.join(out_dir, 'images', 'validation',
osp.splitext(filename)[0] + '.png'))

for filename in sorted(os.listdir(mask_dir)):
img = mmcv.imread(osp.join(mask_dir, filename))
mmcv.imwrite(
img[:, :, 0] // 128,
osp.join(out_dir, 'annotations', 'validation',
osp.splitext(filename)[0] + '.png'))

print('Done!')


if __name__ == '__main__':
main()

0 comments on commit 5581198

Please sign in to comment.