ó ùµÈ[c@ sÁdZddlmZddddddd d d d d ddddddgZddlZddlmZddlmZddl m Z ddl m Z d„Z defd„ƒYZ defd„ƒYZdefd„ƒYZdefd„ƒYZdefd „ƒYZdefd!„ƒYZid"d#d#d#d#gd$d$d%d&d'gfd(6d"ddd)dgd$d$d%d&d'gfd*6d+ddd)dgd$d&d'd,d-gfd.6d+ddd/dgd$d&d'd,d-gfd06d+dd1d2dgd$d&d'd,d-gfd36ZeegZie d"6ed+6ied"6ed+6gZeeƒejje jƒd4ƒd5„Zd6„Zd7„Zd8„Zd9„Zd:„Zd;„Z d<„Z!d=„Z"d>„Z#d?„Z$dS(@sResNets, implemented in Gluon.iÿÿÿÿ(tdivisiontResNetV1tResNetV2t BasicBlockV1t BasicBlockV2t BottleneckV1t BottleneckV2t resnet18_v1t resnet34_v1t resnet50_v1t resnet101_v1t resnet152_v1t resnet18_v2t resnet34_v2t resnet50_v2t resnet101_v2t resnet152_v2t get_resnetNi(tcpui(t HybridBlock(tnn(tbasec C s+tj|ddd|dddtd|ƒS(Nt kernel_sizeitstridestpaddingituse_biast in_channels(RtConv2DtFalse(tchannelststrideR((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyt_conv3x3&scB s&eZdZedd„Zd„ZRS(sÛBasicBlock V1 from `"Deep Residual Learning for Image Recognition" `_ paper. This is used for ResNet V1 for 18, 34 layers. Parameters ---------- channels : int Number of output channels. stride : int Stride size. downsample : bool, default False Whether to downsample the input. in_channels : int, default 0 Number of input channels. Default is 0, to infer from the graph. ic K stt|ƒj|tjddƒ|_|jjt|||ƒƒ|jjtjƒƒ|jjtj dƒƒ|jjt|d|ƒƒ|jjtjƒƒ|r tjddƒ|_ |j jtj |ddd|dt d|ƒƒ|j jtjƒƒn d|_ dS( NtprefixttreluiRRRR(tsuperRt__init__RtHybridSequentialtbodytaddRt BatchNormt Activationt downsampleRRtNone(tselfRRR*Rtkwargs((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR$<s!cC sM|}|j|ƒ}|jr0|j|ƒ}n|j||ddƒ}|S(Ntact_typeR"(R&R*R)(R,tFtxtresidual((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pythybrid_forwardLs  (t__name__t __module__t__doc__RR$R2(((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR,scB s&eZdZedd„Zd„ZRS(sáBottleneck V1 from `"Deep Residual Learning for Image Recognition" `_ paper. This is used for ResNet V1 for 50, 101, 152 layers. Parameters ---------- channels : int Number of output channels. stride : int Stride size. downsample : bool, default False Whether to downsample the input. in_channels : int, default 0 Number of input channels. Default is 0, to infer from the graph. ic K sƒtt|ƒj|tjddƒ|_|jjtj|dddd|ƒƒ|jjtjƒƒ|jjtj dƒƒ|jjt |dd|dƒƒ|jjtjƒƒ|jjtj dƒƒ|jjtj|ddddƒƒ|jjtjƒƒ|rvtjddƒ|_ |j jtj|ddd|dt d |ƒƒ|j jtjƒƒn d|_ dS( NR R!iRiRR"RR(R#RR$RR%R&R'RR(R)RR*RR+(R,RRR*RR-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR$is )$%!cC sM|}|j|ƒ}|jr0|j|ƒ}n|j||ddƒ}|S(NR.R"(R&R*R)(R,R/R0R1((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR2|s  (R3R4R5RR$R2(((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRYscB s&eZdZedd„Zd„ZRS(sßBasicBlock V2 from `"Identity Mappings in Deep Residual Networks" `_ paper. This is used for ResNet V2 for 18, 34 layers. Parameters ---------- channels : int Number of output channels. stride : int Stride size. downsample : bool, default False Whether to downsample the input. in_channels : int, default 0 Number of input channels. Default is 0, to infer from the graph. icK s˜tt|ƒj|tjƒ|_t|||ƒ|_tjƒ|_t|d|ƒ|_ |r‹tj |d|dt d|ƒ|_ n d|_ dS(NiRR(R#RR$RR(tbn1Rtconv1tbn2tconv2RRR*R+(R,RRR*RR-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR$™scC s|}|j|ƒ}|j|ddƒ}|jrE|j|ƒ}n|j|ƒ}|j|ƒ}|j|ddƒ}|j|ƒ}||S(NR.R"(R6R)R*R7R8R9(R,R/R0R1((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR2¥s (R3R4R5RR$R2(((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRˆs cB s&eZdZedd„Zd„ZRS(såBottleneck V2 from `"Identity Mappings in Deep Residual Networks" `_ paper. This is used for ResNet V2 for 50, 101, 152 layers. Parameters ---------- channels : int Number of output channels. stride : int Stride size. downsample : bool, default False Whether to downsample the input. in_channels : int, default 0 Number of input channels. Default is 0, to infer from the graph. icK sætt|ƒj|tjƒ|_tj|ddddddtƒ|_tjƒ|_ t |d||dƒ|_ tjƒ|_ tj|dddddtƒ|_ |rÙtj|d|dtd|ƒ|_n d|_dS(NiRiRRR(R#RR$RR(R6RRR7R8RR9tbn3tconv3R*R+(R,RRR*RR-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR$Ås($cC sÂ|}|j|ƒ}|j|ddƒ}|jrE|j|ƒ}n|j|ƒ}|j|ƒ}|j|ddƒ}|j|ƒ}|j|ƒ}|j|ddƒ}|j|ƒ}||S(NR.R"(R6R)R*R7R8R9R:R;(R,R/R0R1((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR2Ós (R3R4R5RR$R2(((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR´scB s2eZdZded„Zdd„Zd„ZRS(s>ResNet V1 model from `"Deep Residual Learning for Image Recognition" `_ paper. Parameters ---------- block : HybridBlock Class for the residual block. Options are BasicBlockV1, BottleneckV1. layers : list of int Numbers of layers in each block channels : list of int Numbers of channels in each block. Length should be one larger than layers list. classes : int, default 1000 Number of classification classes. thumbnail : bool, default False Enable thumbnail. ièc K s©tt|ƒj|t|ƒt|ƒdks8t‚|jƒ_tjddƒ|_|rƒ|jj t |dddƒƒnz|jj tj |dddddt ƒƒ|jj tj ƒƒ|jj tjd ƒƒ|jj tjdddƒƒxmt|ƒD]_\}}|dkr(dnd} |jj |j||||d| |dd ||ƒƒq W|jj tjƒƒtj|d |d ƒ|_WdQXdS( NiR R!iiiiRR"Rtin_unitsiÿÿÿÿ(R#RR$tlentAssertionErrort name_scopeRR%tfeaturesR'RRRR(R)t MaxPool2Dt enumeratet _make_layertGlobalAvgPool2DtDensetoutput( R,tblocktlayersRtclassest thumbnailR-tit num_layerR((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR$ùs " #, ic C s˜tjdd|ƒ}|jƒp|j|||||kd|ddƒƒx=t|dƒD]+}|j||dtd|ddƒƒq_WWdQX|S(NR sstage%d_RR!i(RR%R?R'trangeR( R,RGRHRRt stage_indexRtlayert_((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRCs ! /cC s"|j|ƒ}|j|ƒ}|S(N(R@RF(R,R/R0((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR2s(R3R4R5RR$RCR2(((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRçs cB s2eZdZded„Zdd„Zd„ZRS(s>ResNet V2 model from `"Identity Mappings in Deep Residual Networks" `_ paper. Parameters ---------- block : HybridBlock Class for the residual block. Options are BasicBlockV1, BottleneckV1. layers : list of int Numbers of layers in each block channels : list of int Numbers of channels in each block. Length should be one larger than layers list. classes : int, default 1000 Number of classification classes. thumbnail : bool, default False Enable thumbnail. ièc K s tt|ƒj|t|ƒt|ƒdks8t‚|jƒÖtjddƒ|_|jj tj dt dt ƒƒ|r¥|jj t |dddƒƒnz|jj tj |dddd d t ƒƒ|jj tj ƒƒ|jj tjd ƒƒ|jj tjd ddƒƒ|d}xwt|ƒD]i\}} |dkrTdnd} |jj |j|| ||d| |dd |ƒƒ||d}q6W|jj tj ƒƒ|jj tjd ƒƒ|jj tjƒƒ|jj tjƒƒtj|d |ƒ|_WdQXdS(NiR R!tscaletcenteriiiiRR"RR<(R#RR$R=R>R?RR%R@R'R(RRRR)RARBRCRDtFlattenRERF( R,RGRHRRIRJR-RRKRLR((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR$0s," "#,  ic C s˜tjdd|ƒ}|jƒp|j|||||kd|ddƒƒx=t|dƒD]+}|j||dtd|ddƒƒq_WWdQX|S(NR sstage%d_RR!i(RR%R?R'RMR( R,RGRHRRRNRRORP((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRCKs ! /cC s"|j|ƒ}|j|ƒ}|S(N(R@RF(R,R/R0((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR2Ts(R3R4R5RR$RCR2(((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRs t basic_blockii@i€iiiii"t bottle_neckiii2iieii$i˜tmodelsc K sä|tks.td|ttjƒƒfƒ‚t|\}}}|dkrY|dksitd|ƒ‚t|d} t|d|} | | |||} |ràddlm} | j| d||fd|ƒd|ƒn| S( s¹ResNet V1 model from `"Deep Residual Learning for Image Recognition" `_ paper. ResNet V2 model from `"Identity Mappings in Deep Residual Networks" `_ paper. Parameters ---------- version : int Version of ResNet. Options are 1, 2. num_layers : int Numbers of layers. Options are 18, 34, 50, 101, 152. 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. s,Invalid number of layers: %d. Options are %siis0Invalid resnet version: %d. Options are 1 and 2.(tget_model_files resnet%d_v%dtroottctx( t resnet_specR>tstrtkeystresnet_net_versionstresnet_block_versionst model_storeRWtload_parameters( tversiont num_layerst pretrainedRYRXR-t block_typeRHRt resnet_classt block_classtnetRW((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRgs cK stdd|S(sµResNet-18 V1 model from `"Deep Residual Learning for Image Recognition" `_ 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. ii(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRŠs cK stdd|S(sµResNet-34 V1 model from `"Deep Residual Learning for Image Recognition" `_ 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. ii"(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR™s cK stdd|S(sµResNet-50 V1 model from `"Deep Residual Learning for Image Recognition" `_ 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. ii2(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR ¨s cK stdd|S(s¶ResNet-101 V1 model from `"Deep Residual Learning for Image Recognition" `_ 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. iie(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR ·s cK stdd|S(s¶ResNet-152 V1 model from `"Deep Residual Learning for Image Recognition" `_ 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. ii˜(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR Æs cK stdd|S(sµResNet-18 V2 model from `"Identity Mappings in Deep Residual 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. ii(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR Õs cK stdd|S(sµResNet-34 V2 model from `"Identity Mappings in Deep Residual 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. ii"(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyR äs cK stdd|S(sµResNet-50 V2 model from `"Identity Mappings in Deep Residual 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. ii2(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRós cK stdd|S(s¶ResNet-101 V2 model from `"Identity Mappings in Deep Residual 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. iie(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRs cK stdd|S(s¶ResNet-152 V2 model from `"Identity Mappings in Deep Residual 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. ii˜(R(R-((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pyRs (%R5t __future__Rt__all__tostcontextRRGRR!RRRRRRRRRRZR]R^Rtpathtjointdata_dirRRRR R R R R RRR(((sc/usr/local/lib/python2.7/site-packages/mxnet-1.3.1-py2.7.egg/mxnet/gluon/model_zoo/vision/resnet.pytsN   -/,37=.+++.  !"