当前位置: 首页>>代码示例>>Python>>正文


Python ndarray.load方法代码示例

本文整理汇总了Python中mxnet.ndarray.load方法的典型用法代码示例。如果您正苦于以下问题:Python ndarray.load方法的具体用法?Python ndarray.load怎么用?Python ndarray.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mxnet.ndarray的用法示例。


在下文中一共展示了ndarray.load方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_params

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def load_params(dir_path="", epoch=None, name=""):
    prefix = os.path.join(dir_path, name)
    _, param_loading_path, _ = get_saving_path(prefix, epoch)
    while not os.path.isfile(param_loading_path):
        logging.info("in load_param, %s Not Found!" % param_loading_path)
        time.sleep(60)
    save_dict = nd.load(param_loading_path)
    arg_params = {}
    aux_params = {}
    for k, v in save_dict.items():
        tp, name = k.split(':', 1)
        if tp == 'arg':
            arg_params[name] = v
        if tp == 'aux':
            aux_params[name] = v
    return arg_params, aux_params, param_loading_path 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:18,代码来源:utils.py

示例2: load_misc

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def load_misc(dir_path="", epoch=None, name=""):
    prefix = os.path.join(dir_path, name)
    _, _, misc_saving_path = get_saving_path(prefix, epoch)
    with open(misc_saving_path, 'r') as fp:
        misc = json.load(fp)
    return misc 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:8,代码来源:utils.py

示例3: load_npz

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def load_npz(path):
    with numpy.load(path) as data:
        ret = {k: data[k] for k in data.keys()}
        return ret 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:6,代码来源:utils.py

示例4: _try_load_parameters

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def _try_load_parameters(self, filename=None, model=None, ctx=None, allow_missing=False,
                         ignore_extra=False):
    def getblock(parent, name):
        if len(name) == 1:
            if name[0].isnumeric():
                return parent[int(name[0])]
            else:
                return getattr(parent, name[0])
        else:
            if name[0].isnumeric():
                return getblock(parent[int(name[0])], name[1:])
            else:
                return getblock(getattr(parent, name[0]), name[1:])
    if filename is not None:
        loaded = ndarray.load(filename)
    else:
        loaded = {k: v.data() for k, v in model._collect_params_with_prefix().items()}
    params = self._collect_params_with_prefix()
    if not loaded and not params:
        return

    if not any('.' in i for i in loaded.keys()):
        # legacy loading
        del loaded
        self.collect_params().load(
            filename, ctx, allow_missing, ignore_extra, self.prefix)
        return

    for name in loaded:
        if name in params:
            if params[name].shape != loaded[name].shape:
                continue
            params[name]._load_init(loaded[name], ctx) 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:35,代码来源:utils.py

示例5: _load_from_pytorch

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def _load_from_pytorch(self, filename, ctx=None):
    import torch
    from mxnet import nd
    loaded = torch.load(filename)
    params = self._collect_params_with_prefix()

    new_params = {}

    for name in loaded:
        if 'bn' in name or 'batchnorm' in name or '.downsample.1.' in name:
            if 'weight' in name:
                mxnet_name = name.replace('weight', 'gamma')
            elif 'bias' in name:
                mxnet_name = name.replace('bias', 'beta')
            else:
                mxnet_name = name
            new_params[mxnet_name] = nd.array(loaded[name].cpu().data.numpy())
        else:
            new_params[name] = nd.array(loaded[name].cpu().data.numpy())

    for name in new_params:
        if name not in params:
            print('==={}==='.format(name))
            raise Exception
        if name in params:
            params[name]._load_init(new_params[name], ctx=ctx) 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:28,代码来源:utils.py

