resnet.py 17.9 KB
Newer Older
C
cuicheng01 已提交
1
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
C
cuicheng01 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

C
cuicheng01 已提交
15
from __future__ import absolute_import, division, print_function
C
cuicheng01 已提交
16 17 18 19 20 21 22 23 24 25

import numpy as np
import paddle
from paddle import ParamAttr
import paddle.nn as nn
from paddle.nn import Conv2D, BatchNorm, Linear
from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
from paddle.nn.initializer import Uniform
import math

C
cuicheng01 已提交
26
from ppcls.arch.backbone.base.theseus_layer import TheseusLayer
D
dongshuilong 已提交
27
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
C
cuicheng01 已提交
28 29

MODEL_URLS = {
D
dongshuilong 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    "ResNet18":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet18_pretrained.pdparams",
    "ResNet18_vd":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet18_vd_pretrained.pdparams",
    "ResNet34":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet34_pretrained.pdparams",
    "ResNet34_vd":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet34_vd_pretrained.pdparams",
    "ResNet50":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet50_pretrained.pdparams",
    "ResNet50_vd":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet50_vd_pretrained.pdparams",
    "ResNet101":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet101_pretrained.pdparams",
    "ResNet101_vd":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet101_vd_pretrained.pdparams",
    "ResNet152":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet152_pretrained.pdparams",
    "ResNet152_vd":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet152_vd_pretrained.pdparams",
    "ResNet200_vd":
    "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/ResNet200_vd_pretrained.pdparams",
C
cuicheng01 已提交
52
}
C
cuicheng01 已提交
53

C
cuicheng01 已提交
54 55 56 57 58 59 60 61 62 63
__all__ = MODEL_URLS.keys()
'''
ResNet config: dict.
    key: depth of ResNet.
    values: config's dict of specific model.
        keys:
            block_type: Two different blocks in ResNet, BasicBlock and BottleneckBlock are optional.
            block_depth: The number of blocks in different stages in ResNet.
            num_channels: The number of channels to enter the next stage.
'''
C
cuicheng01 已提交
64 65
NET_CONFIG = {
    "18": {
D
dongshuilong 已提交
66 67 68 69
        "block_type": "BasicBlock",
        "block_depth": [2, 2, 2, 2],
        "num_channels": [64, 64, 128, 256]
    },
C
cuicheng01 已提交
70
    "34": {
D
dongshuilong 已提交
71 72 73 74
        "block_type": "BasicBlock",
        "block_depth": [3, 4, 6, 3],
        "num_channels": [64, 64, 128, 256]
    },
C
cuicheng01 已提交
75
    "50": {
D
dongshuilong 已提交
76 77 78 79
        "block_type": "BottleneckBlock",
        "block_depth": [3, 4, 6, 3],
        "num_channels": [64, 256, 512, 1024]
    },
C
cuicheng01 已提交
80
    "101": {
D
dongshuilong 已提交
81 82 83 84
        "block_type": "BottleneckBlock",
        "block_depth": [3, 4, 23, 3],
        "num_channels": [64, 256, 512, 1024]
    },
C
cuicheng01 已提交
85
    "152": {
D
dongshuilong 已提交
86 87 88 89
        "block_type": "BottleneckBlock",
        "block_depth": [3, 8, 36, 3],
        "num_channels": [64, 256, 512, 1024]
    },
C
cuicheng01 已提交
90
    "200": {
D
dongshuilong 已提交
91 92 93 94
        "block_type": "BottleneckBlock",
        "block_depth": [3, 12, 48, 3],
        "num_channels": [64, 256, 512, 1024]
    },
C
cuicheng01 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107
}


class ConvBNLayer(TheseusLayer):
    def __init__(self,
                 num_channels,
                 num_filters,
                 filter_size,
                 stride=1,
                 groups=1,
                 is_vd_mode=False,
                 act=None,
                 lr_mult=1.0):
C
cuicheng01 已提交
108
        super().__init__()
