Skip to content

Commit

Permalink
[FIx] Set default backend_args values to None (#2597)
Browse files Browse the repository at this point in the history
## 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`.
  • Loading branch information
xiexinch committed Feb 16, 2023
1 parent 2e27f8b commit a947e3e
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 83 deletions.
2 changes: 1 addition & 1 deletion configs/_base_/datasets/ade20k.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/ade20k_640x640.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/chase_db1.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/cityscapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/coco-stuff10k.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/coco-stuff164k.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/hrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/isaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/loveda.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/pascal_context_59.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/pascal_voc12.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/pascal_voc12_aug.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/potsdam.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/stare.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/vaihingen.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
2 changes: 1 addition & 1 deletion docs/en/migration/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ test_pipeline = [
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', backend_args=dict(backend='local')),
dict(type='LoadImageFromFile', backend_args=None),
dict(
type='TestTimeAug',
transforms=[
Expand Down
42 changes: 20 additions & 22 deletions mmseg/datasets/basesegdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,38 +73,36 @@ class BaseSegDataset(BaseDataset):
ignore_index (int): The label index to be ignored. Default: 255
reduce_zero_label (bool): Whether to mark label zero as ignored.
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
for details. Defaults to ``dict(backend='local')``
for details. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
"""
METAINFO: dict = dict()

def __init__(
self,
ann_file: str = '',
img_suffix='.jpg',
seg_map_suffix='.png',
metainfo: Optional[dict] = None,
data_root: Optional[str] = None,
data_prefix: dict = dict(img_path='', seg_map_path=''),
filter_cfg: Optional[dict] = None,
indices: Optional[Union[int, Sequence[int]]] = None,
serialize_data: bool = True,
pipeline: List[Union[dict, Callable]] = [],
test_mode: bool = False,
lazy_init: bool = False,
max_refetch: int = 1000,
ignore_index: int = 255,
reduce_zero_label: bool = False,
backend_args: dict = dict(backend='local')
) -> None:
def __init__(self,
ann_file: str = '',
img_suffix='.jpg',
seg_map_suffix='.png',
metainfo: Optional[dict] = None,
data_root: Optional[str] = None,
data_prefix: dict = dict(img_path='', seg_map_path=''),
filter_cfg: Optional[dict] = None,
indices: Optional[Union[int, Sequence[int]]] = None,
serialize_data: bool = True,
pipeline: List[Union[dict, Callable]] = [],
test_mode: bool = False,
lazy_init: bool = False,
max_refetch: int = 1000,
ignore_index: int = 255,
reduce_zero_label: bool = False,
backend_args: Optional[dict] = None) -> None:

self.img_suffix = img_suffix
self.seg_map_suffix = seg_map_suffix
self.ignore_index = ignore_index
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_prefix = copy.copy(data_prefix)
Expand Down
60 changes: 27 additions & 33 deletions mmseg/datasets/transforms/loading.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.
import warnings
from typing import Dict
from typing import Dict, Optional

import mmcv
import mmengine.fileio as fileio
Expand Down Expand Up @@ -56,14 +56,14 @@ class LoadAnnotations(MMCV_LoadAnnotations):
Defaults to 'pillow'.
backend_args (dict): Arguments to instantiate a file backend.
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.
"""

def __init__(
self,
reduce_zero_label=None,
backend_args=dict(backend='local'),
backend_args=None,
imdecode_backend='pillow',
) -> None:
super().__init__(
Expand Down Expand Up @@ -203,23 +203,21 @@ class LoadBiomedicalImageFromFile(BaseTransform):
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.
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
for details. Defaults to ``dict(backend='local')``
for details. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
"""

def __init__(
self,
decode_backend: str = 'nifti',
to_xyz: bool = False,
to_float32: bool = True,
backend_args: dict = dict(backend='local')
) -> None:
def __init__(self,
decode_backend: str = 'nifti',
to_xyz: bool = False,
to_float32: bool = True,
backend_args: Optional[dict] = None) -> None:
self.decode_backend = decode_backend
self.to_xyz = to_xyz
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:
"""Functions to load image.
Expand Down Expand Up @@ -295,24 +293,22 @@ class LoadBiomedicalAnnotation(BaseTransform):
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.
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.
Defaults to ``dict(backend='local')``.
Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
"""

def __init__(
self,
decode_backend: str = 'nifti',
to_xyz: bool = False,
to_float32: bool = True,
backend_args: dict = dict(backend='local')
) -> None:
def __init__(self,
decode_backend: str = 'nifti',
to_xyz: bool = False,
to_float32: bool = True,
backend_args: Optional[dict] = None) -> None:
super().__init__()
self.decode_backend = decode_backend
self.to_xyz = to_xyz
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:
"""Functions to load image.
Expand Down Expand Up @@ -384,23 +380,21 @@ class LoadBiomedicalData(BaseTransform):
backend is 'nifti'. Defaults to 'nifti'.
to_xyz (bool): Whether transpose data from Z, Y, X to X, Y, Z.
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
for details. Defaults to ``dict(backend='local')``
for details. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
"""

def __init__(
self,
with_seg=False,
decode_backend: str = 'numpy',
to_xyz: bool = False,
backend_args: dict = dict(backend='local')
) -> None: # noqa
def __init__(self,
with_seg=False,
decode_backend: str = 'numpy',
to_xyz: bool = False,
backend_args: Optional[dict] = None) -> None: # noqa
self.with_seg = with_seg
self.decode_backend = decode_backend
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:
"""Functions to load image.
Expand Down
10 changes: 5 additions & 5 deletions mmseg/engine/hooks/visualization_hook.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os.path as osp
import warnings
from typing import Sequence
from typing import Optional, Sequence

import mmcv
import mmengine.fileio as fileio
Expand Down Expand Up @@ -30,9 +30,9 @@ class SegVisualizationHook(Hook):
interval (int): The interval of visualization. Defaults to 50.
show (bool): Whether to display the drawn image. Default to False.
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
for details. Defaults to ``dict(backend='local')``
for details. Defaults to None.
Notes: mmcv>=2.0.0rc4, mmengine>=0.2.0 required.
"""

Expand All @@ -41,7 +41,7 @@ def __init__(self,
interval: int = 50,
show: bool = False,
wait_time: float = 0.,
backend_args: dict = dict(backend='local')):
backend_args: Optional[dict] = None):
self._visualizer: SegLocalVisualizer = \
SegLocalVisualizer.get_current_instance()
self.interval = interval
Expand All @@ -55,7 +55,7 @@ def __init__(self,
'needs to be excluded.')

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
if not self.draw:
warnings.warn('The draw is False, it means that the '
Expand Down
Loading

0 comments on commit a947e3e

Please sign in to comment.