Commit efc0106a by Ting PAN

Fix the incorrect git revision path

1 parent 4dd97da7
......@@ -16,10 +16,12 @@ from __future__ import print_function
import collections
import functools
import math
from seetadet.core import registry
from seetadet.modeling.mobilenet_v3 import conv_triplet
from seetadet.modeling.mobilenet_v3 import conv_quintet
from seetadet.modeling.mobilenet_v3 import make_divisible
from seetadet.modules import init
from seetadet.modules import nn
......@@ -87,13 +89,26 @@ class InvertedResidual(nn.Module):
class NASMobileNet(nn.Module):
"""NAS variant of mobilenet class."""
def __init__(self, arch, preset):
def __init__(self, arch, preset, width_mult=1.0, depth_mult=1.0):
super(NASMobileNet, self).__init__()
# Hand-craft configurations.
repeats, strides, out_channels, def_blocks = preset
assert sum(repeats) == len(arch), 'Bad architecture.'
self.feature_dims = collections.OrderedDict()
# Apply the width scaling.
out_channels = list(map(lambda x: make_divisible(x * width_mult),
out_channels))
# Apply the depth scaling.
repeated_arch = []
for i, repeat in enumerate(repeats):
idx_start = sum(repeats[:i])
indices = arch[idx_start: idx_start + repeat]
repeat = int(math.ceil(repeat * depth_mult))
repeated_arch += (indices + [indices[-1]] * (repeat - len(indices)))
arch = repeated_arch
# Stem.
features = [nn.Sequential(
*conv_triplet(
......@@ -108,6 +123,7 @@ class NASMobileNet(nn.Module):
dim_in, stride_out = out_channels[0], 2
for repeat, dim_out, stride in \
zip(repeats, out_channels[1:], strides):
repeat = int(math.ceil(repeat * depth_mult))
stride_out *= stride
for i in range(repeat):
stride = stride if i == 0 else 1
......@@ -169,12 +185,49 @@ class ModelSetting(object):
)
@registry.backbone.register('efficient_b0')
def efficient_b0():
def efficientnet(width_mult=1.0, depth_mult=1.0):
return NASMobileNet([10301,
60301, 60301,
60501, 60501,
60301, 60301, 60301,
60501, 60501, 60501,
60501, 60501, 60501, 60501,
60301], ModelSetting.EFFICIENT)
60301],
preset=ModelSetting.EFFICIENT,
width_mult=width_mult,
depth_mult=depth_mult)
@registry.backbone.register('efficientnet_b0')
def efficientnet_b0():
return efficientnet(width_mult=1.0, depth_mult=1.0)
@registry.backbone.register('efficientnet_b1')
def efficientnet_b1():
return efficientnet(width_mult=1.0, depth_mult=1.1)
@registry.backbone.register('efficientnet_b2')
def efficientnet_b2():
return efficientnet(width_mult=1.1, depth_mult=1.2)
@registry.backbone.register('efficientnet_b3')
def efficientnet_b3():
return efficientnet(width_mult=1.2, depth_mult=1.4)
@registry.backbone.register('efficientnet_b4')
def efficientnet_b4():
return efficientnet(width_mult=1.4, depth_mult=1.8)
@registry.backbone.register('efficientnet_b5')
def efficientnet_b5():
return efficientnet(width_mult=1.6, depth_mult=2.2)
@registry.backbone.register('efficientnet_b6')
def efficientnet_b6():
return efficientnet(width_mult=1.8, depth_mult=2.6)
......@@ -23,6 +23,15 @@ from seetadet.modules import init
from seetadet.modules import nn
def make_divisible(v, divisor=8):
"""Return the divisible value."""
min_value = divisor
new_v = max(min_value, int(v + divisor / 2) // divisor * divisor)
if new_v < 0.9 * v:
new_v += divisor
return new_v
def conv_triplet(dim_in, dim_out, kernel_size=1, stride=1):
"""Return a convolution triplet."""
return [nn.Conv2d(dim_in, dim_out,
......@@ -78,13 +87,17 @@ class InvertedResidual(nn.Module):
class NASMobileNet(nn.Module):
"""NAS variant of mobilenet class."""
def __init__(self, arch, preset):
def __init__(self, arch, preset, width_mult=1.0):
super(NASMobileNet, self).__init__()
# Hand-craft configurations
repeats, strides, out_channels, def_blocks = preset
assert sum(repeats) == len(arch), 'Bad architecture.'
self.feature_dims = collections.OrderedDict()
# Apply the width scaling.
out_channels = list(map(lambda x: make_divisible(x * width_mult),
out_channels))
# Stem.
features = [nn.Sequential(
*conv_triplet(
......
......@@ -73,7 +73,6 @@ class SqueezeExcite(nn.Module):
def __init__(self, dim_in, squeeze_ratio=0.25):
super(SqueezeExcite, self).__init__()
dim = make_divisible(dim_in * squeeze_ratio)
print(dim)
self.layers = nn.Sequential(nn.AvgPool2d(-1, global_pooling=True),
nn.Conv2d(dim_in, dim, kernel_size=1),
nn.ReLU(True),
......@@ -129,15 +128,19 @@ class InvertedResidual(nn.Module):
class NASMobileNet(nn.Module):
"""The NAS variant of mobilenet class."""
"""NAS variant of mobilenet class."""
def __init__(self, arch, preset):
def __init__(self, arch, preset, width_mult=1.0):
super(NASMobileNet, self).__init__()
# Hand-craft configurations.
repeats, strides, out_channels, def_blocks = preset
assert sum(repeats) == len(arch), 'Bad architecture.'
self.feature_dims = collections.OrderedDict()
# Apply the width scaling.
out_channels = list(map(lambda x: make_divisible(x * width_mult),
out_channels))
# Stem.
features = [nn.Sequential(
*conv_triplet(
......
......@@ -26,7 +26,7 @@ with open('version.txt', 'r') as f:
version = f.read().strip()
try:
git_version = subprocess.check_output(
['git', 'rev-parse', 'HEAD'], cwd='../').decode('ascii').strip()
['git', 'rev-parse', 'HEAD'], cwd='./').decode('ascii').strip()
except (OSError, subprocess.CalledProcessError):
git_version = None
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!