示例6: resnet18_v1b_89

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def resnet18_v1b_89(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs):
    """Constructs a ResNetV1b-18_2.6x model. Uses resnet18_v1b construction from resnetv1b.py

    Parameters
    ----------
    pretrained : bool or str
        Boolean value controls whether to load the default pretrained weights for model.
        String value represents the hashtag for a certain version of pretrained weights.
    root : str, default '~/.mxnet/models'
        Location for keeping the model parameters.
    ctx : Context, default CPU
        The context in which to load the pretrained weights.
    """
    model = ResNetV1b(BasicBlockV1b, [2, 2, 2, 2], name_prefix='resnetv1b_', **kwargs)
    dirname = os.path.dirname(__file__)
    json_filename = os.path.join(dirname, 'resnet%d_v%db_%.1fx' % (18, 1, 2.6) + ".json")
    with open(json_filename, "r") as jsonFile:
        params_shapes = json.load(jsonFile)
    if pretrained:
        from ..model_store import get_model_file
        params_file = get_model_file('resnet%d_v%db_%.1fx' % (18, 1, 2.6), tag=pretrained,
                                     root=root)
        prune_gluon_block(model, model.name, params_shapes, params=ndarray.load(params_file),
                          pretrained=True, ctx=ctx)
    else:
        prune_gluon_block(model, model.name, params_shapes, params=None, pretrained=False, ctx=ctx)
    if pretrained:
        from ...data import ImageNet1kAttr
        attrib = ImageNet1kAttr()
        model.synset = attrib.synset
        model.classes = attrib.classes
        model.classes_long = attrib.classes_long
    return model 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:35,代码来源:resnetv1b_pruned.py

示例7: resnet50_v1d_86

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def resnet50_v1d_86(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs):
    """Constructs a ResNetV1d-50_1.8x model. Uses resnet50_v1d construction from resnetv1b.py

    Parameters
    ----------
    pretrained : bool or str
        Boolean value controls whether to load the default pretrained weights for model.
        String value represents the hashtag for a certain version of pretrained weights.
    root : str, default '~/.mxnet/models'
        Location for keeping the model parameters.
    ctx : Context, default CPU
        The context in which to load the pretrained weights.
    """
    model = ResNetV1b(BottleneckV1b, [3, 4, 6, 3], deep_stem=True, avg_down=True,
                      name_prefix='resnetv1d_', **kwargs)
    dirname = os.path.dirname(__file__)
    json_filename = os.path.join(dirname, 'resnet%d_v%dd_%.1fx' % (50, 1, 1.8) + ".json")
    with open(json_filename, "r") as jsonFile:
        params_shapes = json.load(jsonFile)
    if pretrained:
        from ..model_store import get_model_file
        params_file = get_model_file('resnet%d_v%dd_%.1fx' % (50, 1, 1.8), tag=pretrained,
                                     root=root)
        prune_gluon_block(model, model.name, params_shapes, params=ndarray.load(params_file),
                          pretrained=True, ctx=ctx)
    else:
        prune_gluon_block(model, model.name, params_shapes, params=None, pretrained=False, ctx=ctx)

    if pretrained:
        from ...data import ImageNet1kAttr
        attrib = ImageNet1kAttr()
        model.synset = attrib.synset
        model.classes = attrib.classes
        model.classes_long = attrib.classes_long
    return model 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:37,代码来源:resnetv1b_pruned.py

示例8: resnet50_v1d_48

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def resnet50_v1d_48(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs):
    """Constructs a ResNetV1d-50_3.6x model. Uses resnet50_v1d construction from resnetv1b.py

    Parameters
    ----------
    pretrained : bool or str
        Boolean value controls whether to load the default pretrained weights for model.
        String value represents the hashtag for a certain version of pretrained weights.
    root : str, default '~/.mxnet/models'
        Location for keeping the model parameters.
    ctx : Context, default CPU
        The context in which to load the pretrained weights.
    """
    model = ResNetV1b(BottleneckV1b, [3, 4, 6, 3], deep_stem=True, avg_down=True,
                      name_prefix='resnetv1d_', **kwargs)
    dirname = os.path.dirname(__file__)
    json_filename = os.path.join(dirname, 'resnet%d_v%dd_%.1fx' % (50, 1, 3.6) + ".json")
    with open(json_filename, "r") as jsonFile:
        params_shapes = json.load(jsonFile)
    if pretrained:
        from ..model_store import get_model_file
        params_file = get_model_file('resnet%d_v%dd_%.1fx' % (50, 1, 3.6), tag=pretrained,
                                     root=root)
        prune_gluon_block(model, model.name, params_shapes, params=ndarray.load(params_file),
                          pretrained=True, ctx=ctx)
    else:
        prune_gluon_block(model, model.name, params_shapes, params=None, pretrained=False, ctx=ctx)

    if pretrained:
        from ...data import ImageNet1kAttr
        attrib = ImageNet1kAttr()
        model.synset = attrib.synset
        model.classes = attrib.classes
        model.classes_long = attrib.classes_long
    return model 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:37,代码来源:resnetv1b_pruned.py

