From 294a1f377a84ead53ba8b5ed4e2769cdf970f8c7 Mon Sep 17 00:00:00 2001 From: yamengxi <49829199+yamengxi@users.noreply.github.com> Date: Thu, 29 Oct 2020 02:58:44 +0800 Subject: [PATCH] fix dataset jpg bug (#213) * fix dataset jpg bug * fix syntax error --- mmseg/datasets/chase_db1.py | 8 ++++---- mmseg/datasets/drive.py | 8 ++++---- mmseg/datasets/hrf.py | 8 ++++---- mmseg/datasets/stare.py | 8 ++++---- tools/convert_datasets/chase_db1.py | 14 +++++++++----- tools/convert_datasets/drive.py | 10 +++++----- tools/convert_datasets/hrf.py | 8 ++++---- tools/convert_datasets/stare.py | 12 ++++++------ 8 files changed, 40 insertions(+), 36 deletions(-) diff --git a/mmseg/datasets/chase_db1.py b/mmseg/datasets/chase_db1.py index 79d544f20..8bc29bea1 100644 --- a/mmseg/datasets/chase_db1.py +++ b/mmseg/datasets/chase_db1.py @@ -10,8 +10,8 @@ class ChaseDB1Dataset(CustomDataset): In segmentation map annotation for Chase_db1, 0 stands for background, which is included in 2 categories. ``reduce_zero_label`` is fixed to False. - The ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to - '_1stHO.jpg'. + The ``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to + '_1stHO.png'. """ CLASSES = ('background', 'vessel') @@ -20,8 +20,8 @@ class ChaseDB1Dataset(CustomDataset): def __init__(self, **kwargs): super(ChaseDB1Dataset, self).__init__( - img_suffix='.jpg', - seg_map_suffix='_1stHO.jpg', + img_suffix='.png', + seg_map_suffix='_1stHO.png', reduce_zero_label=False, **kwargs) assert osp.exists(self.img_dir) diff --git a/mmseg/datasets/drive.py b/mmseg/datasets/drive.py index 177ca5f69..3cbfda8ae 100644 --- a/mmseg/datasets/drive.py +++ b/mmseg/datasets/drive.py @@ -10,8 +10,8 @@ class DRIVEDataset(CustomDataset): In segmentation map annotation for DRIVE, 0 stands for background, which is included in 2 categories. ``reduce_zero_label`` is fixed to False. The - ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to - '_manual1.jpg'. + ``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to + '_manual1.png'. """ CLASSES = ('background', 'vessel') @@ -20,8 +20,8 @@ class DRIVEDataset(CustomDataset): def __init__(self, **kwargs): super(DRIVEDataset, self).__init__( - img_suffix='.jpg', - seg_map_suffix='_manual1.jpg', + img_suffix='.png', + seg_map_suffix='_manual1.png', reduce_zero_label=False, **kwargs) assert osp.exists(self.img_dir) diff --git a/mmseg/datasets/hrf.py b/mmseg/datasets/hrf.py index ff2441783..923203b51 100644 --- a/mmseg/datasets/hrf.py +++ b/mmseg/datasets/hrf.py @@ -10,8 +10,8 @@ class HRFDataset(CustomDataset): In segmentation map annotation for HRF, 0 stands for background, which is included in 2 categories. ``reduce_zero_label`` is fixed to False. The - ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to - '.jpg'. + ``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to + '.png'. """ CLASSES = ('background', 'vessel') @@ -20,8 +20,8 @@ class HRFDataset(CustomDataset): def __init__(self, **kwargs): super(HRFDataset, self).__init__( - img_suffix='.jpg', - seg_map_suffix='.jpg', + img_suffix='.png', + seg_map_suffix='.png', reduce_zero_label=False, **kwargs) assert osp.exists(self.img_dir) diff --git a/mmseg/datasets/stare.py b/mmseg/datasets/stare.py index 97e987a39..cbd14e092 100644 --- a/mmseg/datasets/stare.py +++ b/mmseg/datasets/stare.py @@ -10,8 +10,8 @@ class STAREDataset(CustomDataset): In segmentation map annotation for STARE, 0 stands for background, which is included in 2 categories. ``reduce_zero_label`` is fixed to False. The - ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to - '.ah.jpg'. + ``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to + '.ah.png'. """ CLASSES = ('background', 'vessel') @@ -20,8 +20,8 @@ class STAREDataset(CustomDataset): def __init__(self, **kwargs): super(STAREDataset, self).__init__( - img_suffix='.jpg', - seg_map_suffix='.ah.jpg', + img_suffix='.png', + seg_map_suffix='.ah.png', reduce_zero_label=False, **kwargs) assert osp.exists(self.img_dir) diff --git a/tools/convert_datasets/chase_db1.py b/tools/convert_datasets/chase_db1.py index e127a04f7..56bb210ed 100644 --- a/tools/convert_datasets/chase_db1.py +++ b/tools/convert_datasets/chase_db1.py @@ -50,8 +50,10 @@ def main(): for img_name in sorted(os.listdir(tmp_dir))[:TRAINING_LEN]: img = mmcv.imread(osp.join(tmp_dir, img_name)) if osp.splitext(img_name)[1] == '.jpg': - mmcv.imwrite(img, - osp.join(out_dir, 'images', 'training', img_name)) + mmcv.imwrite( + img, + osp.join(out_dir, 'images', 'training', + osp.splitext(img_name)[0] + '.png')) else: # The annotation img should be divided by 128, because some of # the annotation imgs are not standard. We should set a @@ -61,18 +63,20 @@ def main(): mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'training', - osp.splitext(img_name)[0] + '.jpg')) + osp.splitext(img_name)[0] + '.png')) for img_name in sorted(os.listdir(tmp_dir))[TRAINING_LEN:]: img = mmcv.imread(osp.join(tmp_dir, img_name)) if osp.splitext(img_name)[1] == '.jpg': mmcv.imwrite( - img, osp.join(out_dir, 'images', 'validation', img_name)) + img, + osp.join(out_dir, 'images', 'validation', + osp.splitext(img_name)[0] + '.png')) else: mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'validation', - osp.splitext(img_name)[0] + '.jpg')) + osp.splitext(img_name)[0] + '.png')) print('Removing the temporary files...') diff --git a/tools/convert_datasets/drive.py b/tools/convert_datasets/drive.py index c25a1d205..891f06f72 100644 --- a/tools/convert_datasets/drive.py +++ b/tools/convert_datasets/drive.py @@ -53,7 +53,7 @@ def main(): osp.join( out_dir, 'images', 'training', osp.splitext(img_name)[0].replace('_training', '') + - '.jpg')) + '.png')) now_dir = osp.join(tmp_dir, 'training', '1st_manual') for img_name in os.listdir(now_dir): @@ -62,7 +62,7 @@ def main(): mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'training', - osp.splitext(img_name)[0] + '.jpg')) + osp.splitext(img_name)[0] + '.png')) print('Extracting test.zip...') zip_file = zipfile.ZipFile(testing_path) @@ -76,7 +76,7 @@ def main(): img, osp.join( out_dir, 'images', 'validation', - osp.splitext(img_name)[0].replace('_test', '') + '.jpg')) + osp.splitext(img_name)[0].replace('_test', '') + '.png')) now_dir = osp.join(tmp_dir, 'test', '1st_manual') if osp.exists(now_dir): @@ -91,7 +91,7 @@ def main(): mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'validation', - osp.splitext(img_name)[0] + '.jpg')) + osp.splitext(img_name)[0] + '.png')) now_dir = osp.join(tmp_dir, 'test', '2nd_manual') if osp.exists(now_dir): @@ -101,7 +101,7 @@ def main(): mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'validation', - osp.splitext(img_name)[0] + '.jpg')) + osp.splitext(img_name)[0] + '.png')) print('Removing the temporary files...') diff --git a/tools/convert_datasets/hrf.py b/tools/convert_datasets/hrf.py index 3f00b9bcd..bdeb6e7e5 100644 --- a/tools/convert_datasets/hrf.py +++ b/tools/convert_datasets/hrf.py @@ -68,13 +68,13 @@ def main(): mmcv.imwrite( img, osp.join(out_dir, 'images', 'training', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) for filename in sorted(os.listdir(tmp_dir))[TRAINING_LEN:]: img = mmcv.imread(osp.join(tmp_dir, filename)) mmcv.imwrite( img, osp.join(out_dir, 'images', 'validation', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) print('Generating annotations...') for now_path in annotations_path: @@ -95,13 +95,13 @@ def main(): mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'training', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) for filename in sorted(os.listdir(tmp_dir))[TRAINING_LEN:]: img = mmcv.imread(osp.join(tmp_dir, filename)) mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'validation', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) print('Done!') diff --git a/tools/convert_datasets/stare.py b/tools/convert_datasets/stare.py index 28129da08..6238d62f6 100644 --- a/tools/convert_datasets/stare.py +++ b/tools/convert_datasets/stare.py @@ -73,14 +73,14 @@ def main(): mmcv.imwrite( img, osp.join(out_dir, 'images', 'training', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) for filename in sorted(os.listdir(now_dir))[TRAINING_LEN:]: img = mmcv.imread(osp.join(now_dir, filename)) mmcv.imwrite( img, osp.join(out_dir, 'images', 'validation', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) print('Removing the temporary files...') @@ -112,14 +112,14 @@ def main(): mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'training', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) for filename in sorted(os.listdir(now_dir))[TRAINING_LEN:]: img = mmcv.imread(osp.join(now_dir, filename)) mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'validation', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) print('Removing the temporary files...') @@ -147,14 +147,14 @@ def main(): mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'training', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) for filename in sorted(os.listdir(now_dir))[TRAINING_LEN:]: img = mmcv.imread(osp.join(now_dir, filename)) mmcv.imwrite( img[:, :, 0] // 128, osp.join(out_dir, 'annotations', 'validation', - osp.splitext(filename)[0] + '.jpg')) + osp.splitext(filename)[0] + '.png')) print('Removing the temporary files...')