C
cuicheng01 已提交
109 110
        self.is_vd_mode = is_vd_mode
        self.act = act
C
cuicheng01 已提交
111
        self.avg_pool = AvgPool2D(
C
cuicheng01 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
            kernel_size=2, stride=2, padding=0, ceil_mode=True)
        self.conv = Conv2D(
            in_channels=num_channels,
            out_channels=num_filters,
            kernel_size=filter_size,
            stride=stride,
            padding=(filter_size - 1) // 2,
            groups=groups,
            weight_attr=ParamAttr(learning_rate=lr_mult),
            bias_attr=False)
        self.bn = BatchNorm(
            num_filters,
            param_attr=ParamAttr(learning_rate=lr_mult),
            bias_attr=ParamAttr(learning_rate=lr_mult))
        self.relu = nn.ReLU()

    def forward(self, x):
        if self.is_vd_mode:
C
cuicheng01 已提交
130
            x = self.avg_pool(x)
C
cuicheng01 已提交
131 132 133 134 135 136 137 138
        x = self.conv(x)
        x = self.bn(x)
        if self.act:
            x = self.relu(x)
        return x


class BottleneckBlock(TheseusLayer):
D
dongshuilong 已提交
139 140 141 142 143 144 145 146
    def __init__(
            self,
            num_channels,
            num_filters,
            stride,
            shortcut=True,
            if_first=False,
            lr_mult=1.0, ):
C
cuicheng01 已提交
147
        super().__init__()
C
cuicheng01 已提交
148 149 150 151 152

        self.conv0 = ConvBNLayer(
            num_channels=num_channels,
            num_filters=num_filters,
            filter_size=1,
C
cuicheng01 已提交
153
            act="relu",
C
cuicheng01 已提交
154 155 156 157 158 159
            lr_mult=lr_mult)
        self.conv1 = ConvBNLayer(
            num_channels=num_filters,
            num_filters=num_filters,
            filter_size=3,
            stride=stride,
C
cuicheng01 已提交
160
            act="relu",
C
cuicheng01 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
            lr_mult=lr_mult)
        self.conv2 = ConvBNLayer(
            num_channels=num_filters,
            num_filters=num_filters * 4,
            filter_size=1,
            act=None,
            lr_mult=lr_mult)

        if not shortcut:
            self.short = ConvBNLayer(
                num_channels=num_channels,
                num_filters=num_filters * 4,
                filter_size=1,
                stride=stride if if_first else 1,
                is_vd_mode=False if if_first else True,
                lr_mult=lr_mult)
        self.relu = nn.ReLU()
        self.shortcut = shortcut

    def forward(self, x):
        identity = x
        x = self.conv0(x)
        x = self.conv1(x)
        x = self.conv2(x)

        if self.shortcut:
            short = identity
        else:
            short = self.short(identity)
        x = paddle.add(x=x, y=short)
        x = self.relu(x)
        return x


class BasicBlock(TheseusLayer):
    def __init__(self,
                 num_channels,
                 num_filters,
                 stride,
                 shortcut=True,
                 if_first=False,
                 lr_mult=1.0):
C
cuicheng01 已提交
203 204
        super().__init__()

C
cuicheng01 已提交
205 206 207 208 209 210
        self.stride = stride
        self.conv0 = ConvBNLayer(
            num_channels=num_channels,
            num_filters=num_filters,
            filter_size=3,
            stride=stride,
C
cuicheng01 已提交
211
            act="relu",
C
cuicheng01 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
            lr_mult=lr_mult)
        self.conv1 = ConvBNLayer(
            num_channels=num_filters,
            num_filters=num_filters,
            filter_size=3,
            act=None,
            lr_mult=lr_mult)
        if not shortcut:
            self.short = ConvBNLayer(
                num_channels=num_channels,
                num_filters=num_filters,
                filter_size=1,
                stride=stride if if_first else 1,
                is_vd_mode=False if if_first else True,
                lr_mult=lr_mult)
        self.shortcut = shortcut
        self.relu = nn.ReLU()

    def forward(self, x):
        identity = x
        x = self.conv0(x)
        x = self.conv1(x)
        if self.shortcut:
            short = identity
        else:
            short = self.short(identity)
        x = paddle.add(x=x, y=short)
        x = self.relu(x)
        return x