示例9: resnet50_v1d_11

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def resnet50_v1d_11(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs):
    """Constructs a ResNetV1d-50_8.8x model. Uses resnet50_v1d construction from resnetv1b.py

    Parameters
    ----------
    pretrained : bool or str
        Boolean value controls whether to load the default pretrained weights for model.
        String value represents the hashtag for a certain version of pretrained weights.
    root : str, default '~/.mxnet/models'
        Location for keeping the model parameters.
    ctx : Context, default CPU
        The context in which to load the pretrained weights.
    """
    model = ResNetV1b(BottleneckV1b, [3, 4, 6, 3], deep_stem=True, avg_down=True,
                      name_prefix='resnetv1d_', **kwargs)
    dirname = os.path.dirname(__file__)
    json_filename = os.path.join(dirname, 'resnet%d_v%dd_%.1fx' % (50, 1, 8.8) + ".json")
    with open(json_filename, "r") as jsonFile:
        params_shapes = json.load(jsonFile)
    if pretrained:
        from ..model_store import get_model_file
        params_file = get_model_file('resnet%d_v%dd_%.1fx' % (50, 1, 8.8), tag=pretrained,
                                     root=root)
        prune_gluon_block(model, model.name, params_shapes, params=ndarray.load(params_file),
                          pretrained=True, ctx=ctx)
    else:
        prune_gluon_block(model, model.name, params_shapes, params=None, pretrained=False, ctx=ctx)

    if pretrained:
        from ...data import ImageNet1kAttr
        attrib = ImageNet1kAttr()
        model.synset = attrib.synset
        model.classes = attrib.classes
        model.classes_long = attrib.classes_long
    return model 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:37,代码来源:resnetv1b_pruned.py

示例10: resnet101_v1d_76

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def resnet101_v1d_76(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs):
    """Constructs a ResNetV1d-101_1.9x model. Uses resnet101_v1d construction from resnetv1b.py

    Parameters
    ----------
    pretrained : bool or str
        Boolean value controls whether to load the default pretrained weights for model.
        String value represents the hashtag for a certain version of pretrained weights.
    root : str, default '~/.mxnet/models'
        Location for keeping the model parameters.
    ctx : Context, default CPU
        The context in which to load the pretrained weights.
    """
    model = ResNetV1b(BottleneckV1b, [3, 4, 23, 3], deep_stem=True, avg_down=True,
                      name_prefix='resnetv1d_', **kwargs)
    dirname = os.path.dirname(__file__)
    json_filename = os.path.join(dirname, 'resnet%d_v%dd_%.1fx' % (101, 1, 1.9) + ".json")
    with open(json_filename, "r") as jsonFile:
        params_shapes = json.load(jsonFile)
    if pretrained:
        from ..model_store import get_model_file
        params_file = get_model_file('resnet%d_v%dd_%.1fx' % (101, 1, 1.9), tag=pretrained,
                                     root=root)
        prune_gluon_block(model, model.name, params_shapes, params=ndarray.load(params_file),
                          pretrained=True, ctx=ctx)
    else:
        prune_gluon_block(model, model.name, params_shapes, params=None, pretrained=False, ctx=ctx)

    if pretrained:
        from ...data import ImageNet1kAttr
        attrib = ImageNet1kAttr()
        model.synset = attrib.synset
        model.classes = attrib.classes
        model.classes_long = attrib.classes_long
    return model 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:37,代码来源:resnetv1b_pruned.py

示例11: resnet101_v1d_73

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def resnet101_v1d_73(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs):
    """Constructs a ResNetV1d-101_2.2x model. Uses resnet101_v1d construction from resnetv1b.py

    Parameters
    ----------
    pretrained : bool or str
        Boolean value controls whether to load the default pretrained weights for model.
        String value represents the hashtag for a certain version of pretrained weights.
    root : str, default '~/.mxnet/models'
        Location for keeping the model parameters.
    ctx : Context, default CPU
        The context in which to load the pretrained weights.
    """
    model = ResNetV1b(BottleneckV1b, [3, 4, 23, 3], deep_stem=True, avg_down=True,
                      name_prefix='resnetv1d_', **kwargs)
    dirname = os.path.dirname(__file__)
    json_filename = os.path.join(dirname, 'resnet%d_v%dd_%.1fx' % (101, 1, 2.2) + ".json")
    with open(json_filename, "r") as jsonFile:
        params_shapes = json.load(jsonFile)
    if pretrained:
        from ..model_store import get_model_file
        params_file = get_model_file('resnet%d_v%dd_%.1fx' % (101, 1, 2.2), tag=pretrained,
                                     root=root)
        prune_gluon_block(model, model.name, params_shapes, params=ndarray.load(params_file),
                          pretrained=True, ctx=ctx)
    else:
        prune_gluon_block(model, model.name, params_shapes, params=None, pretrained=False, ctx=ctx)

    if pretrained:
        from ...data import ImageNet1kAttr
        attrib = ImageNet1kAttr()
        model.synset = attrib.synset
        model.classes = attrib.classes
        model.classes_long = attrib.classes_long
    return model 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:37,代码来源:resnetv1b_pruned.py

