From 4927b0ed03efb3b8bee0819b179e4173808a35ea Mon Sep 17 00:00:00 2001 From: angiecao <47491536+angiecao@users.noreply.github.com> Date: Wed, 9 Aug 2023 10:15:50 +0800 Subject: [PATCH] [Fix] Fix module PascalContextDataset (#3235) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 --- mmseg/datasets/pascal_context.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mmseg/datasets/pascal_context.py b/mmseg/datasets/pascal_context.py index a6b2fba7b4..82d00a9b30 100644 --- a/mmseg/datasets/pascal_context.py +++ b/mmseg/datasets/pascal_context.py @@ -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 @@ def __init__(self, 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)