class ResNet(TheseusLayer):
C
cuicheng01 已提交
244 245 246 247 248 249 250 251 252
    """
    ResNet
    Args:
        config: dict. config of ResNet.
        version: str="vb". Different version of ResNet, version vd can perform better. 
        class_num: int=1000. The number of classes.
        lr_mult_list: list. Control the learning rate of different stages.
    Returns:
        model: nn.Layer. Specific ResNet model depends on args.
C
cuicheng01 已提交
253
    """
D
dongshuilong 已提交
254

C
cuicheng01 已提交
255 256
    def __init__(self,
                 config,
C
cuicheng01 已提交
257 258
                 version="vb",
                 class_num=1000,
D
dongshuilong 已提交
259
                 lr_mult_list=[1.0, 1.0, 1.0, 1.0, 1.0]):
C
cuicheng01 已提交
260
        super().__init__()
C
cuicheng01 已提交
261 262 263 264

        self.cfg = config
        self.lr_mult_list = lr_mult_list
        self.is_vd_mode = version == "vd"
C
cuicheng01 已提交
265 266 267 268 269 270
        self.class_num = class_num
        self.num_filters = [64, 128, 256, 512]
        self.block_depth = self.cfg["block_depth"]
        self.block_type = self.cfg["block_type"]
        self.num_channels = self.cfg["num_channels"]
        self.channels_mult = 1 if self.num_channels[-1] == 256 else 4
D
dongshuilong 已提交
271

C
cuicheng01 已提交
272 273 274 275
        assert isinstance(self.lr_mult_list, (
            list, tuple
        )), "lr_mult_list should be in (list, tuple) but got {}".format(
            type(self.lr_mult_list))
D
dongshuilong 已提交
276 277 278
        assert len(self.lr_mult_list
                   ) == 5, "lr_mult_list length should be 5 but got {}".format(
                       len(self.lr_mult_list))
C
cuicheng01 已提交
279 280

        self.stem_cfg = {
C
cuicheng01 已提交
281
            #num_channels, num_filters, filter_size, stride
C
cuicheng01 已提交
282
            "vb": [[3, 64, 7, 2]],
D
dongshuilong 已提交
283 284 285
            "vd": [[3, 32, 3, 2], [32, 32, 3, 1], [32, 64, 3, 1]]
        }

C
cuicheng01 已提交
286 287
        self.stem = nn.Sequential(*[
            ConvBNLayer(
D
dongshuilong 已提交
288 289 290 291 292 293
                num_channels=in_c,
                num_filters=out_c,
                filter_size=k,
                stride=s,
                act="relu",
                lr_mult=self.lr_mult_list[0])
C
cuicheng01 已提交
294 295
            for in_c, out_c, k, s in self.stem_cfg[version]
        ])
D
dongshuilong 已提交
296

C
cuicheng01 已提交
297
        self.max_pool = MaxPool2D(kernel_size=3, stride=2, padding=1)
C
cuicheng01 已提交
298 299
        block_list = []
        for block_idx in range(len(self.block_depth)):
C
cuicheng01 已提交
300
            shortcut = False
C
cuicheng01 已提交
301
            for i in range(self.block_depth[block_idx]):
D
dongshuilong 已提交
302 303 304
                block_list.append(globals()[self.block_type](
                    num_channels=self.num_channels[block_idx] if i == 0 else
                    self.num_filters[block_idx] * self.channels_mult,
C
cuicheng01 已提交
305 306
                    num_filters=self.num_filters[block_idx],
                    stride=2 if i == 0 and block_idx != 0 else 1,
C
cuicheng01 已提交
307
                    shortcut=shortcut,
C
cuicheng01 已提交
308 309
                    if_first=block_idx == i == 0 if version == "vd" else True,
                    lr_mult=self.lr_mult_list[block_idx + 1]))
