Python mxnet.nd.arange() Examples
The following are 7
code examples of mxnet.nd.arange().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mxnet.nd
, or try the search function
.
Example #1
Source File: learn_nms.py From kaggle-rsna18 with MIT License | 6 votes |
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
Example #2
Source File: learn_nms.py From Relation-Networks-for-Object-Detection with MIT License | 6 votes |
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
Example #3
Source File: learn_nms.py From kaggle-rsna18 with MIT License | 5 votes |
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
Example #4
Source File: learn_nms.py From Relation-Networks-for-Object-Detection with MIT License | 5 votes |
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
Example #5
Source File: train_cifar.py From ResidualAttentionNetwork with MIT License | 5 votes |
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
Example #6
Source File: train_mixup_cifar10.py From cascade_rcnn_gluon with Apache License 2.0 | 5 votes |
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
Example #7
Source File: test_encoders.py From gluon-ts with Apache License 2.0 | 5 votes |
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 )