本文整理汇总了Python中mxnet.ndarray.split方法的典型用法代码示例。如果您正苦于以下问题:Python ndarray.split方法的具体用法?Python ndarray.split怎么用?Python ndarray.split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mxnet.ndarray
的用法示例。
在下文中一共展示了ndarray.split方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_out_grads
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def test_out_grads():
x = nd.ones((3, 5))
dx = nd.zeros_like(x)
mark_variables([x], [dx])
da = None
db = nd.array([1,2,3,4,5])
dc = nd.array([5,4,3,2,1])
with record():
a, b, c = nd.split(x, axis=0, num_outputs=3, squeeze_axis=True)
backward([a, b, c], [da, db, dc])
assert (dx.asnumpy() == np.array(
[[1,1,1,1,1],
[1,2,3,4,5],
[5,4,3,2,1]])).all()
示例2: test_out_grads
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def test_out_grads():
x = nd.ones((3, 5))
dx = nd.zeros_like(x)
mark_variables([x], [dx])
da = None
db = nd.array([1,2,3,4,5])
dc = nd.array([5,4,3,2,1])
with train_section():
a, b, c = nd.split(x, axis=0, num_outputs=3, squeeze_axis=True)
backward([a, b, c], [da, db, dc])
assert (dx.asnumpy() == np.array(
[[1,1,1,1,1],
[1,2,3,4,5],
[5,4,3,2,1]])).all()
示例3: split
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def split(x, sizes_or_sections, dim):
if isinstance(sizes_or_sections, list) and len(sizes_or_sections) == 1:
assert len(x) == sizes_or_sections[0]
return [x]
if MX_VERSION.version[0] == 1 and MX_VERSION.version[1] >= 5:
if isinstance(sizes_or_sections, (np.ndarray, list)):
sizes_or_sections1 = tuple(np.cumsum(sizes_or_sections)[:-1])
return nd.split_v2(x, sizes_or_sections1, axis=dim)
if isinstance(sizes_or_sections, list) or isinstance(sizes_or_sections, np.ndarray):
# Old MXNet doesn't support split with different section sizes.
np_arr = x.asnumpy()
indices = np.cumsum(sizes_or_sections)[:-1]
res = np.split(np_arr, indices, axis=dim)
return [tensor(arr, dtype=x.dtype) for arr in res]
else:
return nd.split(x, sizes_or_sections, axis=dim)
示例4: inverse
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def inverse(self, y):
import mxnet.ndarray as F
scale_sqr = self.scale * self.scale
batch, y_channels, y_height, y_width = y.shape
assert (y_channels % scale_sqr == 0)
x_channels = y_channels // scale_sqr
x_height = y_height * self.scale
x_width = y_width * self.scale
x = y.transpose(axes=(0, 2, 3, 1))
x = x.reshape(batch, y_height, y_width, scale_sqr, x_channels)
d3_split_seq = x.split(axis=3, num_outputs=(x.shape[3] // self.scale))
d3_split_seq = [t.reshape(batch, y_height, x_width, x_channels) for t in d3_split_seq]
x = F.stack(*d3_split_seq, axis=0)
x = x.swapaxes(0, 1).transpose(axes=(0, 2, 1, 3, 4)).reshape(batch, x_height, x_width, x_channels)
x = x.transpose(axes=(0, 3, 1, 2))
return x
示例5: tensor_save_bgrimage
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def tensor_save_bgrimage(tensor, filename, cuda=False):
(b, g, r) = F.split(tensor, num_outputs=3, axis=0)
tensor = F.concat(r, g, b, dim=0)
tensor_save_rgbimage(tensor, filename, cuda)
示例6: subtract_imagenet_mean_batch
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def subtract_imagenet_mean_batch(batch):
"""Subtract ImageNet mean pixel-wise from a BGR image."""
batch = F.swapaxes(batch,0, 1)
(r, g, b) = F.split(batch, num_outputs=3, axis=0)
r = r - 123.680
g = g - 116.779
b = b - 103.939
batch = F.concat(r, g, b, dim=0)
batch = F.swapaxes(batch,0, 1)
return batch
示例7: subtract_imagenet_mean_preprocess_batch
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def subtract_imagenet_mean_preprocess_batch(batch):
"""Subtract ImageNet mean pixel-wise from a BGR image."""
batch = F.swapaxes(batch,0, 1)
(r, g, b) = F.split(batch, num_outputs=3, axis=0)
r = r - 123.680
g = g - 116.779
b = b - 103.939
batch = F.concat(b, g, r, dim=0)
batch = F.swapaxes(batch,0, 1)
return batch
示例8: add_imagenet_mean_batch
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def add_imagenet_mean_batch(batch):
batch = F.swapaxes(batch,0, 1)
(b, g, r) = F.split(batch, num_outputs=3, axis=0)
r = r + 123.680
g = g + 116.779
b = b + 103.939
batch = F.concat(b, g, r, dim=0)
batch = F.swapaxes(batch,0, 1)
"""
batch = denormalizer(batch)
"""
return batch
示例9: preprocess_batch
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def preprocess_batch(batch):
batch = F.swapaxes(batch, 0, 1)
(r, g, b) = F.split(batch, num_outputs=3, axis=0)
batch = F.concat(b, g, r, dim=0)
batch = F.swapaxes(batch, 0, 1)
return batch
示例10: edge_func
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def edge_func(self, edges):
real_head, img_head = nd.split(edges.src['emb'], num_outputs=2, axis=-1)
real_tail, img_tail = nd.split(edges.dst['emb'], num_outputs=2, axis=-1)
real_rel, img_rel = nd.split(edges.data['emb'], num_outputs=2, axis=-1)
score = real_head * real_tail * real_rel \
+ img_head * img_tail * real_rel \
+ real_head * img_tail * img_rel \
- img_head * real_tail * img_rel
# TODO: check if there exists minus sign and if gamma should be used here(jin)
return {'score': nd.sum(score, -1)}
示例11: create_neg
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def create_neg(self, neg_head):
if neg_head:
def fn(heads, relations, tails, num_chunks, chunk_size, neg_sample_size):
hidden_dim = heads.shape[1]
emb_real, emb_img = nd.split(tails, num_outputs=2, axis=-1)
rel_real, rel_img = nd.split(relations, num_outputs=2, axis=-1)
real = emb_real * rel_real + emb_img * rel_img
img = -emb_real * rel_img + emb_img * rel_real
emb_complex = nd.concat(real, img, dim=-1)
tmp = emb_complex.reshape(num_chunks, chunk_size, hidden_dim)
heads = heads.reshape(num_chunks, neg_sample_size, hidden_dim)
heads = nd.transpose(heads, axes=(0, 2, 1))
return nd.linalg_gemm2(tmp, heads)
return fn
else:
def fn(heads, relations, tails, num_chunks, chunk_size, neg_sample_size):
hidden_dim = heads.shape[1]
emb_real, emb_img = nd.split(heads, num_outputs=2, axis=-1)
rel_real, rel_img = nd.split(relations, num_outputs=2, axis=-1)
real = emb_real * rel_real - emb_img * rel_img
img = emb_real * rel_img + emb_img * rel_real
emb_complex = nd.concat(real, img, dim=-1)
tmp = emb_complex.reshape(num_chunks, chunk_size, hidden_dim)
tails = tails.reshape(num_chunks, neg_sample_size, hidden_dim)
tails = nd.transpose(tails, axes=(0, 2, 1))
return nd.linalg_gemm2(tmp, tails)
return fn
示例12: hybrid_forward
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def hybrid_forward(self, F, x):
batch, x_channels, x_height, x_width = x.shape
y_channels = x_channels * self.scale * self.scale
assert (x_height % self.scale == 0)
y_height = x_height // self.scale
y = x.transpose(axes=(0, 2, 3, 1))
d2_split_seq = y.split(axis=2, num_outputs=(y.shape[2] // self.scale))
d2_split_seq = [t.reshape(batch, y_height, y_channels) for t in d2_split_seq]
y = F.stack(*d2_split_seq, axis=1)
y = y.transpose(axes=(0, 3, 2, 1))
return y
示例13: _get_lstm_features
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import split [as 别名]
def _get_lstm_features(self, sentence):
self.hidden = self.init_hidden()
length = sentence.shape[0]
embeds = self.word_embeds(sentence).reshape((length, 1, -1))
lstm_out, self.hidden = self.lstm(embeds, self.hidden)
lstm_out = lstm_out.reshape((length, self.hidden_dim))
lstm_feats = self.hidden2tag(lstm_out)
return nd.split(lstm_feats, num_outputs=length, axis=0, squeeze_axis=True)