D
dongshuilong 已提交
310
                shortcut = True
C
cuicheng01 已提交
311
        self.blocks = nn.Sequential(*block_list)
C
cuicheng01 已提交
312

C
cuicheng01 已提交
313
        self.avg_pool = AdaptiveAvgPool2D(1)
314
        self.flatten = nn.Flatten()
W
dbg  
weishengyu 已提交
315
        self.avg_pool_channels = self.num_channels[-1] * 2
C
cuicheng01 已提交
316
        stdv = 1.0 / math.sqrt(self.avg_pool_channels * 1.0)
C
cuicheng01 已提交
317
        self.fc = Linear(
C
cuicheng01 已提交
318
            self.avg_pool_channels,
C
cuicheng01 已提交
319
            self.class_num,
D
dongshuilong 已提交
320
            weight_attr=ParamAttr(initializer=Uniform(-stdv, stdv)))
C
cuicheng01 已提交
321 322 323

    def forward(self, x):
        x = self.stem(x)
C
cuicheng01 已提交
324
        x = self.max_pool(x)
C
cuicheng01 已提交
325
        x = self.blocks(x)
C
cuicheng01 已提交
326
        x = self.avg_pool(x)
327
        x = self.flatten(x)
C
cuicheng01 已提交
328
        x = self.fc(x)
C
cuicheng01 已提交
329 330 331
        return x


D
dongshuilong 已提交
332 333 334 335 336 337 338 339 340 341 342 343 344 345
def _load_pretrained(pretrained, model, model_url, use_ssld):
    if pretrained is False:
        pass
    elif pretrained is True:
        load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
    elif isinstance(pretrained, str):
        load_dygraph_pretrain(model, pretrained)
    else:
        raise RuntimeError(
            "pretrained type is not available. Please use `string` or `boolean` type."
        )


