-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
163 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import torch | ||
from pathlib import Path | ||
|
||
MODEL_NAME = 'efficientdet-d0' | ||
|
||
BASE_PATH = Path('./') | ||
DATA_PATH = BASE_PATH / 'data' | ||
WEIGHTS_PATH = BASE_PATH / 'weights' | ||
MODEL_WEIGHTS = WEIGHTS_PATH / '{}.pth'.format(MODEL_NAME) | ||
|
||
ASPECT_RATIOS = [(1.0, 1.0), (1.4, 0.7), (0.7, 1.4)] | ||
NUM_SCALES = 3 | ||
ANCHOR_SCALE = 4.0 | ||
|
||
NUM_ANCHORS = len(ASPECT_RATIOS) * NUM_SCALES | ||
NUM_CLASSES = 90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/coco |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from model.det import EfficientDet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,37 @@ | ||
import torch | ||
import numpy as np | ||
import torch.nn as nn | ||
import torch.nn.functional as F | ||
|
||
from model.module import DepthWiseSeparableConvModule as DWSConv | ||
|
||
|
||
class Regresser(nn.Module): | ||
def __init__(self, n_features, n_repeats, n_anchors=9): | ||
super(Regresser, self).__init__() | ||
layers = [DWSConv(n_features, n_features) for _ in range(n_repeats)] | ||
class HeadNet(nn.Module): | ||
""" Box Regression and Classification Nets """ | ||
def __init__(self, n_features, out_channels, n_repeats): | ||
super(HeadNet, self).__init__() | ||
self.convs = nn.ModuleList() | ||
self.bns = nn.ModuleList() | ||
|
||
self.layers = nn.Sequential(*layers) | ||
self.head = nn.Sequential( | ||
nn.Conv2d(n_features, n_features, 3, padding=1, groups=n_features), | ||
nn.Conv2d(n_features, n_anchors * 4, 1) | ||
) | ||
|
||
def forward(self, inputs): | ||
inputs = self.layers(inputs) | ||
inputs = self.head(inputs) | ||
out = inputs | ||
return out | ||
for _ in range(n_repeats): | ||
self.convs.append(DWSConv(n_features, n_features, | ||
bath_norm=False, relu=False)) | ||
bn_levels = nn.ModuleList() | ||
for _ in range(5): | ||
bn = nn.BatchNorm2d(n_features, eps=1e-3, momentum=0.01) | ||
bn_levels.append(bn) | ||
self.bns.append(bn_levels) | ||
|
||
self.head = DWSConv(n_features, out_channels, bath_norm=False, relu=False, bias=True) | ||
|
||
class Classifier(nn.Module): | ||
def __init__(self, n_features, n_repeats, n_anchors=9, n_classes=90): | ||
super(Classifier, self).__init__() | ||
layers = [DWSConv(n_features, n_features) for _ in range(n_repeats)] | ||
def forward(self, inputs): | ||
outs = [] | ||
|
||
self.layers = nn.Sequential(*layers) | ||
self.head = nn.Sequential( | ||
nn.Conv2d(n_features, n_features, 3, padding=1, groups=n_features), | ||
nn.Conv2d(n_features, n_anchors * n_classes, 1) | ||
) | ||
for f_idx, f_map in enumerate(inputs): | ||
for conv, bn in zip(self.convs, self.bns): | ||
f_map = conv(f_map) | ||
f_map = bn[f_idx](f_map) | ||
f_map = F.relu(f_map) | ||
outs.append(self.head(f_map)) | ||
|
||
def forward(self, inputs): | ||
inputs = self.layers(inputs) | ||
inputs = self.head(inputs) | ||
out = inputs | ||
return out | ||
return outs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import torch | ||
from model import EfficientDet | ||
import config as cfg | ||
from model.utils import efficientdet_params, count_parameters | ||
|
||
|
||
""" Quick test on parameters number """ | ||
|
||
|
||
model = EfficientDet.from_pretrained().to('cpu') | ||
|
||
model.train() | ||
params = count_parameters(model) | ||
|
||
print('Model: {}, params: {:.6f}M, params in paper: {}'.format(cfg.MODEL_NAME, params / 1e6, | ||
efficientdet_params(cfg.MODEL_NAME)['params'])) | ||
print(' Backbone: {:.6f}M'.format(count_parameters(model.backbone) / 1e6)) | ||
print(' Adjuster: {:.6f}M'.format(count_parameters(model.adjuster) / 1e6)) | ||
print(' BiFPN: {:.6f}M'.format(count_parameters(model.bifpn) / 1e6)) | ||
print(' Head: {:.6f}M'.format((count_parameters(model.classifier) + | ||
count_parameters(model.regresser)) / 1e6)) | ||
|
||
# model.initialize_weights() | ||
|
||
image_size = efficientdet_params(cfg.MODEL_NAME)['R_input'] | ||
x = torch.rand(1, 3, image_size, image_size) | ||
box, cls = model(x) | ||
|
||
for b, c in zip(box, cls): | ||
print(b.shape) | ||
print(c.shape) |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pth |