Skip to content

Commit 8a174a3

Browse files
authoredOct 28, 2020
fix dataset jpg bug (#213)
* fix dataset jpg bug * fix syntax error
1 parent e384ef5 commit 8a174a3

File tree

8 files changed

+40
-36
lines changed

8 files changed

+40
-36
lines changed
 

‎mmseg/datasets/chase_db1.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class ChaseDB1Dataset(CustomDataset):
1010
1111
In segmentation map annotation for Chase_db1, 0 stands for background,
1212
which is included in 2 categories. ``reduce_zero_label`` is fixed to False.
13-
The ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to
14-
'_1stHO.jpg'.
13+
The ``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to
14+
'_1stHO.png'.
1515
"""
1616

1717
CLASSES = ('background', 'vessel')
@@ -20,8 +20,8 @@ class ChaseDB1Dataset(CustomDataset):
2020

2121
def __init__(self, **kwargs):
2222
super(ChaseDB1Dataset, self).__init__(
23-
img_suffix='.jpg',
24-
seg_map_suffix='_1stHO.jpg',
23+
img_suffix='.png',
24+
seg_map_suffix='_1stHO.png',
2525
reduce_zero_label=False,
2626
**kwargs)
2727
assert osp.exists(self.img_dir)

‎mmseg/datasets/drive.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class DRIVEDataset(CustomDataset):
1010
1111
In segmentation map annotation for DRIVE, 0 stands for background, which is
1212
included in 2 categories. ``reduce_zero_label`` is fixed to False. The
13-
``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to
14-
'_manual1.jpg'.
13+
``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to
14+
'_manual1.png'.
1515
"""
1616

1717
CLASSES = ('background', 'vessel')
@@ -20,8 +20,8 @@ class DRIVEDataset(CustomDataset):
2020

2121
def __init__(self, **kwargs):
2222
super(DRIVEDataset, self).__init__(
23-
img_suffix='.jpg',
24-
seg_map_suffix='_manual1.jpg',
23+
img_suffix='.png',
24+
seg_map_suffix='_manual1.png',
2525
reduce_zero_label=False,
2626
**kwargs)
2727
assert osp.exists(self.img_dir)

‎mmseg/datasets/hrf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class HRFDataset(CustomDataset):
1010
1111
In segmentation map annotation for HRF, 0 stands for background, which is
1212
included in 2 categories. ``reduce_zero_label`` is fixed to False. The
13-
``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to
14-
'.jpg'.
13+
``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to
14+
'.png'.
1515
"""
1616

1717
CLASSES = ('background', 'vessel')
@@ -20,8 +20,8 @@ class HRFDataset(CustomDataset):
2020

2121
def __init__(self, **kwargs):
2222
super(HRFDataset, self).__init__(
23-
img_suffix='.jpg',
24-
seg_map_suffix='.jpg',
23+
img_suffix='.png',
24+
seg_map_suffix='.png',
2525
reduce_zero_label=False,
2626
**kwargs)
2727
assert osp.exists(self.img_dir)

‎mmseg/datasets/stare.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class STAREDataset(CustomDataset):
1010
1111
In segmentation map annotation for STARE, 0 stands for background, which is
1212
included in 2 categories. ``reduce_zero_label`` is fixed to False. The
13-
``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is fixed to
14-
'.ah.jpg'.
13+
``img_suffix`` is fixed to '.png' and ``seg_map_suffix`` is fixed to
14+
'.ah.png'.
1515
"""
1616

1717
CLASSES = ('background', 'vessel')
@@ -20,8 +20,8 @@ class STAREDataset(CustomDataset):
2020

2121
def __init__(self, **kwargs):
2222
super(STAREDataset, self).__init__(
23-
img_suffix='.jpg',
24-
seg_map_suffix='.ah.jpg',
23+
img_suffix='.png',
24+
seg_map_suffix='.ah.png',
2525
reduce_zero_label=False,
2626
**kwargs)
2727
assert osp.exists(self.img_dir)

‎tools/convert_datasets/chase_db1.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ def main():
5050
for img_name in sorted(os.listdir(tmp_dir))[:TRAINING_LEN]:
5151
img = mmcv.imread(osp.join(tmp_dir, img_name))
5252
if osp.splitext(img_name)[1] == '.jpg':
53-
mmcv.imwrite(img,
54-
osp.join(out_dir, 'images', 'training', img_name))
53+
mmcv.imwrite(
54+
img,
55+
osp.join(out_dir, 'images', 'training',
56+
osp.splitext(img_name)[0] + '.png'))
5557
else:
5658
# The annotation img should be divided by 128, because some of
5759
# the annotation imgs are not standard. We should set a
@@ -61,18 +63,20 @@ def main():
6163
mmcv.imwrite(
6264
img[:, :, 0] // 128,
6365
osp.join(out_dir, 'annotations', 'training',
64-
osp.splitext(img_name)[0] + '.jpg'))
66+
osp.splitext(img_name)[0] + '.png'))
6567

