Skip to content

Commit

Permalink
support open-mmlab#6915: fix format problem
Browse files Browse the repository at this point in the history
  • Loading branch information
CCODING04 committed Mar 16, 2022
1 parent a11f278 commit 7f90301
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 46 deletions.
23 changes: 11 additions & 12 deletions mmdet/utils/misc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os
import glob
import os
import os.path as osp
import warnings

import mmcv
from mmcv.utils import print_log


def find_latest_checkpoint(path, suffix='pth'):
"""Find the latest checkpoint from the working directory.
Expand Down Expand Up @@ -42,31 +43,29 @@ def find_latest_checkpoint(path, suffix='pth'):


def update_data_root(cfg, logger=None):
"""Update data root according to environmental variable MMDET_DATASETS.
"""Update data root according to env MMDET_DATASETS.
If set env MMDET_DATASETS, update cfg.data_root according to MMDET_DATASETS.
Otherwise, using cfg.data_root as default.
If set env MMDET_DATASETS, update cfg.data_root according to
MMDET_DATASETS. Otherwise, using cfg.data_root as default.
Args:
cfg (mmcv.Config): The model config need to modify
data_root_n (str): The data root set
logger (logging.Logger | str | None): the way to print msg
"""
if 'MMDET_DATASETS' not in os.environ:
print_log(
f"Not set env MMDET_DATASETS, using {cfg.data_root} as data root.",
f'Not set env MMDET_DATASETS, using {cfg.data_root} as data root.',
logger)
return None
else:
dst_root = os.environ['MMDET_DATASETS']
print_log(
f"Set env MMDET_DATASETS={dst_root}, using MMDET_DATASETS as data root.",
logger)
f'Set env MMDET_DATASETS={dst_root}, \
using MMDET_DATASETS as data root.', logger)

assert isinstance(cfg, mmcv.Config), \
f"cfg got wrong type: {type(cfg)}, expected mmcv.Config"
f'cfg got wrong type: {type(cfg)}, expected mmcv.Config'

def update(cfg, src_str, dst_str):
for k, v in cfg.items():
if isinstance(v, mmcv.ConfigDict):
Expand All @@ -75,4 +74,4 @@ def update(cfg, src_str, dst_str):
cfg[k] = v.replace(src_str, dst_str)

update(cfg.data, cfg.data_root, dst_root)
cfg.data_root = dst_root
cfg.data_root = dst_root
2 changes: 1 addition & 1 deletion tools/misc/browse_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
from mmdet.core.utils import mask2ndarray
from mmdet.core.visualization import imshow_det_bboxes
from mmdet.datasets.builder import build_dataset

from mmdet.utils import update_data_root


def parse_args():
parser = argparse.ArgumentParser(description='Browse a dataset')
parser.add_argument('config', help='train config file path')
Expand Down
3 changes: 1 addition & 2 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
from mmdet.datasets import (build_dataloader, build_dataset,
replace_ImageToTensor)
from mmdet.models import build_detector
from mmdet.utils import setup_multi_processes
from mmdet.utils import setup_multi_processes, update_data_root

from mmdet.utils import update_data_root

def parse_args():
parser = argparse.ArgumentParser(
Expand Down
6 changes: 3 additions & 3 deletions tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from mmdet.apis import init_random_seed, set_random_seed, train_detector
from mmdet.datasets import build_dataset
from mmdet.models import build_detector
from mmdet.utils import collect_env, get_root_logger, setup_multi_processes
from mmdet.utils import (collect_env, get_root_logger, setup_multi_processes,
update_data_root)

from mmdet.utils import update_data_root

def parse_args():
parser = argparse.ArgumentParser(description='Train a detector')
Expand Down Expand Up @@ -102,7 +102,7 @@ def main():

# update data root according to MMDET_DATASETS
update_data_root(cfg)

if args.cfg_options is not None:
cfg.merge_from_dict(args.cfg_options)

Expand Down
28 changes: 0 additions & 28 deletions tools/utils.py

This file was deleted.

0 comments on commit 7f90301

Please sign in to comment.