Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-haochen committed Apr 24, 2020
2 parents 690a04b + f41b5f4 commit f1e9c6e
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 8 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ Name | inf. time | box AP | download

Name | inf. time | box AP | download
--- |:---:|:---:|:---:
[FCOS_RT_DLA_34_4x_shtw](configs/FCOS-Detection/FCOS_RT/MS_DLA_34_4x_syncbn_shared_towers.yaml) | 52 FPS | 39.1 | [model](https://cloudstor.aarnet.edu.au/plus/s/4vc3XwQezyhNvnB/download)
[FCOS_RT_DLA_34_4x](configs/FCOS-Detection/FCOS_RT/MS_DLA_34_4x_syncbn.yaml) | 46 FPS | 40.3 | [model](https://cloudstor.aarnet.edu.au/plus/s/zNPNyTkizaOOsUQ/download)
[FCOS_RT_R_50_4x](configs/FCOS-Detection/FCOS_RT/MS_R_50_4x_syncbn.yaml) | 38 FPS | 40.2 | [model](https://cloudstor.aarnet.edu.au/plus/s/TlnlXUr6lNNSyoZ/download)
[FCOS_RT_MS_DLA_34_4x_shtw](configs/FCOS-Detection/FCOS_RT/MS_DLA_34_4x_syncbn_shared_towers.yaml) | 52 FPS | 39.1 | [model](https://cloudstor.aarnet.edu.au/plus/s/4vc3XwQezyhNvnB/download)
[FCOS_RT_MS_DLA_34_4x](configs/FCOS-Detection/FCOS_RT/MS_DLA_34_4x_syncbn.yaml) | 46 FPS | 40.3 | [model](https://cloudstor.aarnet.edu.au/plus/s/zNPNyTkizaOOsUQ/download)
[FCOS_RT_MS_R_50_4x](configs/FCOS-Detection/FCOS_RT/MS_R_50_4x_syncbn.yaml) | 38 FPS | 40.2 | [model](https://cloudstor.aarnet.edu.au/plus/s/TlnlXUr6lNNSyoZ/download)

*Inference time is measured on a NVIDIA 1080Ti with batch size 1.*
If you prefer BN in FCOS heads, please try the following models.

Name | inf. time | box AP | download
--- |:---:|:---:|:---:
[FCOS_RT_MS_DLA_34_4x_shtw_bn](configs/FCOS-Detection/FCOS_RT/MS_DLA_34_4x_syncbn_shared_towers_bn_head.yaml) | 52 FPS | 38.9 | [model](https://cloudstor.aarnet.edu.au/plus/s/rdmHHSs4oCg7l7U/download)
[FCOS_RT_MS_DLA_34_4x_bn](configs/FCOS-Detection/FCOS_RT/MS_DLA_34_4x_syncbn_bn_head.yaml) | 48 FPS | 39.4 | [model](https://cloudstor.aarnet.edu.au/plus/s/T5httPVo1VndbD4/download)
[FCOS_RT_MS_R_50_4x_bn](configs/FCOS-Detection/FCOS_RT/MS_R_50_4x_syncbn_bn_head.yaml) | 40 FPS | 39.3 | [model](https://cloudstor.aarnet.edu.au/plus/s/dHNUNs0YxVhZAmg/download)

*Inference time is measured on a NVIDIA 1080Ti with batch size 1. Real-time models use shorter side 512 for inference.*

### COCO Instance Segmentation Baselines with [BlendMask](https://arxiv.org/abs/2001.00309)

Expand Down
26 changes: 24 additions & 2 deletions adet/modeling/fcos/fcos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from torch import nn
from torch.nn import functional as F

from detectron2.layers import ShapeSpec
from detectron2.layers import ShapeSpec, NaiveSyncBatchNorm
from detectron2.modeling.proposal_generator.build import PROPOSAL_GENERATOR_REGISTRY

from adet.layers import DFConv2d, IOULoss, NaiveGroupNorm
Expand All @@ -25,6 +25,19 @@ def forward(self, input):
return input * self.scale


class ModuleListDial(nn.ModuleList):
def __init__(self, modules=None):
super(ModuleListDial, self).__init__(modules)
self.cur_position = 0

def forward(self, x):
result = self[self.cur_position](x)
self.cur_position += 1
if self.cur_position >= len(self):
self.cur_position = 0
return result


@PROPOSAL_GENERATOR_REGISTRY.register()
class FCOS(nn.Module):
"""
Expand Down Expand Up @@ -184,6 +197,7 @@ def __init__(self, cfg, input_shape: List[ShapeSpec]):
"share": (cfg.MODEL.FCOS.NUM_SHARE_CONVS,
False)}
norm = None if cfg.MODEL.FCOS.NORM == "none" else cfg.MODEL.FCOS.NORM
self.num_levels = len(input_shape)

in_channels = [s.channels for s in input_shape]
assert len(set(in_channels)) == 1, "Each level must have the same channel!"
Expand All @@ -206,6 +220,14 @@ def __init__(self, cfg, input_shape: List[ShapeSpec]):
tower.append(nn.GroupNorm(32, in_channels))
elif norm == "NaiveGN":
tower.append(NaiveGroupNorm(32, in_channels))
elif norm == "BN":
tower.append(ModuleListDial([
nn.BatchNorm2d(in_channels) for _ in range(self.num_levels)
]))
elif norm == "SyncBN":
tower.append(ModuleListDial([
NaiveSyncBatchNorm(in_channels) for _ in range(self.num_levels)
]))
tower.append(nn.ReLU())
self.add_module('{}_tower'.format(head),
nn.Sequential(*tower))
Expand All @@ -225,7 +247,7 @@ def __init__(self, cfg, input_shape: List[ShapeSpec]):
)

if cfg.MODEL.FCOS.USE_SCALE:
self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in self.fpn_strides])
self.scales = nn.ModuleList([Scale(init_value=1.0) for _ in range(self.num_levels)])
else:
self.scales = None

Expand Down
26 changes: 26 additions & 0 deletions configs/FCOS-Detection/FCOS_RT/MS_DLA_34_4x_syncbn_bn_head.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
_BASE_: "../Base-FCOS.yaml"
INPUT:
MIN_SIZE_TRAIN: (256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608)
MAX_SIZE_TRAIN: 900
MAX_SIZE_TEST: 736
MIN_SIZE_TEST: 512
MODEL:
BACKBONE:
NAME: "build_fcos_dla_fpn_backbone"
FREEZE_AT: -1
WEIGHTS: "http://dl.yf.io/dla/models/imagenet/dla34-ba72cf86.pth"
DLA:
CONV_BODY: "DLA34"
NORM: "SyncBN"
FPN:
IN_FEATURES: ["level3", "level4", "level5"]
FCOS:
TOP_LEVELS: 0
SIZES_OF_INTEREST: [64, 128]
FPN_STRIDES: [8, 16, 32]
IN_FEATURES: ['p3', 'p4', 'p5']
NORM: "SyncBN"
SOLVER:
STEPS: (300000, 340000)
MAX_ITER: 360000
OUTPUT_DIR: "output/fcos/FCOS_RT_MS_DLA_34_4x_syncbn_bn_head"
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ MODEL:
SOLVER:
STEPS: (300000, 340000)
MAX_ITER: 360000
OUTPUT_DIR: "output/fcos/MS_DLA_34_4x_syncbn_shared_towers"
OUTPUT_DIR: "output/fcos/FCOS_RT_MS_DLA_34_4x_syncbn_shared_towers"
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
_BASE_: "../Base-FCOS.yaml"
INPUT:
MIN_SIZE_TRAIN: (256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608)
MAX_SIZE_TRAIN: 900
MAX_SIZE_TEST: 736
MIN_SIZE_TEST: 512
MODEL:
BACKBONE:
NAME: "build_fcos_dla_fpn_backbone"
FREEZE_AT: -1
WEIGHTS: "http://dl.yf.io/dla/models/imagenet/dla34-ba72cf86.pth"
DLA:
CONV_BODY: "DLA34"
NORM: "SyncBN"
FPN:
IN_FEATURES: ["level3", "level4", "level5"]
FCOS:
TOP_LEVELS: 0
SIZES_OF_INTEREST: [64, 128]
FPN_STRIDES: [8, 16, 32]
IN_FEATURES: ['p3', 'p4', 'p5']
NUM_SHARE_CONVS: 4
NUM_BOX_CONVS: 0
NUM_CLS_CONVS: 0
NORM: "SyncBN"
SOLVER:
STEPS: (300000, 340000)
MAX_ITER: 360000
OUTPUT_DIR: "output/fcos/FCOS_RT_MS_DLA_34_4x_syncbn_shared_towers_bn_head"
2 changes: 1 addition & 1 deletion configs/FCOS-Detection/FCOS_RT/MS_R_50_4x_syncbn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ MODEL:
SOLVER:
STEPS: (300000, 340000)
MAX_ITER: 360000
OUTPUT_DIR: "output/fcos/FCOS_RT_MS_R_50_4x"
OUTPUT_DIR: "output/fcos/FCOS_RT_MS_R_50_4x_syncbn"
21 changes: 21 additions & 0 deletions configs/FCOS-Detection/FCOS_RT/MS_R_50_4x_syncbn_bn_head.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
_BASE_: "../Base-FCOS.yaml"
INPUT:
MIN_SIZE_TRAIN: (256, 288, 320, 352, 384, 416, 448, 480, 512, 544, 576, 608)
MAX_SIZE_TRAIN: 900
MAX_SIZE_TEST: 736
MIN_SIZE_TEST: 512
MODEL:
WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl"
RESNETS:
DEPTH: 50
NORM: "SyncBN"
FCOS:
TOP_LEVELS: 0
SIZES_OF_INTEREST: [64, 128]
FPN_STRIDES: [8, 16, 32]
IN_FEATURES: ['p3', 'p4', 'p5']
NORM: "SyncBN"
SOLVER:
STEPS: (300000, 340000)
MAX_ITER: 360000
OUTPUT_DIR: "output/fcos/FCOS_RT_MS_R_50_4x_syncbn_bn_head"

0 comments on commit f1e9c6e

Please sign in to comment.