Skip to content

Commit

Permalink
force mxnet>=1.3.0, replace load_params with load_parameters (#398)
Browse files Browse the repository at this point in the history
* force mxnet>=1.3.0, replace load_params with load_parameters

* fix pylint
  • Loading branch information
zhreshold authored Oct 16, 2018
1 parent 922d5a5 commit b55232d
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 74 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/classification/dive_deep_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test(ctx, val_data):
################################################################
# Next time if you need to use it, just run

net.load_params('dive_deep_cifar10_resnet20_v2.params', ctx=ctx)
net.load_parameters('dive_deep_cifar10_resnet20_v2.params', ctx=ctx)

################################################################
# Next Step
Expand Down
9 changes: 4 additions & 5 deletions gluoncv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
mx_version = '1.3.0'
try:
import mxnet as mx
import warnings
from distutils.version import LooseVersion
if LooseVersion(mx.__version__) < LooseVersion(mx_version):
msg = (
"Legacy mxnet=={} detected, some new modules may not work properly. "
"mxnet>={} is recommended. You can use pip to upgrade mxnet "
"`pip install mxnet --pre --upgrade`").format(mx.__version__, mx_version)
warnings.warn(msg)
"mxnet>={} is required. You can use pip to upgrade mxnet "
"`pip install mxnet/mxnet-cu90 --pre --upgrade`").format(mx.__version__, mx_version)
raise ImportError(msg)
except ImportError:
raise ImportError(
"Unable to import dependency mxnet. "
"A quick tip is to install via `pip install mxnet --pre`. "
"A quick tip is to install via `pip install mxnet/mxnet-cu90 --pre`. "
"please refer to https://gluon-cv.mxnet.io/#installation for details.")

