Skip to content

Commit

Permalink
use mmcv.init_dist (open-mmlab#1851)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellock authored Dec 22, 2019
1 parent ed9d42a commit 7ef08d3
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ repos:
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-yapf
rev: 80b9cd2f0f3b1f3456a77eff3ddbaf08f18c08ae
rev: v0.29.0
hooks:
- id: yapf
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v2.4.0
hooks:
- id: flake8
- id: trailing-whitespace
Expand Down
9 changes: 4 additions & 5 deletions mmdet/apis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from .env import get_root_logger, init_dist, set_random_seed
from .inference import (async_inference_detector, inference_detector,
init_detector, show_result, show_result_pyplot)
from .train import train_detector
from .train import get_root_logger, set_random_seed, train_detector

__all__ = [
'async_inference_detector', 'init_dist', 'get_root_logger',
'set_random_seed', 'train_detector', 'init_detector', 'inference_detector',
'show_result', 'show_result_pyplot'
'get_root_logger', 'set_random_seed', 'train_detector', 'init_detector',
'async_inference_detector', 'inference_detector', 'show_result',
'show_result_pyplot'
]
69 changes: 0 additions & 69 deletions mmdet/apis/env.py

This file was deleted.

27 changes: 24 additions & 3 deletions mmdet/apis/train.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
from __future__ import division
import logging
import random
import re
from collections import OrderedDict

import numpy as np
import torch
import torch.distributed as dist
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import DistSamplerSeedHook, Runner, obj_from_dict
from mmcv.runner import (DistSamplerSeedHook, Runner, get_dist_info,
obj_from_dict)

from mmdet import datasets
from mmdet.core import (CocoDistEvalmAPHook, CocoDistEvalRecallHook,
DistEvalmAPHook, DistOptimizerHook, Fp16OptimizerHook)
from mmdet.datasets import DATASETS, build_dataloader
from mmdet.models import RPN
from .env import get_root_logger


def set_random_seed(seed):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)


def get_root_logger(log_level=logging.INFO):
logger = logging.getLogger()
if not logger.hasHandlers():
logging.basicConfig(
format='%(asctime)s - %(levelname)s - %(message)s',
level=log_level)
rank, _ = get_dist_info()
if rank != 0:
logger.setLevel('ERROR')
return logger


def parse_losses(losses):
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mmcv>=0.2.10
numpy
albumentations>=0.3.2
imagecorruptions
matplotlib
mmcv>=0.2.15
numpy
pycocotools
six
terminaltables
pycocotools
torch>=1.1
torchvision
imagecorruptions
albumentations>=0.3.2
3 changes: 1 addition & 2 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import torch
import torch.distributed as dist
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import get_dist_info, load_checkpoint
from mmcv.runner import get_dist_info, init_dist, load_checkpoint

from mmdet.apis import init_dist
from mmdet.core import coco_eval, results2json, wrap_fp16_model
from mmdet.datasets import build_dataloader, build_dataset
from mmdet.models import build_detector
Expand Down
4 changes: 2 additions & 2 deletions tools/test_robustness.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import torch
import torch.distributed as dist
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import get_dist_info, load_checkpoint
from mmcv.runner import get_dist_info, init_dist, load_checkpoint
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
from robustness_eval import get_results

from mmdet import datasets
from mmdet.apis import init_dist, set_random_seed
from mmdet.apis import set_random_seed
from mmdet.core import (eval_map, fast_eval_recall, results2json,
wrap_fp16_model)
from mmdet.datasets import build_dataloader, build_dataset
Expand Down
4 changes: 2 additions & 2 deletions tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import torch
from mmcv import Config
from mmcv.runner import init_dist

from mmdet import __version__
from mmdet.apis import (get_root_logger, init_dist, set_random_seed,
train_detector)
from mmdet.apis import get_root_logger, set_random_seed, train_detector
from mmdet.datasets import build_dataset
from mmdet.models import build_detector

Expand Down

0 comments on commit 7ef08d3

Please sign in to comment.