ó ùµÈ[c@svdZdddddgZddlZdd lmZd d lmZd d lmZd d l m Z m Z ddlm Z d„Z d„Zd„Zdefd„ƒYZiddddddgfd6ddddddgfd6ddddddgfd6ddddddgfd6Zeeƒejje jƒd ƒd!„Zd"„Zd#„Zd$„Zd%„ZdS(&sDenseNet, implemented in Gluon.tDenseNett densenet121t densenet161t densenet169t densenet201iÿÿÿÿNi(tcpui(t HybridBlock(tnn(tHybridConcurrenttIdentity(tbasec 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_((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyt_make_dense_block s  #c Cstjddƒ}|jtjƒƒ|jtjdƒƒ|jtj||dddtƒƒ|jtjƒƒ|jtjdƒƒ|jtj|dddddtƒƒ|rÑ|jtj|ƒƒntd dddƒ}|jt ƒƒ|j|ƒ|S( NR ttrelut kernel_sizeituse_biasitpaddingtaxis( RR Rt BatchNormt ActivationtConv2DtFalsetDropoutRR (RRRt new_featuresR((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyR's&( cCs€tjddƒ}|jtjƒƒ|jtjdƒƒ|jtj|dddtƒƒ|jtjddd dƒƒ|S( NR RRRiRt pool_sizeitstrides(RR RRR R!R"t AvgPool2D(tnum_output_featuresR((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyt_make_transition8s "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"RR t MaxPool2Dt enumerateRtlenR)R'tFlattentDensetoutput( tselftnum_init_featuresRt block_configRRtclassestkwargst num_featurestiR((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyR+Us( (&cCs"|j|ƒ}|j|ƒ}|S(N(R,R2(R3tFtx((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pythybrid_forwardos(t__name__t __module__t__doc__R+R<(((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyRAsi@i ii iiiyi`i0i$i¡i©iÉtmodelsc Ksht|\}}}t||||}|rdddlm} |j| d|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. root : str, default $MXNET_HOME/models Location for keeping the model parameters. i(tget_model_files densenet%dtroottctx(t densenet_specRt model_storeRAtload_parameters( Rt pretrainedRCRBR7R4RR5tnetRA((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyt get_densenet}s &cKs td|S(sÃDensenet-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. root : str, default '$MXNET_HOME/models' Location for keeping the model parameters. iy(RI(R7((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyR”s cKs td|S(sÃDensenet-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. root : str, default '$MXNET_HOME/models' Location for keeping the model parameters. i¡(RI(R7((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyR£s cKs td|S(sÃDensenet-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. root : str, default '$MXNET_HOME/models' Location for keeping the model parameters. i©(RI(R7((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyR²s cKs td|S(sÃDensenet-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. root : str, default '$MXNET_HOME/models' Location for keeping the model parameters. iÉ(RI(R7((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyRÁs (R?t__all__tostcontextRtblockRRRt contrib.nnRR R RRR)RRDR"tpathtjointdata_dirRIRRRR(((se/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/densenet.pyts*    5 !