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


Python nd.arange方法代码示例

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


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

示例1: extract_pairwise_multi_position_embedding_nd

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import arange [as 别名]
def extract_pairwise_multi_position_embedding_nd(position_mat, feat_dim, wave_length=1000):
    """ Extract multi-class position embedding

    Args:
        position_mat: [num_fg_classes, num_rois, num_rois, 4]
        feat_dim: dimension of embedding feature
        wave_length:

    Returns:
        embedding: [num_fg_classes, num_rois, num_rois, feat_dim]
    """
    feat_range = nd.arange(0, feat_dim / 8)
    dim_mat = nd.broadcast_power(lhs=nd.full((1,), wave_length),
                                     rhs=(8. / feat_dim) * feat_range)
    dim_mat = nd.Reshape(dim_mat, shape=(1, 1, 1, 1, -1))
    position_mat = nd.expand_dims(100.0 * position_mat, axis=4)
    div_mat = nd.broadcast_div(lhs=position_mat, rhs=dim_mat)
    sin_mat = nd.sin(data=div_mat)
    cos_mat = nd.cos(data=div_mat)
    # embedding, [num_fg_classes, num_rois, num_rois, 4, feat_dim/4]
    embedding = nd.concat(sin_mat, cos_mat, dim=4)
    embedding = nd.Reshape(embedding, shape=(0, 0, 0, feat_dim))
    return embedding 
开发者ID:i-pan,项目名称:kaggle-rsna18,代码行数:25,代码来源:learn_nms.py

示例2: extract_rank_embedding_nd

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import arange [as 别名]
def extract_rank_embedding_nd(rank_dim, feat_dim, wave_length=1000):
    rank_range = nd.arange(0, rank_dim)
    feat_range = nd.arange(0, feat_dim / 2)
    dim_mat = nd.broadcast_power(lhs=nd.full((1,), wave_length),
                                     rhs=(2. / feat_dim) * feat_range)
    dim_mat = nd.Reshape(dim_mat, shape=(1, -1))
    rank_mat = nd.expand_dims(rank_range, axis=1)
    div_mat = nd.broadcast_div(lhs=rank_mat, rhs=dim_mat)
    sin_mat = nd.sin(data=div_mat)
    cos_mat = nd.cos(data=div_mat)
    embedding = nd.concat(sin_mat, cos_mat, dim=1)
    return embedding 
开发者ID:i-pan,项目名称:kaggle-rsna18,代码行数:14,代码来源:learn_nms.py

示例3: label_transform

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import arange [as 别名]
def label_transform(label, classes):
    ind = label.astype('int')
    res = nd.zeros((ind.shape[0], classes), ctx=label.context)
    res[nd.arange(ind.shape[0], ctx=label.context), ind] = 1
    return res 
开发者ID:PistonY,项目名称:ResidualAttentionNetwork,代码行数:7,代码来源:train_cifar.py

示例4: label_transform

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import arange [as 别名]
def label_transform(label, classes):
    ind = label.astype('int')
    res = nd.zeros((ind.shape[0], classes), ctx = label.context)
    res[nd.arange(ind.shape[0], ctx = label.context), ind] = 1
    return res 
开发者ID:zzdang,项目名称:cascade_rcnn_gluon,代码行数:7,代码来源:train_mixup_cifar10.py

示例5: test_hierarchical_cnn_encoders

# 需要导入模块: from mxnet import nd [as 别名]
# 或者: from mxnet.nd import arange [as 别名]
def test_hierarchical_cnn_encoders(use_residual, hybridize) -> None:
    num_ts = 2
    ts_len = 10
    num_static_feat = 2
    num_dynamic_feat = 5

    test_data = nd.arange(num_ts * ts_len).reshape(shape=(num_ts, ts_len, 1))
    test_static_feat = nd.random.randn(num_ts, num_static_feat)
    test_dynamic_feat = nd.random.randn(num_ts, ts_len, num_dynamic_feat)

    chl_dim = [30, 30, 30]
    ks_seq = [3] * len(chl_dim)
    dial_seq = [1, 3, 9]

    cnn = HierarchicalCausalConv1DEncoder(
        dial_seq,
        ks_seq,
        chl_dim,
        use_residual,
        use_dynamic_feat=True,
        use_static_feat=True,
    )
    cnn.collect_params().initialize()

    if hybridize:
        cnn.hybridize()

    true_shape = (num_ts, ts_len, 31) if use_residual else (num_ts, ts_len, 30)

    assert (
        cnn(test_data, test_static_feat, test_dynamic_feat)[1].shape
        == true_shape
    ) 
开发者ID:awslabs,项目名称:gluon-ts,代码行数:35,代码来源:test_encoders.py


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