Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
>>> model = get_darknet('v3', 53, pretrained=True)
>>> print(model)
"""
assert darknet_version in darknet_versions and darknet_version in darknet_spec, (
"Invalid darknet version: {}. Options are {}".format(
darknet_version, str(darknet_versions.keys())))
specs = darknet_spec[darknet_version]
assert num_layers in specs, (
"Invalid number of layers: {}. Options are {}".format(num_layers, str(specs.keys())))
layers, channels = specs[num_layers]
darknet_class = darknet_versions[darknet_version]
net = darknet_class(layers, channels, **kwargs)
if pretrained:
from ..model_store import get_model_file
net.load_parameters(get_model_file(
'darknet%d'%(num_layers), tag=pretrained, root=root), ctx=ctx)
return net
Normalization layer used (default: :class:`mxnet.gluon.nn.BatchNorm`)
Can be :class:`mxnet.gluon.nn.BatchNorm` or :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
norm_kwargs : dict
Additional `norm_layer` arguments, for example `num_devices=4`
for :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
"""
assert num_layers in resnext_spec, \
"Invalid number of layers: %d. Options are %s" % (
num_layers, str(resnext_spec.keys()))
layers = resnext_spec[num_layers]
net = ResNext(layers, cardinality, bottleneck_width, use_se=use_se, deep_stem=deep_stem,
avg_down=avg_down, **kwargs)
if pretrained:
from .model_store import get_model_file
if not use_se:
net.load_parameters(get_model_file('resnext%d_%dx%dd' % (num_layers, cardinality,
bottleneck_width),
tag=pretrained, root=root), ctx=ctx)
else:
net.load_parameters(get_model_file('se_resnext%d_%dx%dd' % (num_layers, cardinality,
bottleneck_width),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
net.synset = attrib.synset
net.classes = attrib.classes
net.classes_long = attrib.classes_long
return net
Location for keeping the model parameters.
norm_layer : object
Normalization layer used (default: :class:`mxnet.gluon.nn.BatchNorm`)
Can be :class:`mxnet.gluon.nn.BatchNorm` or :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
norm_kwargs : dict
Additional `norm_layer` arguments, for example `num_devices=4`
for :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
"""
assert num_layers in resnext_spec, \
"Invalid number of layers: %d. Options are %s" % (
num_layers, str(resnext_spec.keys()))
layers = resnext_spec[num_layers]
net = SENet(layers, cardinality, bottleneck_width, avg_down, **kwargs)
if pretrained:
from .model_store import get_model_file
net.load_parameters(get_model_file('senet_%d' % (num_layers + 2),
root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
net.synset = attrib.synset
net.classes = attrib.classes
net.classes_long = attrib.classes_long
return net
>>> print(model)
"""
acronyms = {
'pascal_voc': 'voc',
'pascal_aug': 'voc',
'ade20k': 'ade',
'coco': 'coco',
}
from ..data import datasets
# infer number of classes
model = FCN(datasets[dataset].NUM_CLASS, backbone=backbone, pretrained_base=pretrained_base,
ctx=ctx, **kwargs)
model.classes = datasets[dataset].classes
if pretrained:
from .model_store import get_model_file
model.load_parameters(get_model_file(
'fcn_%s_%s'%(backbone, acronyms[dataset]), tag=pretrained, root=root), ctx=ctx)
return 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.
norm_layer : object
Normalization layer used (default: :class:`mxnet.gluon.nn.BatchNorm`)
Can be :class:`mxnet.gluon.nn.BatchNorm` or :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
norm_kwargs : dict
Additional `norm_layer` arguments, for example `num_devices=4`
for :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
"""
num_init_features, growth_rate, block_config = densenet_spec[num_layers]
net = DenseNet(num_init_features, growth_rate, block_config, **kwargs)
if pretrained:
from .model_store import get_model_file
net.load_parameters(get_model_file('densenet%d'%(num_layers),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
net.synset = attrib.synset
net.classes = attrib.classes
net.classes_long = attrib.classes_long
return net
Additional `norm_layer` arguments, for example `num_devices=4`
for :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
Returns
-------
HybridBlock
A SSD detection network.
"""
pretrained_base = False if pretrained else pretrained_base
base_name = None if callable(features) else name
net = SSD(base_name, base_size, features, filters, sizes, ratios, steps,
pretrained=pretrained_base, classes=classes, ctx=ctx, root=root, **kwargs)
if pretrained:
from ..model_store import get_model_file
full_name = '_'.join(('ssd', str(base_size), name, dataset))
net.load_parameters(get_model_file(full_name, tag=pretrained, root=root), ctx=ctx)
return net
norm_layer : object
Normalization layer used (default: :class:`mxnet.gluon.nn.BatchNorm`)
Can be :class:`mxnet.gluon.nn.BatchNorm` or :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
norm_kwargs : dict
Additional `norm_layer` arguments, for example `num_devices=4`
for :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
Returns
-------
HybridBlock
A YOLOV3 detection network.
"""
net = YOLOV3(stages, filters, anchors, strides, classes=classes, **kwargs)
if pretrained:
from ..model_store import get_model_file
full_name = '_'.join(('yolo3', name, dataset))
net.load_parameters(get_model_file(full_name, tag=pretrained, root=root), ctx=ctx)
return net
root : str, default '~/.mxnet/models'
Location for keeping the model parameters.
ctx : Context, default CPU
The context in which to load the pretrained weights.
dilated: bool, default False
Whether to apply dilation strategy to ResNetV1b, yielding a stride 8 model.
norm_layer : object
Normalization layer used (default: :class:`mxnet.gluon.nn.BatchNorm`).
Can be :class:`mxnet.gluon.nn.BatchNorm` or :class:`mxnet.gluon.contrib.nn.SyncBatchNorm`.
"""
model = ResNetV1b(BottleneckV1b, [3, 4, 6, 3],
deep_stem=True, avg_down=True, stem_width=64,
name_prefix='resnetv1e_', **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_parameters(get_model_file('resnet%d_v%dd'%(50, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
model.classes = attrib.classes
model.classes_long = attrib.classes_long
return model
def resnet34_v1b_kinetics400(nclass=400, pretrained=False, pretrained_base=True,
use_tsn=False, partial_bn=False,
num_segments=1, num_crop=1, root='~/.mxnet/models',
ctx=mx.cpu(), **kwargs):
model = ActionRecResNetV1b(depth=34,
nclass=nclass,
partial_bn=partial_bn,
num_segments=num_segments,
num_crop=num_crop,
dropout_ratio=0.5,
init_std=0.01)
if pretrained:
from ..model_store import get_model_file
model.load_parameters(get_model_file('resnet34_v1b_kinetics400',
tag=pretrained, root=root))
from ...data import Kinetics400Attr
attrib = Kinetics400Attr()
model.classes = attrib.classes
model.collect_params().reset_ctx(ctx)
return model