6668
for img_name in sorted(os.listdir(tmp_dir))[TRAINING_LEN:]:
6769
img = mmcv.imread(osp.join(tmp_dir, img_name))
6870
if osp.splitext(img_name)[1] == '.jpg':
6971
mmcv.imwrite(
70-
img, osp.join(out_dir, 'images', 'validation', img_name))
72+
img,
73+
osp.join(out_dir, 'images', 'validation',
74+
osp.splitext(img_name)[0] + '.png'))
7175
else:
7276
mmcv.imwrite(
7377
img[:, :, 0] // 128,
7478
osp.join(out_dir, 'annotations', 'validation',
75-
osp.splitext(img_name)[0] + '.jpg'))
79+
osp.splitext(img_name)[0] + '.png'))
7680

7781
print('Removing the temporary files...')
7882

‎tools/convert_datasets/drive.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def main():
5353
osp.join(
5454
out_dir, 'images', 'training',
5555
osp.splitext(img_name)[0].replace('_training', '') +
56-
'.jpg'))
56+
'.png'))
5757

5858
now_dir = osp.join(tmp_dir, 'training', '1st_manual')
5959
for img_name in os.listdir(now_dir):
@@ -62,7 +62,7 @@ def main():
6262
mmcv.imwrite(
6363
img[:, :, 0] // 128,
6464
osp.join(out_dir, 'annotations', 'training',
65-
osp.splitext(img_name)[0] + '.jpg'))
65+
osp.splitext(img_name)[0] + '.png'))
6666

6767
print('Extracting test.zip...')
6868
zip_file = zipfile.ZipFile(testing_path)
@@ -76,7 +76,7 @@ def main():
7676
img,
7777
osp.join(
7878
out_dir, 'images', 'validation',
79-
osp.splitext(img_name)[0].replace('_test', '') + '.jpg'))
79+
osp.splitext(img_name)[0].replace('_test', '') + '.png'))
8080

8181
now_dir = osp.join(tmp_dir, 'test', '1st_manual')
8282
if osp.exists(now_dir):
@@ -91,7 +91,7 @@ def main():
9191
mmcv.imwrite(
9292
img[:, :, 0] // 128,
9393
osp.join(out_dir, 'annotations', 'validation',
94-
osp.splitext(img_name)[0] + '.jpg'))
94+
osp.splitext(img_name)[0] + '.png'))
9595

9696
now_dir = osp.join(tmp_dir, 'test', '2nd_manual')
9797
if osp.exists(now_dir):
@@ -101,7 +101,7 @@ def main():
101101
mmcv.imwrite(
102102
img[:, :, 0] // 128,
103103
osp.join(out_dir, 'annotations', 'validation',
104-
osp.splitext(img_name)[0] + '.jpg'))
104+
osp.splitext(img_name)[0] + '.png'))
105105

106106
print('Removing the temporary files...')
107107

