[Fix] Fix module PascalContextDataset (#3235)

## Motivation

- 'PascalContextDataset' object has no attribute 'file_client', it will
cause an error.
- The attribute ‘ann_file’ is not allowed to be empty, otherwise, an
error will be reported.

## Modification
- Replace file_client with fileio
pull/3254/head
angiecao 2023-08-09 10:15:50 +08:00 committed by GitHub
parent 1235217667
commit 4927b0ed03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 9 deletions

View File

@ -1,5 +1,5 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import mmengine.fileio as fileio
from mmseg.registry import DATASETS
from .basesegdataset import BaseSegDataset
@ -46,18 +46,18 @@ class PascalContextDataset(BaseSegDataset):
[255, 71, 0], [0, 235, 255], [0, 173, 255], [31, 0, 255]])
def __init__(self,
ann_file: str,
ann_file='',
img_suffix='.jpg',
seg_map_suffix='.png',
reduce_zero_label=False,
**kwargs) -> None:
super().__init__(
img_suffix=img_suffix,
seg_map_suffix=seg_map_suffix,
ann_file=ann_file,
reduce_zero_label=False,
reduce_zero_label=reduce_zero_label,
**kwargs)
assert self.file_client.exists(
self.data_prefix['img_path']) and osp.isfile(self.ann_file)
assert fileio.exists(self.data_prefix['img_path'], self.backend_args)
@DATASETS.register_module()
@ -66,8 +66,10 @@ class PascalContextDataset59(BaseSegDataset):
In segmentation map annotation for PascalContext, 0 stands for background,
which is included in 60 categories. ``reduce_zero_label`` is fixed to
False. The ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is
True. The ``img_suffix`` is fixed to '.jpg' and ``seg_map_suffix`` is
fixed to '.png'.
Noted: If the background is 255 and the ids of categories are from 0 to 58,
``reduce_zero_label`` needs to be set to False.
Args:
ann_file (str): Annotation file path.
@ -100,7 +102,7 @@ class PascalContextDataset59(BaseSegDataset):
[255, 71, 0], [0, 235, 255], [0, 173, 255], [31, 0, 255]])
def __init__(self,
ann_file: str,
ann_file='',
img_suffix='.jpg',
seg_map_suffix='.png',
reduce_zero_label=True,
@ -111,5 +113,4 @@ class PascalContextDataset59(BaseSegDataset):
ann_file=ann_file,
reduce_zero_label=reduce_zero_label,
**kwargs)
assert self.file_client.exists(
self.data_prefix['img_path']) and osp.isfile(self.ann_file)
assert fileio.exists(self.data_prefix['img_path'], self.backend_args)