Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SeetaResearch
/
SeetaDet
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit efc0106a
authored
Nov 02, 2020
by
Ting PAN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the incorrect git revision path
1 parent
4dd97da7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
9 deletions
seetadet/modeling/efficientnet.py
seetadet/modeling/mobilenet_v2.py
seetadet/modeling/mobilenet_v3.py
setup.py
seetadet/modeling/efficientnet.py
View file @
efc0106
...
@@ -16,10 +16,12 @@ from __future__ import print_function
...
@@ -16,10 +16,12 @@ from __future__ import print_function
import
collections
import
collections
import
functools
import
functools
import
math
from
seetadet.core
import
registry
from
seetadet.core
import
registry
from
seetadet.modeling.mobilenet_v3
import
conv_triplet
from
seetadet.modeling.mobilenet_v3
import
conv_triplet
from
seetadet.modeling.mobilenet_v3
import
conv_quintet
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
init
from
seetadet.modules
import
nn
from
seetadet.modules
import
nn
...
@@ -87,13 +89,26 @@ class InvertedResidual(nn.Module):
...
@@ -87,13 +89,26 @@ class InvertedResidual(nn.Module):
class
NASMobileNet
(
nn
.
Module
):
class
NASMobileNet
(
nn
.
Module
):
"""NAS variant of mobilenet class."""
"""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__
()
super
(
NASMobileNet
,
self
)
.
__init__
()
# Hand-craft configurations.
# Hand-craft configurations.
repeats
,
strides
,
out_channels
,
def_blocks
=
preset
repeats
,
strides
,
out_channels
,
def_blocks
=
preset
assert
sum
(
repeats
)
==
len
(
arch
),
'Bad architecture.'
assert
sum
(
repeats
)
==
len
(
arch
),
'Bad architecture.'
self
.
feature_dims
=
collections
.
OrderedDict
()
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.
# Stem.
features
=
[
nn
.
Sequential
(
features
=
[
nn
.
Sequential
(
*
conv_triplet
(
*
conv_triplet
(
...
@@ -108,6 +123,7 @@ class NASMobileNet(nn.Module):
...
@@ -108,6 +123,7 @@ class NASMobileNet(nn.Module):
dim_in
,
stride_out
=
out_channels
[
0
],
2
dim_in
,
stride_out
=
out_channels
[
0
],
2
for
repeat
,
dim_out
,
stride
in
\
for
repeat
,
dim_out
,
stride
in
\
zip
(
repeats
,
out_channels
[
1
:],
strides
):
zip
(
repeats
,
out_channels
[
1
:],
strides
):
repeat
=
int
(
math
.
ceil
(
repeat
*
depth_mult
))
stride_out
*=
stride
stride_out
*=
stride
for
i
in
range
(
repeat
):
for
i
in
range
(
repeat
):
stride
=
stride
if
i
==
0
else
1
stride
=
stride
if
i
==
0
else
1
...
@@ -169,12 +185,49 @@ class ModelSetting(object):
...
@@ -169,12 +185,49 @@ class ModelSetting(object):
)
)
@registry.backbone.register
(
'efficient_b0'
)
def
efficientnet
(
width_mult
=
1.0
,
depth_mult
=
1.0
):
def
efficient_b0
():
return
NASMobileNet
([
10301
,
return
NASMobileNet
([
10301
,
60301
,
60301
,
60301
,
60301
,
60501
,
60501
,
60501
,
60501
,
60301
,
60301
,
60301
,
60301
,
60301
,
60301
,
60501
,
60501
,
60501
,
60501
,
60501
,
60501
,
60501
,
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
)
seetadet/modeling/mobilenet_v2.py
View file @
efc0106
...
@@ -23,6 +23,15 @@ from seetadet.modules import init
...
@@ -23,6 +23,15 @@ from seetadet.modules import init
from
seetadet.modules
import
nn
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
):
def
conv_triplet
(
dim_in
,
dim_out
,
kernel_size
=
1
,
stride
=
1
):
"""Return a convolution triplet."""
"""Return a convolution triplet."""
return
[
nn
.
Conv2d
(
dim_in
,
dim_out
,
return
[
nn
.
Conv2d
(
dim_in
,
dim_out
,
...
@@ -78,13 +87,17 @@ class InvertedResidual(nn.Module):
...
@@ -78,13 +87,17 @@ class InvertedResidual(nn.Module):
class
NASMobileNet
(
nn
.
Module
):
class
NASMobileNet
(
nn
.
Module
):
"""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__
()
super
(
NASMobileNet
,
self
)
.
__init__
()
# Hand-craft configurations
# Hand-craft configurations
repeats
,
strides
,
out_channels
,
def_blocks
=
preset
repeats
,
strides
,
out_channels
,
def_blocks
=
preset
assert
sum
(
repeats
)
==
len
(
arch
),
'Bad architecture.'
assert
sum
(
repeats
)
==
len
(
arch
),
'Bad architecture.'
self
.
feature_dims
=
collections
.
OrderedDict
()
self
.
feature_dims
=
collections
.
OrderedDict
()
# Apply the width scaling.
out_channels
=
list
(
map
(
lambda
x
:
make_divisible
(
x
*
width_mult
),
out_channels
))
# Stem.
# Stem.
features
=
[
nn
.
Sequential
(
features
=
[
nn
.
Sequential
(
*
conv_triplet
(
*
conv_triplet
(
...
...
seetadet/modeling/mobilenet_v3.py
View file @
efc0106
...
@@ -73,7 +73,6 @@ class SqueezeExcite(nn.Module):
...
@@ -73,7 +73,6 @@ class SqueezeExcite(nn.Module):
def
__init__
(
self
,
dim_in
,
squeeze_ratio
=
0.25
):
def
__init__
(
self
,
dim_in
,
squeeze_ratio
=
0.25
):
super
(
SqueezeExcite
,
self
)
.
__init__
()
super
(
SqueezeExcite
,
self
)
.
__init__
()
dim
=
make_divisible
(
dim_in
*
squeeze_ratio
)
dim
=
make_divisible
(
dim_in
*
squeeze_ratio
)
print
(
dim
)
self
.
layers
=
nn
.
Sequential
(
nn
.
AvgPool2d
(
-
1
,
global_pooling
=
True
),
self
.
layers
=
nn
.
Sequential
(
nn
.
AvgPool2d
(
-
1
,
global_pooling
=
True
),
nn
.
Conv2d
(
dim_in
,
dim
,
kernel_size
=
1
),
nn
.
Conv2d
(
dim_in
,
dim
,
kernel_size
=
1
),
nn
.
ReLU
(
True
),
nn
.
ReLU
(
True
),
...
@@ -129,15 +128,19 @@ class InvertedResidual(nn.Module):
...
@@ -129,15 +128,19 @@ class InvertedResidual(nn.Module):
class
NASMobileNet
(
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__
()
super
(
NASMobileNet
,
self
)
.
__init__
()
# Hand-craft configurations.
# Hand-craft configurations.
repeats
,
strides
,
out_channels
,
def_blocks
=
preset
repeats
,
strides
,
out_channels
,
def_blocks
=
preset
assert
sum
(
repeats
)
==
len
(
arch
),
'Bad architecture.'
assert
sum
(
repeats
)
==
len
(
arch
),
'Bad architecture.'
self
.
feature_dims
=
collections
.
OrderedDict
()
self
.
feature_dims
=
collections
.
OrderedDict
()
# Apply the width scaling.
out_channels
=
list
(
map
(
lambda
x
:
make_divisible
(
x
*
width_mult
),
out_channels
))
# Stem.
# Stem.
features
=
[
nn
.
Sequential
(
features
=
[
nn
.
Sequential
(
*
conv_triplet
(
*
conv_triplet
(
...
...
setup.py
View file @
efc0106
...
@@ -26,7 +26,7 @@ with open('version.txt', 'r') as f:
...
@@ -26,7 +26,7 @@ with open('version.txt', 'r') as f:
version
=
f
.
read
()
.
strip
()
version
=
f
.
read
()
.
strip
()
try
:
try
:
git_version
=
subprocess
.
check_output
(
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
):
except
(
OSError
,
subprocess
.
CalledProcessError
):
git_version
=
None
git_version
=
None
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment