本文整理汇总了Python中chainer.functions.get_item方法的典型用法代码示例。如果您正苦于以下问题:Python functions.get_item方法的具体用法?Python functions.get_item怎么用?Python functions.get_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chainer.functions
的用法示例。
在下文中一共展示了functions.get_item方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_aabb_corners
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def get_aabb_corners(grids, image_size):
_, _, height, width = grids.shape
grids = (grids + 1) / 2
x_points = grids[:, 0, ...] * image_size.width
y_points = grids[:, 1, ...] * image_size.height
x_points = F.clip(x_points, 0., float(image_size.width))
y_points = F.clip(y_points, 0., float(image_size.height))
top_left_x = F.get_item(x_points, [..., 0, 0])
top_left_y = F.get_item(y_points, [..., 0, 0])
top_right_x = F.get_item(x_points, [..., 0, width - 1])
top_right_y = F.get_item(y_points, [..., 0, width - 1])
bottom_right_x = F.get_item(x_points, [..., height - 1, width - 1])
bottom_right_y = F.get_item(y_points, [..., height - 1, width - 1])
bottom_left_x = F.get_item(x_points, [..., height - 1, 0])
bottom_left_y = F.get_item(y_points, [..., height - 1, 0])
top_left_x_aabb = F.minimum(top_left_x, bottom_left_x)
top_left_y_aabb = F.minimum(top_left_y, top_right_y)
bottom_right_x_aabb = F.maximum(top_right_x, bottom_right_x)
bottom_right_y_aabb = F.maximum(bottom_left_y, bottom_right_y)
return top_left_y_aabb, top_left_x_aabb, bottom_right_y_aabb, bottom_right_x_aabb
示例2: calc_bboxes
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def calc_bboxes(self, predicted_bboxes, image_size, out_size):
predicted_bboxes = (predicted_bboxes + 1) / 2
x_points = predicted_bboxes[:, 0, ...] * image_size.width
y_points = predicted_bboxes[:, 1, ...] * image_size.height
top_left_x = F.get_item(x_points, [..., 0, 0])
top_left_y = F.get_item(y_points, [..., 0, 0])
bottom_right_x = F.get_item(x_points, [..., out_size.height - 1, out_size.width - 1])
bottom_right_y = F.get_item(y_points, [..., out_size.height - 1, out_size.width - 1])
bboxes = F.stack(
[
F.minimum(top_left_x, bottom_right_x),
F.minimum(top_left_y, bottom_right_y),
F.maximum(top_left_x, bottom_right_x),
F.maximum(top_left_y, bottom_right_y),
],
axis=1
)
return bboxes
示例3: get_corners
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def get_corners(self, grids, image_size, scale_to_image_size=True):
_, _, height, width = grids.shape
if scale_to_image_size:
grids = (grids + 1) / 2
x_points = grids[:, 0, ...] * image_size.width
y_points = grids[:, 1, ...] * image_size.height
else:
x_points = grids[:, 0, ...]
y_points = grids[:, 1, ...]
top_left_x = F.get_item(x_points, [..., 0, 0])
top_left_y = F.get_item(y_points, [..., 0, 0])
top_right_x = F.get_item(x_points, [..., 0, width - 1])
top_right_y = F.get_item(y_points, [..., 0, width - 1])
bottom_left_x = F.get_item(x_points, [..., height - 1, 0])
bottom_left_y = F.get_item(y_points, [..., height - 1, 0])
bottom_right_x = F.get_item(x_points, [..., height - 1, width - 1])
bottom_right_y = F.get_item(y_points, [..., height - 1, width - 1])
return top_left_x, top_right_x, bottom_left_x, bottom_right_x, top_left_y, top_right_y, bottom_left_y, bottom_right_y
示例4: forward
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def forward(self, xs, activation=None):
ilens = [x.shape[0] for x in xs]
# xs: (B, T, F)
xs = F.pad_sequence(xs, padding=-1)
pad_shape = xs.shape
# emb: (B*T, E)
emb = self.enc(xs)
# ys: (B*T, C)
ys = self.linear(emb)
if activation:
ys = activation(ys)
# ys: [(T, C), ...]
ys = F.separate(ys.reshape(pad_shape[0], pad_shape[1], -1), axis=0)
ys = [F.get_item(y, slice(0, ilen)) for y, ilen in zip(ys, ilens)]
return ys
示例5: forward
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def forward(self, inputs, device):
x, = inputs
y = functions.get_item(x, self.slices)
return y,
示例6: check_forward
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def check_forward(self, x_data):
slices = []
for i, s in enumerate(self.slices):
if isinstance(s, numpy.ndarray):
s = chainer.backends.cuda.cupy.array(s)
if isinstance(s, list):
s = chainer.backends.cuda.cupy.array(s, dtype=numpy.int32)
slices.append(s)
slices = tuple(slices)
x = chainer.Variable(x_data)
y = functions.get_item(x, slices)
self.assertEqual(y.data.dtype, numpy.float32)
numpy.testing.assert_equal(cuda.to_cpu(x_data)[self.slices],
cuda.to_cpu(y.data))
示例7: check_backward
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def check_backward(self, x_data, y_grad):
slices = []
for i, s in enumerate(self.slices):
if isinstance(s, numpy.ndarray):
s = chainer.backends.cuda.cupy.array(s)
if isinstance(s, list):
s = chainer.backends.cuda.cupy.array(s, dtype=numpy.int32)
slices.append(s)
slices = tuple(slices)
def f(x):
return functions.get_item(x, slices)
gradient_check.check_backward(
f, (x_data,), y_grad, dtype='d')
示例8: test_multiple_ellipsis
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def test_multiple_ellipsis(self):
with self.assertRaises(ValueError):
functions.get_item(self.x_data, (Ellipsis, Ellipsis))
示例9: test_get_item_slice_step
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def test_get_item_slice_step(self, name, slices):
skip_opsets = tuple(range(7, 11))
name = 'get_item_' + name
model = chainer.Sequential(
lambda x: F.get_item(x, slices=slices))
x = input_generator.increasing(2, 3, 4)
self.expect(
model, x, name=name, expected_num_initializers=0,
skip_opset_version=skip_opsets)
示例10: test_get_item_unsupported
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def test_get_item_unsupported(self, slices):
model = chainer.Sequential(
lambda x: F.get_item(x, slices=slices))
x = input_generator.increasing(2, 3, 4)
with pytest.raises(ValueError):
export(model, x, opset_version=7)
示例11: test_get_item_unsupported_advanced_index
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def test_get_item_unsupported_advanced_index(self, slices):
model = chainer.Sequential(
lambda x: F.get_item(x, slices=slices))
x = input_generator.increasing(2, 3, 4)
with pytest.raises(ValueError):
export(model, x)
示例12: get_corners
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def get_corners(self, grids):
_, _, height, width = grids.shape
grids = (grids + 1) / 2
x_points = grids[:, 0, ...] * self.image_size.width
y_points = grids[:, 1, ...] * self.image_size.height
top_left_x = F.get_item(x_points, [..., 0, 0])
top_left_y = F.get_item(y_points, [..., 0, 0])
top_right_x = F.get_item(x_points, [..., 0, width - 1])
top_right_y = F.get_item(y_points, [..., 0, width - 1])
bottom_left_x = F.get_item(x_points, [..., height - 1, 0])
bottom_left_y = F.get_item(y_points, [..., height - 1, 0])
return top_left_x, top_right_x, bottom_left_x, top_left_y, top_right_y, bottom_left_y
示例13: sample
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def sample(self, x):
pi, mu, log_var = self.get_gaussian_params(x)
n_batch = pi.shape[0]
# Choose one of Gaussian means and vars n_batch times
ps = chainer.backends.cuda.to_cpu(pi.array)
idx = [np.random.choice(self.gaussian_mixtures, p=p) for p in ps]
mu = F.get_item(mu, [range(n_batch), idx])
log_var = F.get_item(log_var, [range(n_batch), idx])
# Sampling
z = F.gaussian(mu, log_var)
return z
示例14: test_output
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def test_output(self, name, slices):
skip_opsets = None
if name.startswith('gathernd'):
skip_opsets = tuple(range(7, 11))
name = 'get_item_' + name
model = chainer.Sequential(
lambda x: F.get_item(x, slices=slices))
x = input_generator.increasing(2, 3, 4)
self.expect(
model, x, name=name, expected_num_initializers=0,
skip_opset_version=skip_opsets)
示例15: test_get_item_error
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import get_item [as 别名]
def test_get_item_error(slices):
model = chainer.Sequential(
lambda x: F.get_item(x, slices=slices))
x = input_generator.increasing(2, 3, 4)
with pytest.raises(ValueError):
export(model, x)