Skip to content

Commit

Permalink
fix dataset jpg bug (#213)
Browse files Browse the repository at this point in the history
* fix dataset jpg bug

* fix syntax error
  • Loading branch information
yamengxi authored Oct 28, 2020
1 parent e384ef5 commit 8a174a3
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 36 deletions.
8 changes: 4 additions & 4 deletions mmseg/datasets/chase_db1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
8 changes: 4 additions & 4 deletions mmseg/datasets/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
8 changes: 4 additions & 4 deletions mmseg/datasets/hrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
8 changes: 4 additions & 4 deletions mmseg/datasets/stare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
14 changes: 9 additions & 5 deletions tools/convert_datasets/chase_db1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...')

Expand Down
10 changes: 5 additions & 5 deletions tools/convert_datasets/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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...')

Expand Down
8 changes: 4 additions & 4 deletions tools/convert_datasets/hrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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!')

Expand Down
12 changes: 6 additions & 6 deletions tools/convert_datasets/stare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...')

Expand Down Expand Up @@ -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...')

Expand Down Expand Up @@ -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...')

Expand Down

0 comments on commit 8a174a3

Please sign in to comment.