ó ùµÈ[c @s³dZddddddddd d d d g Zd ZdZddlZddlmZddlmZddl m Z ddlm Z dej fd„ƒYZ ddddde ed„Zed„Zdej fd„ƒYZde fd„ƒYZdej fd „ƒYZeeƒejje jƒd!ƒd"„Zeeƒejje jƒd!ƒd#„Zd$„Zd%„Zd&„Zd'„Zd(„Zd)„Zd*„Zd+„Z dS(,s0MobileNet and MobileNetV2, implemented in Gluon.t MobileNett MobileNetV2t mobilenet1_0tmobilenet_v2_1_0t mobilenet0_75tmobilenet_v2_0_75t mobilenet0_5tmobilenet_v2_0_5t mobilenet0_25tmobilenet_v2_0_25t get_mobilenettget_mobilenet_v2tdwSuns18/04/18iÿÿÿÿNi(tnni(tcpu(t HybridBlock(tbasetRELU6cBs eZdZd„Zd„ZRS(sRelu6 used in MobileNetV2.cKstt|ƒj|dS(N(tsuperRt__init__(tselftkwargs((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR(scCs|j|ddddƒS(Niitnametrelu6(tclip(RtFtx((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pythybrid_forward+s(t__name__t __module__t__doc__RR(((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR%s iic Csv|jtj||||d|dtƒƒ|jtjdtƒƒ|rr|j|r_tƒn tjdƒƒndS(Ntgroupstuse_biastscaletrelu(taddR tConv2DtFalset BatchNormtTrueRt Activation(touttchannelstkerneltstridetpadt num_grouptactiveR((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyt _add_conv0s+cCsHt|d|ddd|ddd|d|ƒt|d|d|ƒdS( NR*R+iR,R-iR.R(R0(R)t dw_channelsR*R,R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyt _add_conv_dw8stLinearBottleneckcBs eZdZd„Zd„ZRS(s·LinearBottleneck used in MobileNetV2 model from the `"Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation" `_ paper. Parameters ---------- in_channels : int Number of input channels. channels : int Number of output channels. t : int Layer expansion ratio. stride : int stride cKsÃtt|ƒj||dko+||k|_|jƒ€tjƒ|_t|j||dt ƒt|j||ddd|ddd||dt ƒt|j|dt dt ƒWdQXdS( NiRR+iR,R-R.R/( RR3Rt use_shortcutt name_scopeR tHybridSequentialR)R0R'R%(Rt in_channelsR*ttR,R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyRPs cCs1|j|ƒ}|jr-|j||ƒ}n|S(N(R)R4t elemwise_add(RRRR)((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR (RRRRR(((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR3>s cBs&eZdZddd„Zd„ZRS(s$MobileNet model from the `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" `_ paper. Parameters ---------- multiplier : float, default 1.0 The width multiplier for controling the model size. Only multipliers that are no less than 0.25 are supported. 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. gð?ièc KsÒtt|ƒj||jƒªtjddƒ|_|jjƒmt|jdtd|ƒddddd d ƒgdd gd gd d gd dgddgD]}t||ƒ^q¬}gd gd gd d gd dgddgd D]}t||ƒ^qþ}dd gddgdd dg}xBt |||ƒD].\}} } t |jd|d| d | ƒqRW|jj tj ƒƒ|jj tj ƒƒWdQXtj|ƒ|_WdQXdS(NtprefixtR*i R+iR-iR,ii@i€iiiiiR1(RRRR5R R6tfeaturesR0tinttzipR2R#tGlobalAvgPool2DtFlattentDensetoutput( Rt multipliertclassesRRR1R*tstridestdwctcts((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyRrs /NO%"#cCs"|j|ƒ}|j|ƒ}|S(N(R<RB(RRR((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR„s(RRRRR(((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyRcs cBs&eZdZddd„Zd„ZRS(sMobileNetV2 model from the `"Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation" `_ 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. gð?iècKs¡tt|ƒj||jƒytjddƒ|_|jjƒòt|jtd|ƒdddddd d t ƒgdgd gd gddgdd gddgddgdD]}t||ƒ^qÂ}gd gd gddgdd gddgddgddgD]}t||ƒ^q&}d gdgd }d dgdd d dgd gddgd gd}xTt ||||ƒD]=\} } } } |jj t d| d| d| d| ƒƒq¦W|dkrtd|ƒnd} t|j| d t ƒ|jj tj ƒƒWdQXtjddƒ|_|jjƒ6|jj tj|d dtddƒtjƒƒWdQXWdQXdS(NR:t features_i R+iR,iR-iRiii@ii`i i@iR7R*R8gð?itoutput_R tpred_(RRRR5R R6R<R0R=R'R>R#R3R?RBR$R%R@(RRCRDRRtin_channels_grouptchannels_groupttsREtin_cRGR8RHt last_channels((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR™s. aa:(" cCs"|j|ƒ}|j|ƒ}|S(N(R<RB(RRR((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR¸s(RRRRR(((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyRŠs tmodelscKswt||}|rsddlm}dj|ƒ}|d krM|d }n|j|d|d|ƒd |ƒn|S( sàMobileNet model from the `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" `_ paper. Parameters ---------- multiplier : float The width multiplier for controling the model size. Only multipliers that are no less than 0.25 are supported. The actual number of channels is equal to the original channel size multiplied by this multiplier. pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. root : str, default $MXNET_HOME/models Location for keeping the model parameters. i(tget_model_files{0:.2f}s1.00s0.50iÿÿÿÿs mobilenet%stroottctx(s1.00s0.50(Rt model_storeRRtformattload_parameters(RCt pretrainedRTRSRtnetRRtversion_suffix((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR ¿s   cKswt||}|rsddlm}dj|ƒ}|d krM|d }n|j|d|d|ƒd |ƒn|S( sÿMobileNetV2 model from the `"Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation" `_ paper. Parameters ---------- multiplier : float The width multiplier for controling the model size. Only multipliers that are no less than 0.25 are supported. The actual number of channels is equal to the original channel size multiplied by this multiplier. pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. root : str, default $MXNET_HOME/models Location for keeping the model parameters. i(RRs{0:.2f}s1.00s0.50iÿÿÿÿsmobilenetv2_%sRSRT(s1.00s0.50(RRURRRVRW(RCRXRTRSRRYRRRZ((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR Þs   cKs td|S(sœMobileNet model from the `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" `_ paper, with width multiplier 1.0. Parameters ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. gð?(R (R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyRþs cKs td|S(s MobileNetV2 model from the `"Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation" `_ paper. Parameters ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. gð?(R (R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR s cKs td|S(sMobileNet model from the `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" `_ paper, with width multiplier 0.75. Parameters ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. gè?(R (R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyRs cKs td|S(s MobileNetV2 model from the `"Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation" `_ paper. Parameters ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. gè?(R (R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR,s cKs td|S(sœMobileNet model from the `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" `_ paper, with width multiplier 0.5. Parameters ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. gà?(R (R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR<s cKs td|S(s MobileNetV2 model from the `"Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation" `_ paper. Parameters ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. gà?(R (R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyRKs cKs td|S(sMobileNet model from the `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" `_ paper, with width multiplier 0.25. Parameters ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. gÐ?(R (R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR[s cKs td|S(s MobileNetV2 model from the `"Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation" `_ paper. Parameters ---------- pretrained : bool, default False Whether to load the pretrained weights for model. ctx : Context, default CPU The context in which to load the pretrained weights. gÐ?(R (R((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyR js (!Rt__all__t __modify__t__modified_date__tosR;R tcontextRtblockRRRR'R%R0R2R3RRtpathtjointdata_dirR R RRRRRRRR (((sf/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/mobilenet.pyts:    %'5 ! !