Skip to content

Commit

Permalink
Use isort to sort imports and setup travis (open-mmlab#1085)
Browse files Browse the repository at this point in the history
* add isort config

* use isort to sort imports

* add isort to travis
  • Loading branch information
hellock authored Jul 31, 2019
1 parent 864880d commit d2483e1
Show file tree
Hide file tree
Showing 65 changed files with 127 additions and 123 deletions.
7 changes: 7 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[isort]
line_length = 79
multi_line_output = 0
known_first_party = mmdet
known_third_party = mmcv,numpy,matplotlib,pycocotools,six,seaborn,terminaltables,torch,torchvision
no_lines_before = STDLIB,LOCALFOLDER
default_section = THIRDPARTY
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dist: xenial
language: python

install:
- pip install flake8 yapf
- pip install isort flake8 yapf

python:
- "3.5"
Expand All @@ -11,4 +11,5 @@ python:

script:
- flake8
- isort -rc --diff mmdet/ tools/
- yapf -r -d --style .style.yapf mmdet/ tools/
10 changes: 4 additions & 6 deletions mmdet/apis/train.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
from __future__ import division

import re
from collections import OrderedDict

import torch
from mmcv.runner import Runner, DistSamplerSeedHook, obj_from_dict
from mmcv.parallel import MMDataParallel, MMDistributedDataParallel
from mmcv.runner import DistSamplerSeedHook, Runner, obj_from_dict

from mmdet import datasets
from mmdet.core import (DistOptimizerHook, DistEvalmAPHook,
CocoDistEvalRecallHook, CocoDistEvalmAPHook,
Fp16OptimizerHook)
from mmdet.datasets import build_dataloader, 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

Expand Down
2 changes: 1 addition & 1 deletion mmdet/core/anchor/anchor_target.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from ..bbox import assign_and_sample, build_assigner, PseudoSampler, bbox2delta
from ..bbox import PseudoSampler, assign_and_sample, bbox2delta, build_assigner
from ..utils import multi_apply


Expand Down
4 changes: 2 additions & 2 deletions mmdet/core/anchor/guided_anchor_target.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch

from ..bbox import build_assigner, build_sampler, PseudoSampler
from ..utils import unmap, multi_apply
from ..bbox import PseudoSampler, build_assigner, build_sampler
from ..utils import multi_apply, unmap


def calc_region(bbox, ratio, featmap_size=None):
Expand Down
2 changes: 1 addition & 1 deletion mmdet/core/bbox/assigners/approx_max_iou_assigner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch

from .max_iou_assigner import MaxIoUAssigner
from ..geometry import bbox_overlaps
from .max_iou_assigner import MaxIoUAssigner


class ApproxMaxIoUAssigner(MaxIoUAssigner):
Expand Down
4 changes: 2 additions & 2 deletions mmdet/core/bbox/assigners/max_iou_assigner.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import torch

from .base_assigner import BaseAssigner
from .assign_result import AssignResult
from ..geometry import bbox_overlaps
from .assign_result import AssignResult
from .base_assigner import BaseAssigner


class MaxIoUAssigner(BaseAssigner):
Expand Down
2 changes: 1 addition & 1 deletion mmdet/core/bbox/bbox_target.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch

from .transforms import bbox2delta
from ..utils import multi_apply
from .transforms import bbox2delta


def bbox_target(pos_bboxes_list,
Expand Down
2 changes: 1 addition & 1 deletion mmdet/core/bbox/samplers/combined_sampler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .base_sampler import BaseSampler
from ..assign_sampling import build_sampler
from .base_sampler import BaseSampler


class CombinedSampler(BaseSampler):
Expand Down
2 changes: 1 addition & 1 deletion mmdet/core/bbox/samplers/ohem_sampler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch

from .base_sampler import BaseSampler
from ..transforms import bbox2roi
from .base_sampler import BaseSampler


class OHEMSampler(BaseSampler):
Expand Down
6 changes: 3 additions & 3 deletions mmdet/core/evaluation/eval_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import numpy as np
import torch
import torch.distributed as dist
from mmcv.parallel import collate, scatter
from mmcv.runner import Hook
from mmcv.parallel import scatter, collate
from pycocotools.cocoeval import COCOeval
from torch.utils.data import Dataset

from .coco_utils import results2json, fast_eval_recall
from .mean_ap import eval_map
from mmdet import datasets
from .coco_utils import fast_eval_recall, results2json
from .mean_ap import eval_map


class DistEvalHook(Hook):
Expand Down
3 changes: 2 additions & 1 deletion mmdet/core/fp16/hooks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import copy

import torch
import torch.nn as nn
from mmcv.runner import OptimizerHook

from .utils import cast_tensor_type
from ..utils.dist_utils import allreduce_grads
from .utils import cast_tensor_type


class Fp16OptimizerHook(OptimizerHook):
Expand Down
4 changes: 2 additions & 2 deletions mmdet/core/mask/mask_target.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
import numpy as np
import mmcv
import numpy as np
import torch


def mask_target(pos_proposals_list, pos_assigned_gt_inds_list, gt_masks_list,
Expand Down
3 changes: 1 addition & 2 deletions mmdet/core/post_processing/merge_augs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import torch

import numpy as np
import torch

from mmdet.ops import nms
from ..bbox import bbox_mapping_back
Expand Down
4 changes: 2 additions & 2 deletions mmdet/core/utils/dist_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from collections import OrderedDict

import torch.distributed as dist
from torch._utils import (_flatten_dense_tensors, _unflatten_dense_tensors,
_take_tensors)
from mmcv.runner import OptimizerHook
from torch._utils import (_flatten_dense_tensors, _take_tensors,
_unflatten_dense_tensors)


def _allreduce_coalesced(tensors, world_size, bucket_size_mb=-1):
Expand Down
8 changes: 4 additions & 4 deletions mmdet/datasets/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from mmcv.parallel import DataContainer as DC
from torch.utils.data import Dataset

from .registry import DATASETS
from .transforms import (ImageTransform, BboxTransform, MaskTransform,
SegMapTransform, Numpy2Tensor)
from .utils import to_tensor, random_scale
from .extra_aug import ExtraAugmentation
from .registry import DATASETS
from .transforms import (BboxTransform, ImageTransform, MaskTransform,
Numpy2Tensor, SegMapTransform)
from .utils import random_scale, to_tensor


@DATASETS.register_module
Expand Down
4 changes: 2 additions & 2 deletions mmdet/datasets/loader/build_loader.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import platform
from functools import partial

from mmcv.runner import get_dist_info
from mmcv.parallel import collate
from mmcv.runner import get_dist_info
from torch.utils.data import DataLoader

from .sampler import GroupSampler, DistributedGroupSampler, DistributedSampler
from .sampler import DistributedGroupSampler, DistributedSampler, GroupSampler

if platform.system() != 'Windows':
# https://github.com/pytorch/pytorch/issues/973
Expand Down
7 changes: 3 additions & 4 deletions mmdet/datasets/loader/sampler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import division

import math
import torch
import numpy as np

import numpy as np
import torch
from mmcv.runner.utils import get_dist_info
from torch.utils.data import Sampler
from torch.utils.data import DistributedSampler as _DistributedSampler
from torch.utils.data import Sampler


class DistributedSampler(_DistributedSampler):
Expand Down
4 changes: 2 additions & 2 deletions mmdet/models/anchor_heads/anchor_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import torch.nn as nn
from mmcv.cnn import normal_init

from mmdet.core import (AnchorGenerator, anchor_target, delta2bbox,
multi_apply, multiclass_nms, force_fp32)
from mmdet.core import (AnchorGenerator, anchor_target, delta2bbox, force_fp32,
multi_apply, multiclass_nms)
from ..builder import build_loss
from ..registry import HEADS

Expand Down
4 changes: 2 additions & 2 deletions mmdet/models/anchor_heads/fcos_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import torch.nn as nn
from mmcv.cnn import normal_init

from mmdet.core import multi_apply, multiclass_nms, distance2bbox, force_fp32
from mmdet.core import distance2bbox, force_fp32, multi_apply, multiclass_nms
from ..builder import build_loss
from ..registry import HEADS
from ..utils import bias_init_with_prob, Scale, ConvModule
from ..utils import ConvModule, Scale, bias_init_with_prob

INF = 1e8

Expand Down
6 changes: 3 additions & 3 deletions mmdet/models/anchor_heads/ga_retina_head.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import torch.nn as nn
from mmcv.cnn import normal_init

from .guided_anchor_head import GuidedAnchorHead, FeatureAdaption
from ..registry import HEADS
from ..utils import bias_init_with_prob, ConvModule
from mmdet.ops import MaskedConv2d
from ..registry import HEADS
from ..utils import ConvModule, bias_init_with_prob
from .guided_anchor_head import FeatureAdaption, GuidedAnchorHead


@HEADS.register_module
Expand Down
2 changes: 1 addition & 1 deletion mmdet/models/anchor_heads/ga_rpn_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from mmdet.core import delta2bbox
from mmdet.ops import nms
from .guided_anchor_head import GuidedAnchorHead
from ..registry import HEADS
from .guided_anchor_head import GuidedAnchorHead


@HEADS.register_module
Expand Down
8 changes: 4 additions & 4 deletions mmdet/models/anchor_heads/guided_anchor_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import torch.nn as nn
from mmcv.cnn import normal_init

from mmdet.core import (AnchorGenerator, anchor_target, anchor_inside_flags,
ga_loc_target, ga_shape_target, delta2bbox,
multi_apply, multiclass_nms, force_fp32)
from mmdet.core import (AnchorGenerator, anchor_inside_flags, anchor_target,
delta2bbox, force_fp32, ga_loc_target, ga_shape_target,
multi_apply, multiclass_nms)
from mmdet.ops import DeformConv, MaskedConv2d
from ..builder import build_loss
from .anchor_head import AnchorHead
from ..registry import HEADS
from ..utils import bias_init_with_prob
from .anchor_head import AnchorHead


class FeatureAdaption(nn.Module):
Expand Down
4 changes: 2 additions & 2 deletions mmdet/models/anchor_heads/retina_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import torch.nn as nn
from mmcv.cnn import normal_init

from .anchor_head import AnchorHead
from ..registry import HEADS
from ..utils import bias_init_with_prob, ConvModule
from ..utils import ConvModule, bias_init_with_prob
from .anchor_head import AnchorHead


@HEADS.register_module
Expand Down
2 changes: 1 addition & 1 deletion mmdet/models/anchor_heads/rpn_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from mmdet.core import delta2bbox
from mmdet.ops import nms
from .anchor_head import AnchorHead
from ..registry import HEADS
from .anchor_head import AnchorHead


@HEADS.register_module
Expand Down
2 changes: 1 addition & 1 deletion mmdet/models/anchor_heads/ssd_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from mmcv.cnn import xavier_init

from mmdet.core import AnchorGenerator, anchor_target, multi_apply
from .anchor_head import AnchorHead
from ..losses import smooth_l1_loss
from ..registry import HEADS
from .anchor_head import AnchorHead


# TODO: add loss evaluator for SSD
Expand Down
2 changes: 1 addition & 1 deletion mmdet/models/backbones/hrnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from torch.nn.modules.batchnorm import _BatchNorm

from ..registry import BACKBONES
from ..utils import build_norm_layer, build_conv_layer
from ..utils import build_conv_layer, build_norm_layer
from .resnet import BasicBlock, Bottleneck


Expand Down
6 changes: 2 additions & 4 deletions mmdet/models/backbones/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import torch.nn as nn
import torch.utils.checkpoint as cp
from torch.nn.modules.batchnorm import _BatchNorm

from mmcv.cnn import constant_init, kaiming_init
from mmcv.runner import load_checkpoint
from torch.nn.modules.batchnorm import _BatchNorm

from mmdet.ops import DeformConv, ModulatedDeformConv, ContextBlock
from mmdet.models.plugins import GeneralizedAttention

from mmdet.ops import ContextBlock, DeformConv, ModulatedDeformConv
from ..registry import BACKBONES
from ..utils import build_conv_layer, build_norm_layer

Expand Down
4 changes: 2 additions & 2 deletions mmdet/models/backbones/resnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import torch.nn as nn

from mmdet.ops import DeformConv, ModulatedDeformConv
from .resnet import Bottleneck as _Bottleneck
from .resnet import ResNet
from ..registry import BACKBONES
from ..utils import build_conv_layer, build_norm_layer
from .resnet import Bottleneck as _Bottleneck
from .resnet import ResNet


class Bottleneck(_Bottleneck):
Expand Down
3 changes: 1 addition & 2 deletions mmdet/models/backbones/ssd_vgg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from mmcv.cnn import (VGG, xavier_init, constant_init, kaiming_init,
normal_init)
from mmcv.cnn import VGG, constant_init, kaiming_init, normal_init, xavier_init
from mmcv.runner import load_checkpoint

from ..registry import BACKBONES
Expand Down
4 changes: 2 additions & 2 deletions mmdet/models/bbox_heads/bbox_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import torch.nn as nn
import torch.nn.functional as F

from mmdet.core import (delta2bbox, multiclass_nms, bbox_target, force_fp32,
auto_fp16)
from mmdet.core import (auto_fp16, bbox_target, delta2bbox, force_fp32,
multiclass_nms)
from ..builder import build_loss
from ..losses import accuracy
from ..registry import HEADS
Expand Down
2 changes: 1 addition & 1 deletion mmdet/models/bbox_heads/convfc_bbox_head.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import torch.nn as nn

from .bbox_head import BBoxHead
from ..registry import HEADS
from ..utils import ConvModule
from .bbox_head import BBoxHead


@HEADS.register_module
Expand Down
4 changes: 2 additions & 2 deletions mmdet/models/builder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from torch import nn

from mmdet.utils import build_from_cfg
from .registry import (BACKBONES, NECKS, ROI_EXTRACTORS, SHARED_HEADS, HEADS,
LOSSES, DETECTORS)
from .registry import (BACKBONES, DETECTORS, HEADS, LOSSES, NECKS,
ROI_EXTRACTORS, SHARED_HEADS)


def build(cfg, registry, default_args=None):
Expand Down
Loading

0 comments on commit d2483e1

Please sign in to comment.