__version__ = '0.3.0'
Expand Down
4 changes: 2 additions & 2 deletions gluoncv/model_zoo/cifarresnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ def get_cifar_resnet(version, num_layers, pretrained=False, ctx=cpu(),
net = resnet_class(block_class, layers, channels, **kwargs)
if pretrained:
from .model_store import get_model_file
net.load_params(get_model_file('cifar_resnet%d_v%d'%(num_layers, version),
tag=pretrained, root=root), ctx=ctx)
net.load_parameters(get_model_file('cifar_resnet%d_v%d'%(num_layers, version),
tag=pretrained, root=root), ctx=ctx)
return net

def cifar_resnet20_v1(**kwargs):
Expand Down
6 changes: 3 additions & 3 deletions gluoncv/model_zoo/cifarresnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ def get_cifar_resnext(num_layers, cardinality=16, bottleneck_width=64,
net = CIFARResNext(layers, cardinality, bottleneck_width, **kwargs)
if pretrained:
from .model_store import get_model_file
net.load_params(get_model_file('cifar_resnext%d_%dx%dd'%(num_layers, cardinality,
bottleneck_width),
tag=pretrained, root=root), ctx=ctx)
net.load_parameters(get_model_file('cifar_resnext%d_%dx%dd'%(num_layers, cardinality,
bottleneck_width),
tag=pretrained, root=root), ctx=ctx)
return net

def cifar_resnext29_32x4d(**kwargs):
Expand Down
4 changes: 2 additions & 2 deletions gluoncv/model_zoo/cifarwideresnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def get_cifar_wide_resnet(num_layers, width_factor=1, drop_rate=0.0,
net = CIFARWideResNet(CIFARBasicBlockV2, layers, channels, drop_rate, **kwargs)
if pretrained:
from .model_store import get_model_file
net.load_params(get_model_file('cifar_wideresnet%d_%d'%(num_layers, width_factor),
tag=pretrained, root=root), ctx=ctx)
net.load_parameters(get_model_file('cifar_wideresnet%d_%d'%(num_layers, width_factor),
tag=pretrained, root=root), ctx=ctx)
return net

def cifar_wideresnet16_10(**kwargs):
Expand Down
4 changes: 2 additions & 2 deletions gluoncv/model_zoo/nasnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ def get_nasnet(repeat=6, penultimate_filters=4032,
net = NASNetALarge(repeat=repeat, penultimate_filters=penultimate_filters, **kwargs)
if pretrained:
from .model_store import get_model_file
net.load_params(get_model_file('nasnet_%d_%d'%(repeat, penultimate_filters),
tag=pretrained, root=root), ctx=ctx)
net.load_parameters(get_model_file('nasnet_%d_%d'%(repeat, penultimate_filters),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
net.synset = attrib.synset
Expand Down
68 changes: 34 additions & 34 deletions gluoncv/model_zoo/resnetv1b.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ def resnet18_v1b(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs)
model = ResNetV1b(BasicBlockV1b, [2, 2, 2, 2], **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%db'%(18, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%db'%(18, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -314,8 +314,8 @@ def resnet34_v1b(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs)
model = ResNetV1b(BasicBlockV1b, [3, 4, 6, 3], **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%db'%(34, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%db'%(34, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -349,8 +349,8 @@ def resnet50_v1b(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs)
model = ResNetV1b(BottleneckV1b, [3, 4, 6, 3], **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%db'%(50, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%db'%(50, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -384,8 +384,8 @@ def resnet101_v1b(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
model = ResNetV1b(BottleneckV1b, [3, 4, 23, 3], **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%db'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%db'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -419,8 +419,8 @@ def resnet152_v1b(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
model = ResNetV1b(BottleneckV1b, [3, 8, 36, 3], **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%db'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%db'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -448,8 +448,8 @@ def resnet50_v1c(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs)
model = ResNetV1b(BottleneckV1b, [3, 4, 6, 3], deep_stem=True, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%dc'%(50, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%dc'%(50, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -478,8 +478,8 @@ def resnet101_v1c(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
model = ResNetV1b(BottleneckV1b, [3, 4, 23, 3], deep_stem=True, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%dc'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%dc'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -507,8 +507,8 @@ def resnet152_v1c(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
model = ResNetV1b(BottleneckV1b, [3, 8, 36, 3], deep_stem=True, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%dc'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%dc'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -536,8 +536,8 @@ def resnet50_v1d(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs)
model = ResNetV1b(BottleneckV1b, [3, 4, 6, 3], deep_stem=True, avg_down=True, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%dd'%(50, 1),
tag=pretrained, root=root), ctx=ctx)
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
Expand Down Expand Up @@ -565,8 +565,8 @@ def resnet101_v1d(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
model = ResNetV1b(BottleneckV1b, [3, 4, 23, 3], deep_stem=True, avg_down=True, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%dd'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%dd'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -594,8 +594,8 @@ def resnet152_v1d(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
model = ResNetV1b(BottleneckV1b, [3, 8, 36, 3], deep_stem=True, avg_down=True, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%dd'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%dd'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -624,8 +624,8 @@ def resnet50_v1e(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs)
deep_stem=True, avg_down=True, stem_width=64, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%dd'%(50, 1),
tag=pretrained, root=root), ctx=ctx)
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
Expand Down Expand Up @@ -654,8 +654,8 @@ def resnet101_v1e(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
deep_stem=True, avg_down=True, stem_width=64, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%dd'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%dd'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -684,8 +684,8 @@ def resnet152_v1e(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
deep_stem=True, avg_down=True, stem_width=64, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%dd'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%dd'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -714,8 +714,8 @@ def resnet50_v1s(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs)
model = ResNetV1b(BottleneckV1b, [3, 4, 6, 3], deep_stem=True, stem_width=64, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%ds'%(50, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%ds'%(50, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -744,8 +744,8 @@ def resnet101_v1s(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
model = ResNetV1b(BottleneckV1b, [3, 4, 23, 3], deep_stem=True, stem_width=64, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%ds'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%ds'%(101, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down Expand Up @@ -774,8 +774,8 @@ def resnet152_v1s(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs
model = ResNetV1b(BottleneckV1b, [3, 8, 36, 3], deep_stem=True, stem_width=64, **kwargs)
if pretrained:
from .model_store import get_model_file
model.load_params(get_model_file('resnet%d_v%ds'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
model.load_parameters(get_model_file('resnet%d_v%ds'%(152, 1),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
model.synset = attrib.synset
Expand Down
12 changes: 6 additions & 6 deletions gluoncv/model_zoo/resnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ def get_resnext(num_layers, cardinality=32, bottleneck_width=4, use_se=False,
if pretrained:
from .model_store import get_model_file
if not use_se:
net.load_params(get_model_file('resnext%d_%dx%dd'%(num_layers, cardinality,
bottleneck_width),
tag=pretrained, root=root), ctx=ctx)
net.load_parameters(get_model_file('resnext%d_%dx%dd'%(num_layers, cardinality,
bottleneck_width),
tag=pretrained, root=root), ctx=ctx)
else:
net.load_params(get_model_file('se_resnext%d_%dx%dd'%(num_layers, cardinality,
bottleneck_width),
tag=pretrained, root=root), ctx=ctx)
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
Expand Down
4 changes: 2 additions & 2 deletions gluoncv/model_zoo/se_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ def get_se_resnet(version, num_layers, pretrained=False, ctx=cpu(),
net = resnet_class(block_class, layers, channels, **kwargs)
if pretrained:
from .model_store import get_model_file
net.load_params(get_model_file('se_resnet%d_v%d'%(num_layers, version),
tag=pretrained, root=root), ctx=ctx)
net.load_parameters(get_model_file('se_resnet%d_v%d'%(num_layers, version),
tag=pretrained, root=root), ctx=ctx)
from ..data import ImageNet1kAttr
attrib = ImageNet1kAttr()
net.synset = attrib.synset
Expand Down
4 changes: 2 additions & 2 deletions gluoncv/model_zoo/senet.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def get_senet(num_layers, cardinality=64, bottleneck_width=4,
net = SENet(layers, cardinality, bottleneck_width, **kwargs)
if pretrained:
from .model_store import get_model_file
net.load_params(get_model_file('senet_%d'%(num_layers+2),
root=root), ctx=ctx)
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
Expand Down
2 changes: 1 addition & 1 deletion gluoncv/model_zoo/ssd/ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def get_ssd(name, base_size, features, filters, sizes, ratios, steps, classes,
if pretrained:
from ..model_store import get_model_file
full_name = '_'.join(('ssd', str(base_size), name, dataset))
net.load_params(get_model_file(full_name, tag=pretrained, root=root), ctx=ctx)
net.load_parameters(get_model_file(full_name, tag=pretrained, root=root), ctx=ctx)
return net

def ssd_300_vgg16_atrous_voc(pretrained=False, pretrained_base=True, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions gluoncv/model_zoo/ssd/vgg_atrous.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def get_vgg_atrous_extractor(num_layers, im_size, pretrained=False, ctx=mx.cpu()
from ..model_store import get_model_file
batch_norm_suffix = '_bn' if kwargs.get('batch_norm') else ''
net.initialize(ctx=ctx)
net.load_params(get_model_file('vgg%d_atrous%s'%(num_layers, batch_norm_suffix),
tag=pretrained, root=root), ctx=ctx, allow_missing=True)
net.load_parameters(get_model_file('vgg%d_atrous%s'%(num_layers, batch_norm_suffix),
tag=pretrained, root=root), ctx=ctx, allow_missing=True)
return net

def vgg16_atrous_300(**kwargs):
Expand Down
2 changes: 1 addition & 1 deletion gluoncv/model_zoo/yolo/yolo3.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def get_yolov3(name, stages, filters, anchors, strides, classes,
if pretrained:
from ..model_store import get_model_file
full_name = '_'.join(('yolo3', name, dataset))
net.load_params(get_model_file(full_name, tag=pretrained, root=root), ctx=ctx)
net.load_parameters(get_model_file(full_name, tag=pretrained, root=root), ctx=ctx)
return net

def yolo3_darknet53_voc(pretrained_base=True, pretrained=False, num_sync_bn_devices=-1, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion scripts/classification/cifar/demo_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
net = get_model(model_name, **kwargs)

if not pretrained:
net.load_params(opt.saved_params, ctx = context)
net.load_parameters(opt.saved_params, ctx = context)

# Load Images
img = image.imread(opt.input_pic)
Expand Down
2 changes: 1 addition & 1 deletion scripts/classification/cifar/train_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
kwargs = {'classes': classes}
net = get_model(model_name, **kwargs)
if opt.resume_from:
net.load_params(opt.resume_from, ctx = context)
net.load_parameters(opt.resume_from, ctx = context)
optimizer = 'nag'

save_period = opt.save_period
Expand Down
Loading

0 comments on commit b55232d

Please sign in to comment.