σ šΔοYc@sBdZdddddgZddlmZdd lmZdd lmZd d lm Z m Z d „Z d„Z d„Z defd„ƒYZiddddddgfd6ddddddgfd6ddddddgfd6ddddddgfd6Zeeƒd„Zd„Zd „Zd!„Zd"„Zd#S($sDenseNet, implemented in Gluon.tDenseNett densenet121t densenet161t densenet169t densenet201i(tcpui(t HybridBlock(tnni(tHybridConcurrenttIdentityc Cs]tjdd|ƒ}|jƒ5x-t|ƒD]}|jt|||ƒƒq0WWdQX|S(Ntprefixsstage%d_(RtHybridSequentialt name_scopetrangetaddt_make_dense_layer(t num_layerstbn_sizet growth_ratetdropoutt stage_indextoutt_((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyt_make_dense_blocks  #c Cstjddƒ}|jtjƒƒ|jtjdƒƒ|jtj||dddtƒƒ|jtjƒƒ|jtjdƒƒ|jtj|dddddtƒƒ|rΡ|jtj|ƒƒntd dddƒ}|jt ƒƒ|j|ƒ|S( NR ttrelut kernel_sizeituse_biasitpaddingt concat_dim( RR Rt BatchNormt ActivationtConv2DtFalsetDropoutRR (RRRt new_featuresR((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyR$s&( cCs€tjddƒ}|jtjƒƒ|jtjdƒƒ|jtj|dddtƒƒ|jtjddd dƒƒ|S( NR RRRiRt pool_sizeitstrides(RR RRRR R!t AvgPool2D(tnum_output_featuresR((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyt_make_transition5s "cBs)eZdZdddd„Zd„ZRS(sκDensenet-BC model from the `"Densely Connected Convolutional Networks" `_ paper. Parameters ---------- num_init_features : int Number of filters to learn in the first convolution layer. growth_rate : int Number of filters to add each layer (`k` in the paper). block_config : list of int List of integers for numbers of layers in each pooling block. bn_size : int, default 4 Multiplicative factor for number of bottle neck layers. (i.e. bn_size * k features in the bottleneck layer) dropout : float, default 0 Rate of dropout after each dense layer. classes : int, default 1000 Number of classification classes. iiiθc KsΡtt|ƒj||jƒ©tjddƒ|_|jjtj|ddddddd t ƒƒ|jjtj ƒƒ|jjtj d ƒƒ|jjtj d ddddd ƒƒ|}x‹t |ƒD]}\} } |jjt| |||| d ƒƒ|| |}| t|ƒd krΣ|jjt|dƒƒ|d}qΣqΣW|jjtj ƒƒ|jjtj d ƒƒ|jjtjd dƒƒ|jjtjƒƒtj|ƒ|_WdQXdS( NR RRiR%iRiRRR$i(tsuperRt__init__R RR tfeaturesRR R!RRt MaxPool2Dt enumerateRtlenR(R&tFlattentDenset classifier( tselftnum_init_featuresRt block_configRRtclassestkwargst num_featurestiR((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyR*Rs( (&cCs"|j|ƒ}|j|ƒ}|S(N(R+R1(R2tFtx((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pythybrid_forwardls(t__name__t __module__t__doc__R*R;(((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyR>si@i ii iiiyi`i0i$i‘i©iΙc Ksbt|\}}}t||||}|r^ddlm}|j|d|ƒd|ƒn|S(sΔDensenet-BC model from the `"Densely Connected Convolutional Networks" `_ paper. Parameters ---------- num_layers : int Number of layers for the variant of densenet. Options are 121, 161, 169, 201. 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. i(tget_model_files densenet%dtctx(t densenet_specRt model_storeR?t load_params( Rt pretrainedR@R6R3RR4tnetR?((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyt get_densenetzs  cKs td|S(scDensenet-BC 121-layer model from the `"Densely Connected Convolutional Networks" `_ 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. iy(RF(R6((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyRŽs cKs td|S(scDensenet-BC 161-layer model from the `"Densely Connected Convolutional Networks" `_ 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. i‘(RF(R6((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyR›s cKs td|S(scDensenet-BC 169-layer model from the `"Densely Connected Convolutional Networks" `_ 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. i©(RF(R6((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyR¨s cKs td|S(scDensenet-BC 201-layer model from the `"Densely Connected Convolutional Networks" `_ 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. iΙ(RF(R6((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyR΅s N(R>t__all__tcontextRtblockRRRt custom_layersRR RRR(RRAR!RFRRRR(((sEbuild/bdist.linux-armv7l/egg/mxnet/gluon/model_zoo/vision/densenet.pyts$   5