szha commented on a change in pull request #9614: MobileNetV2
URL: https://github.com/apache/incubator-mxnet/pull/9614#discussion_r165114975
##########
File path: python/mxnet/gluon/model_zoo/vision/mobilenet.py
##########
@@ -74,13 +126,102 @@ def hybrid_forward(self, F, x):
x = self.output(x)
return x
+
+class MobileNetV2(nn.HybridBlock):
+ r"""MobileNetV2 model from the
+ `"Inverted Residuals and Linear Bottlenecks:
+ Mobile Networks for Classification, Detection and Segmentation"
+ <https://arxiv.org/abs/1801.04381>`_ paper.
+
+ Parameters
+ ----------
+ multiplier : float, default 1.0
+ The width multiplier for controling the model size. The actual number
of channels
+ is equal to the original channel size multiplied by this multiplier.
+ classes : int, default 1000
+ Number of classes for the output layer.
+ """
+
+ def __init__(self, multiplier=1.0, classes=1000, **kwargs):
+ super(MobileNetV2, self).__init__(**kwargs)
+ with self.name_scope():
+ self.features = nn.HybridSequential(prefix='features_')
+ with self.features.name_scope():
+ self.features.add(
+ nn.Conv2D(int(32 * multiplier), 3, strides=2, padding=1,
use_bias=False),
+ nn.BatchNorm(scale=True),
+ nn.Activation('relu')
+ )
+
+ c_bgn = int(32 * multiplier)
+ c_end = int(16 * multiplier)
+ self.features.add(BottleNeck(c_in=c_bgn, c_out=c_end, t=1,
s=1))
+
+ c_bgn = int(16 * multiplier)
+ c_end = int(24 * multiplier)
+ self.features.add(BottleNeck(c_in=c_bgn, c_out=c_end, t=6,
s=2))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+
+ c_bgn = int(24 * multiplier)
+ c_end = int(32 * multiplier)
+ self.features.add(BottleNeck(c_in=c_bgn, c_out=c_end, t=6,
s=2))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+
+ c_bgn = int(32 * multiplier)
+ c_end = int(64 * multiplier)
+ self.features.add(BottleNeck(c_in=c_bgn, c_out=c_end, t=6,
s=2))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+
+ c_bgn = int(64 * multiplier)
+ c_end = int(96 * multiplier)
+ self.features.add(BottleNeck(c_in=c_bgn, c_out=c_end, t=6,
s=1))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+
+ c_bgn = int(96 * multiplier)
+ c_end = int(160 * multiplier)
+ self.features.add(BottleNeck(c_in=c_bgn, c_out=c_end, t=6,
s=2))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+ self.features.add(BottleNeck(c_in=c_end, c_out=c_end, t=6,
s=1))
+
+ c_bgn = int(160 * multiplier)
+ c_end = int(320 * multiplier)
+ self.features.add(BottleNeck(c_in=c_bgn, c_out=c_end, t=6,
s=1))
Review comment:
the construction looks like it could be refactored. can you use similar
implementation from mobilenet v1?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services