[FIx] Set default `backend_args` values to None (#2597)

## Motivation

In MMEngine >= 0.2.0, it might directly determine what the backend is by
using the `data_root` path.

## Modification

Set all default `backend_args` values are `None`.
pull/2612/merge
谢昕辰 2023-02-16 15:33:52 +08:00 committed by GitHub
parent 2e27f8b678
commit a947e3e754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 75 additions and 83 deletions

View File

@ -25,7 +25,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -25,7 +25,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -26,7 +26,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -25,7 +25,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -25,7 +25,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -25,7 +25,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -26,7 +26,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -26,7 +26,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -32,7 +32,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -25,7 +25,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -28,7 +28,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -25,7 +25,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -27,7 +27,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -25,7 +25,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -26,7 +26,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -25,7 +25,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -237,7 +237,7 @@ test_pipeline = [
] ]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [ tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')), dict(type='LoadImageFromFile', backend_args=None),
dict( dict(
type='TestTimeAug', type='TestTimeAug',
transforms=[ transforms=[

View File

@ -73,15 +73,14 @@ class BaseSegDataset(BaseDataset):
ignore_index (int): The label index to be ignored. Default: 255 ignore_index (int): The label index to be ignored. Default: 255
reduce_zero_label (bool): Whether to mark label zero as ignored. reduce_zero_label (bool): Whether to mark label zero as ignored.
Default to False. Default to False.
backend_args (dict): Arguments to instantiate a file backend. backend_args (dict, Optional): Arguments to instantiate a file backend.
See https://mmengine.readthedocs.io/en/latest/api/fileio.htm See https://mmengine.readthedocs.io/en/latest/api/fileio.htm
for details. Defaults to ``dict(backend='local')`` for details. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required. Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
""" """
METAINFO: dict = dict() METAINFO: dict = dict()
def __init__( def __init__(self,
self,
ann_file: str = '', ann_file: str = '',
img_suffix='.jpg', img_suffix='.jpg',
seg_map_suffix='.png', seg_map_suffix='.png',
@ -97,14 +96,13 @@ class BaseSegDataset(BaseDataset):
max_refetch: int = 1000, max_refetch: int = 1000,
ignore_index: int = 255, ignore_index: int = 255,
reduce_zero_label: bool = False, reduce_zero_label: bool = False,
backend_args: dict = dict(backend='local') backend_args: Optional[dict] = None) -> None:
) -> None:
self.img_suffix = img_suffix self.img_suffix = img_suffix
self.seg_map_suffix = seg_map_suffix self.seg_map_suffix = seg_map_suffix
self.ignore_index = ignore_index self.ignore_index = ignore_index
self.reduce_zero_label = reduce_zero_label self.reduce_zero_label = reduce_zero_label
self.backend_args = backend_args.copy() self.backend_args = backend_args.copy() if backend_args else None
self.data_root = data_root self.data_root = data_root
self.data_prefix = copy.copy(data_prefix) self.data_prefix = copy.copy(data_prefix)

View File

@ -1,6 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved. # Copyright (c) OpenMMLab. All rights reserved.
import warnings import warnings
from typing import Dict from typing import Dict, Optional
import mmcv import mmcv
import mmengine.fileio as fileio import mmengine.fileio as fileio
@ -56,14 +56,14 @@ class LoadAnnotations(MMCV_LoadAnnotations):
Defaults to 'pillow'. Defaults to 'pillow'.
backend_args (dict): Arguments to instantiate a file backend. backend_args (dict): Arguments to instantiate a file backend.
See https://mmengine.readthedocs.io/en/latest/api/fileio.htm See https://mmengine.readthedocs.io/en/latest/api/fileio.htm
for details. Defaults to ``dict(backend='local')`` for details. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required. Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
""" """
def __init__( def __init__(
self, self,
reduce_zero_label=None, reduce_zero_label=None,
backend_args=dict(backend='local'), backend_args=None,
imdecode_backend='pillow', imdecode_backend='pillow',
) -> None: ) -> None:
super().__init__( super().__init__(
@ -203,23 +203,21 @@ class LoadBiomedicalImageFromFile(BaseTransform):
to_float32 (bool): Whether to convert the loaded image to a float32 to_float32 (bool): Whether to convert the loaded image to a float32
numpy array. If set to False, the loaded image is an float64 array. numpy array. If set to False, the loaded image is an float64 array.
Defaults to True. Defaults to True.
backend_args (dict): Arguments to instantiate a file backend. backend_args (dict, Optional): Arguments to instantiate a file backend.
See https://mmengine.readthedocs.io/en/latest/api/fileio.htm See https://mmengine.readthedocs.io/en/latest/api/fileio.htm
for details. Defaults to ``dict(backend='local')`` for details. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required. Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
""" """
def __init__( def __init__(self,
self,
decode_backend: str = 'nifti', decode_backend: str = 'nifti',
to_xyz: bool = False, to_xyz: bool = False,
to_float32: bool = True, to_float32: bool = True,
backend_args: dict = dict(backend='local') backend_args: Optional[dict] = None) -> None:
) -> None:
self.decode_backend = decode_backend self.decode_backend = decode_backend
self.to_xyz = to_xyz self.to_xyz = to_xyz
self.to_float32 = to_float32 self.to_float32 = to_float32
self.backend_args = backend_args.copy() self.backend_args = backend_args.copy() if backend_args else None
def transform(self, results: Dict) -> Dict: def transform(self, results: Dict) -> Dict:
"""Functions to load image. """Functions to load image.
@ -295,24 +293,22 @@ class LoadBiomedicalAnnotation(BaseTransform):
to_float32 (bool): Whether to convert the loaded seg map to a float32 to_float32 (bool): Whether to convert the loaded seg map to a float32
numpy array. If set to False, the loaded image is an float64 array. numpy array. If set to False, the loaded image is an float64 array.
Defaults to True. Defaults to True.
backend_args (dict): Arguments to instantiate a file backend. backend_args (dict, Optional): Arguments to instantiate a file backend.
See :class:`mmengine.fileio` for details. See :class:`mmengine.fileio` for details.
Defaults to ``dict(backend='local')``. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required. Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
""" """
def __init__( def __init__(self,
self,
decode_backend: str = 'nifti', decode_backend: str = 'nifti',
to_xyz: bool = False, to_xyz: bool = False,
to_float32: bool = True, to_float32: bool = True,
backend_args: dict = dict(backend='local') backend_args: Optional[dict] = None) -> None:
) -> None:
super().__init__() super().__init__()
self.decode_backend = decode_backend self.decode_backend = decode_backend
self.to_xyz = to_xyz self.to_xyz = to_xyz
self.to_float32 = to_float32 self.to_float32 = to_float32
self.backend_args = backend_args.copy() self.backend_args = backend_args.copy() if backend_args else None
def transform(self, results: Dict) -> Dict: def transform(self, results: Dict) -> Dict:
"""Functions to load image. """Functions to load image.
@ -384,23 +380,21 @@ class LoadBiomedicalData(BaseTransform):
backend is 'nifti'. Defaults to 'nifti'. backend is 'nifti'. Defaults to 'nifti'.
to_xyz (bool): Whether transpose data from Z, Y, X to X, Y, Z. to_xyz (bool): Whether transpose data from Z, Y, X to X, Y, Z.
Defaults to False. Defaults to False.
backend_args (dict): Arguments to instantiate a file backend. backend_args (dict, Optional): Arguments to instantiate a file backend.
See https://mmengine.readthedocs.io/en/latest/api/fileio.htm See https://mmengine.readthedocs.io/en/latest/api/fileio.htm
for details. Defaults to ``dict(backend='local')`` for details. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required. Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
""" """
def __init__( def __init__(self,
self,
with_seg=False, with_seg=False,
decode_backend: str = 'numpy', decode_backend: str = 'numpy',
to_xyz: bool = False, to_xyz: bool = False,
backend_args: dict = dict(backend='local') backend_args: Optional[dict] = None) -> None: # noqa
) -> None: # noqa
self.with_seg = with_seg self.with_seg = with_seg
self.decode_backend = decode_backend self.decode_backend = decode_backend
self.to_xyz = to_xyz self.to_xyz = to_xyz
self.backend_args = backend_args.copy() self.backend_args = backend_args.copy() if backend_args else None
def transform(self, results: Dict) -> Dict: def transform(self, results: Dict) -> Dict:
"""Functions to load image. """Functions to load image.

View File

@ -1,7 +1,7 @@
# Copyright (c) OpenMMLab. All rights reserved. # Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp import os.path as osp
import warnings import warnings
from typing import Sequence from typing import Optional, Sequence
import mmcv import mmcv
import mmengine.fileio as fileio import mmengine.fileio as fileio
@ -30,9 +30,9 @@ class SegVisualizationHook(Hook):
interval (int): The interval of visualization. Defaults to 50. interval (int): The interval of visualization. Defaults to 50.
show (bool): Whether to display the drawn image. Default to False. show (bool): Whether to display the drawn image. Default to False.
wait_time (float): The interval of show (s). Defaults to 0. wait_time (float): The interval of show (s). Defaults to 0.
backend_args (dict): Arguments to instantiate a file backend. backend_args (dict, Optional): Arguments to instantiate a file backend.
See https://mmengine.readthedocs.io/en/latest/api/fileio.htm See https://mmengine.readthedocs.io/en/latest/api/fileio.htm
for details. Defaults to ``dict(backend='local')`` for details. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required. Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
""" """
@ -41,7 +41,7 @@ class SegVisualizationHook(Hook):
interval: int = 50, interval: int = 50,
show: bool = False, show: bool = False,
wait_time: float = 0., wait_time: float = 0.,
backend_args: dict = dict(backend='local')): backend_args: Optional[dict] = None):
self._visualizer: SegLocalVisualizer = \ self._visualizer: SegLocalVisualizer = \
SegLocalVisualizer.get_current_instance() SegLocalVisualizer.get_current_instance()
self.interval = interval self.interval = interval
@ -55,7 +55,7 @@ class SegVisualizationHook(Hook):
'needs to be excluded.') 'needs to be excluded.')
self.wait_time = wait_time self.wait_time = wait_time
self.backend_args = backend_args.copy() self.backend_args = backend_args.copy() if backend_args else None
self.draw = draw self.draw = draw
if not self.draw: if not self.draw:
warnings.warn('The draw is False, it means that the ' warnings.warn('The draw is False, it means that the '

View File

@ -57,9 +57,9 @@ class TestLoading:
results = transform(copy.deepcopy(results)) results = transform(copy.deepcopy(results))
assert results['gt_seg_map'].shape == (288, 512) assert results['gt_seg_map'].shape == (288, 512)
assert results['gt_seg_map'].dtype == np.uint8 assert results['gt_seg_map'].dtype == np.uint8
# assert repr(transform) == transform.__class__.__name__ + \ assert repr(transform) == transform.__class__.__name__ + \
# "(reduce_zero_label=True, imdecode_backend='pillow', " + \ "(reduce_zero_label=True, imdecode_backend='pillow', " + \
# "backend_args={'backend': 'local'})" 'backend_args=None)'
# reduce_zero_label # reduce_zero_label
transform = LoadAnnotations(reduce_zero_label=True) transform = LoadAnnotations(reduce_zero_label=True)
@ -241,7 +241,7 @@ class TestLoading:
"decode_backend='nifti', " "decode_backend='nifti', "
'to_xyz=False, ' 'to_xyz=False, '
'to_float32=True, ' 'to_float32=True, '
"backend_args={'backend': 'local'})") 'backend_args=None)')
def test_load_biomedical_annotation(self): def test_load_biomedical_annotation(self):
results = dict( results = dict(
@ -265,7 +265,7 @@ class TestLoading:
'with_seg=True, ' 'with_seg=True, '
"decode_backend='numpy', " "decode_backend='numpy', "
'to_xyz=False, ' 'to_xyz=False, '
"backend_args={'backend': 'local'})") 'backend_args=None)')
transform = LoadBiomedicalData(with_seg=False) transform = LoadBiomedicalData(with_seg=False)
results = transform(copy.deepcopy(input_results)) results = transform(copy.deepcopy(input_results))
@ -275,4 +275,4 @@ class TestLoading:
'with_seg=False, ' 'with_seg=False, '
"decode_backend='numpy', " "decode_backend='numpy', "
'to_xyz=False, ' 'to_xyz=False, '
"backend_args={'backend': 'local'})") 'backend_args=None)')