當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。