本文整理汇总了Python中chainer.is_debug方法的典型用法代码示例。如果您正苦于以下问题:Python chainer.is_debug方法的具体用法?Python chainer.is_debug怎么用?Python chainer.is_debug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chainer
的用法示例。
在下文中一共展示了chainer.is_debug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forward
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def forward(self, *xs):
"""Applies broadcasted elementwise summation.
Args:
xs (list of Variables): Input variables whose length should
be one if the link has a learnable bias parameter, otherwise
should be two.
"""
axis = self.axis
# Case of only one argument where b is a learnt parameter.
if hasattr(self, 'b'):
if chainer.is_debug():
assert len(xs) == 1
x, = xs
b = self.b
return bias.bias(x, b, axis)
# Case of two arguments where b is given as an argument.
else:
if chainer.is_debug():
assert len(xs) == 2
x, y = xs
return bias.bias(x, y, axis)
示例2: forward
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def forward(self, inputs):
self.retain_inputs((1,))
x, t = inputs
self._in_shape = x.shape
self._in_dtype = x.dtype
if chainer.is_debug():
if not ((0 <= t).all() and
(t < x.shape[1]).all()):
msg = 'Each label `t` need to satisfty `0 <= t < x.shape[1]`'
raise ValueError(msg)
xp = backend.get_array_module(x)
if xp is numpy:
# This code is equivalent to `t.choose(x.T)`, but `numpy.choose`
# does not work when `x.shape[1] > 32`.
return x[six.moves.range(t.size), t],
else:
y = cuda.elementwise(
'S t, raw T x',
'T y',
'int ind[] = {i, t}; y = x[ind];',
'getitem_fwd'
)(t, x)
return y,
示例3: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def __init__(self, slices):
if isinstance(slices, list):
if all([isinstance(s, int) for s in slices]):
slices = slices,
slices = tuple(slices)
elif not isinstance(slices, tuple):
slices = slices,
if chainer.is_debug():
n_ellipses = 0
for s in slices:
if s is Ellipsis:
n_ellipses += 1
if n_ellipses > 1:
raise ValueError('Only one Ellipsis is allowed')
self.slices = slices
示例4: forward
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def forward(self, inputs):
self.retain_inputs((0,))
x, W = inputs
self._w_shape = W.shape
xp = backend.get_array_module(*inputs)
if chainer.is_debug():
valid_x = xp.logical_and(0 <= x, x < len(W))
if self.ignore_label is not None:
valid_x = xp.logical_or(valid_x, x == self.ignore_label)
if not valid_x.all():
raise ValueError('Each not ignored `x` value need to satisfy '
'`0 <= x < len(W)`')
if self.ignore_label is not None:
mask = (x == self.ignore_label)
return xp.where(mask[..., None], 0, W[xp.where(mask, 0, x)]),
return W[x],
示例5: forward
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def forward(self, axis, gamma, x, x_layout, xp, expander,
beta, eps, decay, running_mean, running_var):
if running_mean is not None:
mean = running_mean
var = running_var
else:
# Create dummies.
mean = xp.zeros_like(gamma, dtype=x.dtype)
var = xp.zeros_like(gamma, dtype=x.dtype)
# mean and inv_std are used as buffers to save
# intermediate results computed during forward pass. These buffers
# are used to speed-up backward pass.
cudnn_x_layout = cuda._get_cudnn_tensor_layout_x(x_layout)
reserve_space, y, mean, inv_std = (
cudnn.batch_normalization_forward_training_ex(
x, gamma, beta, mean, var, None, None,
eps, decay, self.is_for_conv2d,
self.cudnn_mode, chainer.is_debug(),
d_layout=cudnn_x_layout))
y_layout = x_layout
return (
y, y_layout, running_mean, running_var, mean, var, inv_std,
reserve_space)
示例6: _scan_directory
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def _scan_directory(fs, directory):
local_files = []
try:
local_files = fs.list(directory)
except Exception as e:
if chainer.is_debug():
print("Cannot list directory {}: {}".format(directory, e))
local_files = filter(lambda s: not s.startswith('tmp'), local_files)
files = filter(None, [(_parse_filename(f), f) for f in local_files])
files = list(files)
files.sort()
if len(files) > 0:
_i, filename = max(files)
return filename
else:
return None
示例7: forward
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def forward(self, *xs):
"""Applies broadcasted elementwise product.
Args:
xs (list of Variables): Input variables whose length should
be one if the link has a learnable weight parameter, otherwise
should be two.
"""
axis = self.axis
# Case of only one argument where W is a learnt parameter.
if hasattr(self, 'W'):
if chainer.is_debug():
assert len(xs) == 1
x, = xs
W = self.W
z = scale.scale(x, W, axis)
# Case of two arguments where W is given as an argument.
else:
if chainer.is_debug():
assert len(xs) == 2
x, y = xs
z = scale.scale(x, y, axis)
# Forward propagate bias term if given.
if hasattr(self, 'bias'):
return self.bias(z)
else:
return z
示例8: setUp
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def setUp(self):
self.original_debug = chainer.is_debug()
chainer.set_debug(True)
self.one = numpy.array([1], numpy.float32)
self.f = chainer.FunctionNode()
示例9: setUp
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def setUp(self):
self.original_debug = chainer.is_debug()
chainer.set_debug(True)
self.one = numpy.array([1], numpy.float32)
self.f = chainer.Function()
示例10: setUp
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def setUp(self):
self.link = links.EmbedID(2, 2, ignore_label=self.ignore_label)
self.t = numpy.array([self.t_value], dtype=numpy.int32)
self.original_debug = chainer.is_debug()
chainer.set_debug(True)
示例11: setUp
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def setUp(self):
self.x = numpy.arange(10).reshape((2, 5)).astype('f')
self.ind = numpy.array(self.indices, 'i')
self.debug = chainer.is_debug()
chainer.set_debug(True)
示例12: setUp
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def setUp(self):
self.default_debug = chainer.is_debug()
chainer.set_debug(True)
示例13: setUp
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def setUp(self):
self.x = numpy.random.uniform(-1, 1, (1, 2)).astype(numpy.float32)
self.t = numpy.array([self.t_value], dtype=numpy.int32)
self.original_debug = chainer.is_debug()
chainer.set_debug(True)
示例14: setUp
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def setUp(self):
self.default_debug = chainer.is_debug()
chainer.set_debug(True)
self.a_data = numpy.random.uniform(-1, 1, (4, 3, 2))
self.b_data = numpy.random.uniform(-1, 1, (2, 2))
示例15: setUp
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import is_debug [as 别名]
def setUp(self):
self.x = numpy.random.uniform(-1, 1, (2, 2)).astype(numpy.float32)
# `0` is required to avoid NaN
self.t = numpy.array([self.t_value, 0], dtype=numpy.int32)
self.original_debug = chainer.is_debug()
chainer.set_debug(True)