Skip to content

Commit

Permalink
[Fix] Robust mapping from image path to seg map path (#3091)
Browse files Browse the repository at this point in the history
## Motivation

Suppose an image is named `jpg.jpg` and its corresponding segmap is
named `jpg.png`.
The original implementation will try to read segmap from `png.png` and
causes FileNotfoundError

## Modification

Only replace the suffix, instead of full string search and replacement. 

## BC-breaking (Optional)

Probably no. 

## Use cases (Optional)


## Checklist

1. Pre-commit or other linting tools are used to fix the potential lint
issues.
2. The modification is covered by complete unit tests. If not, please
add more unit test to ensure the correctness.
3. If the modification has potential influence on downstream projects,
this PR should be tested with downstream projects, like MMDet or
MMDet3D.
4. The documentation has been modified accordingly, like docstring or
example tutorials.

---------

Co-authored-by: 谢昕辰 <[email protected]>
Co-authored-by: CSH <[email protected]>
  • Loading branch information
3 people committed Jun 16, 2023
1 parent 279b897 commit c30d506
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mmseg/datasets/basesegdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def load_data_list(self) -> List[dict]:
data_info['seg_fields'] = []
data_list.append(data_info)
else:
_suffix_len = len(self.img_suffix)
for img in fileio.list_dir_or_file(
dir_path=img_dir,
list_dir=False,
Expand All @@ -260,7 +261,7 @@ def load_data_list(self) -> List[dict]:
backend_args=self.backend_args):
data_info = dict(img_path=osp.join(img_dir, img))
if ann_dir is not None:
seg_map = img.replace(self.img_suffix, self.seg_map_suffix)
seg_map = img[:-_suffix_len] + self.seg_map_suffix
data_info['seg_map_path'] = osp.join(ann_dir, seg_map)
data_info['label_map'] = self.label_map
data_info['reduce_zero_label'] = self.reduce_zero_label
Expand Down

0 comments on commit c30d506

Please sign in to comment.