def ResNet18(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
346 347 348
    """
    ResNet18
    Args:
D
dongshuilong 已提交
349 350 351
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
352 353 354
    Returns:
        model: nn.Layer. Specific `ResNet18` model depends on args.
    """
D
dongshuilong 已提交
355 356
    model = ResNet(config=NET_CONFIG["18"], version="vb", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet18"], use_ssld)
C
cuicheng01 已提交
357 358
    return model

C
cuicheng01 已提交
359

D
dongshuilong 已提交
360
def ResNet18_vd(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
361 362 363
    """
    ResNet18_vd
    Args:
D
dongshuilong 已提交
364 365 366
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
367 368 369
    Returns:
        model: nn.Layer. Specific `ResNet18_vd` model depends on args.
    """
D
dongshuilong 已提交
370 371
    model = ResNet(config=NET_CONFIG["18"], version="vd", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet18_vd"], use_ssld)
C
cuicheng01 已提交
372 373
    return model

C
cuicheng01 已提交
374

D
dongshuilong 已提交
375
def ResNet34(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
376 377 378
    """
    ResNet34
    Args:
D
dongshuilong 已提交
379 380 381
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
382
    Returns:
C
cuicheng01 已提交
383
        model: nn.Layer. Specific `ResNet34` model depends on args.
C
cuicheng01 已提交
384
    """
D
dongshuilong 已提交
385 386
    model = ResNet(config=NET_CONFIG["34"], version="vb", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet34"], use_ssld)
C
cuicheng01 已提交
387 388 389
    return model


D
dongshuilong 已提交
390
def ResNet34_vd(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
391 392 393
    """
    ResNet34_vd
    Args:
D
dongshuilong 已提交
394 395 396
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
397
    Returns:
C
cuicheng01 已提交
398
        model: nn.Layer. Specific `ResNet34_vd` model depends on args.
C
cuicheng01 已提交
399
    """
D
dongshuilong 已提交
400 401
    model = ResNet(config=NET_CONFIG["34"], version="vd", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet34_vd"], use_ssld)
C
cuicheng01 已提交
402 403 404
    return model


D
dongshuilong 已提交
405
def ResNet50(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
406 407 408
    """
    ResNet50
    Args:
D
dongshuilong 已提交
409 410 411
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
412 413 414
    Returns:
        model: nn.Layer. Specific `ResNet50` model depends on args.
    """
D
dongshuilong 已提交
415 416
    model = ResNet(config=NET_CONFIG["50"], version="vb", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet50"], use_ssld)
C
cuicheng01 已提交
417 418
    return model

C
cuicheng01 已提交
419

D
dongshuilong 已提交
420
def ResNet50_vd(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
421 422 423
    """
    ResNet50_vd
    Args:
D
dongshuilong 已提交
424 425 426
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
427 428 429
    Returns:
        model: nn.Layer. Specific `ResNet50_vd` model depends on args.
    """
D
dongshuilong 已提交
430 431
    model = ResNet(config=NET_CONFIG["50"], version="vd", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet50_vd"], use_ssld)
C
cuicheng01 已提交
432 433
    return model

C
cuicheng01 已提交
434

D
dongshuilong 已提交
435
def ResNet101(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
436 437 438
    """
    ResNet101
    Args:
D
dongshuilong 已提交
439 440 441
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
442 443 444
    Returns:
        model: nn.Layer. Specific `ResNet101` model depends on args.
    """
D
dongshuilong 已提交
445 446
    model = ResNet(config=NET_CONFIG["101"], version="vb", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet101"], use_ssld)
C
cuicheng01 已提交
447 448
    return model

C
cuicheng01 已提交
449

D
dongshuilong 已提交
450
def ResNet101_vd(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
451 452 453
    """
    ResNet101_vd
    Args:
D
dongshuilong 已提交
454 455 456
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
457 458 459
    Returns:
        model: nn.Layer. Specific `ResNet101_vd` model depends on args.
    """
D
dongshuilong 已提交
460 461
    model = ResNet(config=NET_CONFIG["101"], version="vd", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet101_vd"], use_ssld)
C
cuicheng01 已提交
462 463
    return model

C
cuicheng01 已提交
464

D
dongshuilong 已提交
465
def ResNet152(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
466 467 468
    """
    ResNet152
    Args:
D
dongshuilong 已提交
469 470 471
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
472 473 474
    Returns:
        model: nn.Layer. Specific `ResNet152` model depends on args.
    """
D
dongshuilong 已提交
475 476
    model = ResNet(config=NET_CONFIG["152"], version="vb", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet152"], use_ssld)
C
cuicheng01 已提交
477 478
    return model

C
cuicheng01 已提交
479

D
dongshuilong 已提交
480
def ResNet152_vd(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
481 482 483
    """
    ResNet152_vd
    Args:
D
dongshuilong 已提交
484 485 486
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
487 488 489
    Returns:
        model: nn.Layer. Specific `ResNet152_vd` model depends on args.
    """
D
dongshuilong 已提交
490 491
    model = ResNet(config=NET_CONFIG["152"], version="vd", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet152_vd"], use_ssld)
C
cuicheng01 已提交
492 493 494
    return model


D
dongshuilong 已提交
495
def ResNet200_vd(pretrained=False, use_ssld=False, **kwargs):
C
cuicheng01 已提交
496 497 498
    """
    ResNet200_vd
    Args:
D
dongshuilong 已提交
499 500 501
        pretrained: bool=False or str. If `True` load pretrained parameters, `False` otherwise.
                    If str, means the path of the pretrained model.
        use_ssld: bool=False. Whether using distillation pretrained model when pretrained=True.
C
cuicheng01 已提交
502 503 504
    Returns:
        model: nn.Layer. Specific `ResNet200_vd` model depends on args.
    """
D
dongshuilong 已提交
505 506
    model = ResNet(config=NET_CONFIG["200"], version="vd", **kwargs)
    _load_pretrained(pretrained, model, MODEL_URLS["ResNet200_vd"], use_ssld)
C
cuicheng01 已提交
507
    return model