示例12: resnet50_v1d_37

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def resnet50_v1d_37(pretrained=False, root='~/.mxnet/models', ctx=cpu(0), **kwargs):
    """Constructs a ResNetV1d-50_5.9x model. Uses resnet50_v1d construction from resnetv1b.py

    Parameters
    ----------
    pretrained : bool or str
        Boolean value controls whether to load the default pretrained weights for model.
        String value represents the hashtag for a certain version of pretrained weights.
    root : str, default '~/.mxnet/models'
        Location for keeping the model parameters.
    ctx : Context, default CPU
        The context in which to load the pretrained weights.
    """
    model = ResNetV1b(BottleneckV1b, [3, 4, 6, 3], deep_stem=True, avg_down=True,
                      name_prefix='resnetv1d_', **kwargs)
    dirname = os.path.dirname(__file__)
    json_filename = os.path.join(dirname, 'resnet%d_v%dd_%.1fx' % (50, 1, 5.9) + ".json")
    with open(json_filename, "r") as jsonFile:
        params_shapes = json.load(jsonFile)
    if pretrained:
        from ..model_store import get_model_file
        params_file = get_model_file('resnet%d_v%dd_%.1fx' % (50, 1, 5.9), tag=pretrained,
                                     root=root)
        prune_gluon_block(model, model.name, params_shapes, params=ndarray.load(params_file),
                          pretrained=True, ctx=ctx)
    else:
        prune_gluon_block(model, model.name, params_shapes, params=None, pretrained=False, ctx=ctx)

    if pretrained:
        from ...data import ImageNet1kAttr
        attrib = ImageNet1kAttr()
        model.synset = attrib.synset
        model.classes = attrib.classes
        model.classes_long = attrib.classes_long
    return model 
开发者ID:Angzz,项目名称:panoptic-fpn-gluon,代码行数:37,代码来源:resnetv1b_pruned.py

示例13: get_alphapose

# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import load [as 别名]
def get_alphapose(name, dataset, num_joints, pretrained=False,
                  pretrained_base=False, ctx=mx.cpu(),
                  norm_layer=nn.BatchNorm, norm_kwargs=None,
                  root=os.path.join('~', '.mxnet', 'models'), **kwargs):
    r"""Utility function to return AlphaPose networks.

    Parameters
    ----------
    name : str
        Model name.
    dataset : str
        The name of dataset.
    pretrained : bool or str
        Boolean value controls whether to load the default pretrained weights for model.
        String value represents the hashtag for a certain version of pretrained weights.
    ctx : mxnet.Context
        Context such as mx.cpu(), mx.gpu(0).
    root : str
        Model weights storing path.

    Returns
    -------
    mxnet.gluon.HybridBlock
        The AlphaPose network.

    """
    if norm_kwargs is None:
        norm_kwargs = {}
    preact = FastSEResNet(name, norm_layer=norm_layer, **norm_kwargs)
    if not pretrained and pretrained_base:
        from gluoncv.model_zoo import get_model
        base_network = get_model(name, pretrained=True, root=root)
        _try_load_parameters(self=base_network, model=base_network)
    net = AlphaPose(preact, num_joints, **kwargs)
    if pretrained:
        from gluoncv.model_zoo.model_store import get_model_file
        full_name = '_'.join(('alpha_pose', name, dataset))
        net.load_parameters(get_model_file(full_name, tag=pretrained, root=root))
    else:
        import warnings
        with warnings.catch_warnings(record=True):
            warnings.simplefilter("always")
            net.collect_params().initialize()
    net.collect_params().reset_ctx(ctx)
    return net 
开发者ID:osmr,项目名称:imgclsmob,代码行数:47,代码来源:oth_alpha_pose.py


注:本文中的mxnet.ndarray.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。