dwSun commented on a change in pull request #9614: MobileNetV2
URL: https://github.com/apache/incubator-mxnet/pull/9614#discussion_r165874238
 
 

 ##########
 File path: python/mxnet/gluon/model_zoo/vision/mobilenet.py
 ##########
 @@ -147,57 +143,21 @@ def __init__(self, multiplier=1.0, classes=1000, 
**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))
+                _add_conv(self.features, int(32 * multiplier), kernel=3, 
stride=2, pad=1)
+
+                c_bgns = [int(x * multiplier) for x in [32] + [16] + [24] * 2
+                          + [32] * 3 + [64] * 4 + [96] * 3 + [160] * 3]
+                c_ends = [int(x * multiplier) for x in [16] + [24] * 2 + [32] 
* 3
+                          + [64] * 4 + [96] * 3 + [160] * 3 + [320]]
+                ts = [1] + [6] * 16
+                strides = [1, 2] * 2 + [1] * 2 + [2] + [1] * 3 + [1] * 3 + [2] 
+ [1] * 3
+
+                for c_bgn, c_end, t, s in zip(c_bgns, c_ends, ts, strides):
+                    self.features.add(BottleNeck(c_in=c_bgn, c_out=c_end, t=t, 
s=s))
 
 Review comment:
   I prefer compact code too. But shouldn't we keep our code simply and clear.
   Some people use the word 'scary' to describe code inside caffe and torch. 
Maybe it will be helpful to keep the code simple and stupid.
   This kind of code take twice the time to write and more time to understand. 
As a programmer,  I am a bit lazy. So, personally, I prefer previous version.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to