‎tools/convert_datasets/hrf.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ def main():
6868
mmcv.imwrite(
6969
img,
7070
osp.join(out_dir, 'images', 'training',
71-
osp.splitext(filename)[0] + '.jpg'))
71+
osp.splitext(filename)[0] + '.png'))
7272
for filename in sorted(os.listdir(tmp_dir))[TRAINING_LEN:]:
7373
img = mmcv.imread(osp.join(tmp_dir, filename))
7474
mmcv.imwrite(
7575
img,
7676
osp.join(out_dir, 'images', 'validation',
77-
osp.splitext(filename)[0] + '.jpg'))
77+
osp.splitext(filename)[0] + '.png'))
7878

7979
print('Generating annotations...')
8080
for now_path in annotations_path:
@@ -95,13 +95,13 @@ def main():
9595
mmcv.imwrite(
9696
img[:, :, 0] // 128,
9797
osp.join(out_dir, 'annotations', 'training',
98-
osp.splitext(filename)[0] + '.jpg'))
98+
osp.splitext(filename)[0] + '.png'))
9999
for filename in sorted(os.listdir(tmp_dir))[TRAINING_LEN:]:
100100
img = mmcv.imread(osp.join(tmp_dir, filename))
101101
mmcv.imwrite(
102102
img[:, :, 0] // 128,
103103
osp.join(out_dir, 'annotations', 'validation',
104-
osp.splitext(filename)[0] + '.jpg'))
104+
osp.splitext(filename)[0] + '.png'))
105105

106106
print('Done!')
107107

‎tools/convert_datasets/stare.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ def main():
7373
mmcv.imwrite(
7474
img,
7575
osp.join(out_dir, 'images', 'training',
76-
osp.splitext(filename)[0] + '.jpg'))
76+
osp.splitext(filename)[0] + '.png'))
7777

7878
for filename in sorted(os.listdir(now_dir))[TRAINING_LEN:]:
7979
img = mmcv.imread(osp.join(now_dir, filename))
8080
mmcv.imwrite(
8181
img,
8282
osp.join(out_dir, 'images', 'validation',
83-
osp.splitext(filename)[0] + '.jpg'))
83+
osp.splitext(filename)[0] + '.png'))
8484

8585
print('Removing the temporary files...')
8686

@@ -112,14 +112,14 @@ def main():
112112
mmcv.imwrite(
113113
img[:, :, 0] // 128,
114114
osp.join(out_dir, 'annotations', 'training',
115-
osp.splitext(filename)[0] + '.jpg'))
115+
osp.splitext(filename)[0] + '.png'))
116116

117117
for filename in sorted(os.listdir(now_dir))[TRAINING_LEN:]:
118118
img = mmcv.imread(osp.join(now_dir, filename))
119119
mmcv.imwrite(
120120
img[:, :, 0] // 128,
121121
osp.join(out_dir, 'annotations', 'validation',
122-
osp.splitext(filename)[0] + '.jpg'))
122+
osp.splitext(filename)[0] + '.png'))
123123

124124
print('Removing the temporary files...')
125125

@@ -147,14 +147,14 @@ def main():
147147
mmcv.imwrite(
148148
img[:, :, 0] // 128,
149149
osp.join(out_dir, 'annotations', 'training',
150-
osp.splitext(filename)[0] + '.jpg'))
150+
osp.splitext(filename)[0] + '.png'))
151151

152152
for filename in sorted(os.listdir(now_dir))[TRAINING_LEN:]:
153153
img = mmcv.imread(osp.join(now_dir, filename))
154154
mmcv.imwrite(
155155
img[:, :, 0] // 128,
156156
osp.join(out_dir, 'annotations', 'validation',
157-
osp.splitext(filename)[0] + '.jpg'))
157+
osp.splitext(filename)[0] + '.png'))
158158

159159
print('Removing the temporary files...')
160160

0 commit comments

Comments
 (0)
Please sign in to comment.