本文整理汇总了Python中chainer.functions.identity方法的典型用法代码示例。如果您正苦于以下问题:Python functions.identity方法的具体用法?Python functions.identity怎么用?Python functions.identity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chainer.functions
的用法示例。
在下文中一共展示了functions.identity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: darts_skip_connection
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def darts_skip_connection(channels,
stride):
"""
DARTS specific skip connection layer.
Parameters:
----------
channels : int
Number of input/output channels.
stride : int or tuple/list of 2 int
Stride of the convolution.
"""
assert (channels > 0)
if stride == 1:
return F.identity
else:
assert (stride == 2)
return DartsReduceBranch(
in_channels=channels,
out_channels=channels,
stride=stride)
示例2: __init__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def __init__(self, out_dim, hidden_channels=16,
n_update_layers=4, n_atom_types=MAX_ATOMIC_NUM,
dropout_ratio=0.5, concat_hidden=False,
weight_tying=True, activation=functions.identity,
n_edge_types=4, with_gwm=True):
update_kwargs = {'dropout_ratio': dropout_ratio}
readout_kwargs = {'activation': activation,
'activation_agg': activation}
super(GIN_GWM, self).__init__(
update_layer=GINUpdate, readout_layer=GGNNReadout,
out_dim=out_dim, hidden_channels=hidden_channels,
n_update_layers=n_update_layers, n_atom_types=n_atom_types,
concat_hidden=concat_hidden, weight_tying=weight_tying,
n_edge_types=n_edge_types, with_gwm=with_gwm,
update_kwargs=update_kwargs, readout_kwargs=readout_kwargs
)
示例3: __init__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def __init__(self, out_dim, in_channels=None, nobias=False,
activation=functions.identity,
activation_agg=functions.identity,
concat_n_info=False):
super(ScatterGGNNReadout, self).__init__()
self.concat_n_info = concat_n_info
if self.concat_n_info:
out_dim -= 1
with self.init_scope():
self.i_layer = chainer.links.Linear(
in_channels, out_dim, nobias=nobias)
self.j_layer = chainer.links.Linear(
in_channels, out_dim, nobias=nobias)
self.out_dim = out_dim
self.in_channels = in_channels
self.nobias = nobias
self.activation = activation
self.activation_agg = activation_agg
示例4: __call__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def __call__(self, x):
if self.squeeze:
identity = self.c_squeeze(x)
elif self.resize_identity:
identity = self.identity_conv(x)
else:
identity = x
x = self.body(x)
x = x + identity
return x
示例5: __call__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def __call__(self, x):
if self.resize_identity:
identity = self.identity_conv(x)
else:
identity = F.identity(x)
x = self.body(x)
x = x + identity
return x
示例6: test_backward
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def test_backward(self):
x = chainer.Variable(numpy.array([1]), name='x')
y1 = F.identity(x)
y1.name = 'y1'
y2 = F.identity(x)
y2.name = 'y2'
z = y1 + y2
z.name = 'z'
z.grad = numpy.array([1])
z.backward(retain_grad=True)
self.assertEqual(y1.grad[0], 1)
self.assertEqual(y2.grad[0], 1)
self.assertEqual(x.grad[0], 2)
示例7: test_backward_no_grad_required
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def test_backward_no_grad_required(self):
class DummyId(chainer.functions.math.identity.Identity):
def backward(self, a, b):
raise Exception('backward should not be called on inputs that '
'do not require grads')
x = chainer.Variable(self.x)
y1, y2 = DummyId().apply((x, x))
x.node._requires_grad = False
y1.backward()
示例8: test_raise
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def test_raise(self):
x = np.array([1], np.float32)
x = chainer.Variable(x)
y = F.identity(x)
y.grad = np.array([np.nan], np.float32)
with pytest.raises(RuntimeError):
y.backward()
示例9: test_int
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def test_int(self):
x = np.array([1], np.int)
x = chainer.Variable(x)
y = F.identity(x)
y.grad = np.array([0], np.int)
y.backward()
示例10: test_raise_double_backprop_2
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def test_raise_double_backprop_2(self):
x = chainer.Variable(np.array(42, np.float32))
z = F.identity(x) # new style
y = IdentityFunction()(z) # old style
y.backward(enable_double_backprop=True)
with pytest.raises(RuntimeError):
x.grad_var.backward()
示例11: test_grad_raise_double_backprop_2
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def test_grad_raise_double_backprop_2(self):
x = chainer.Variable(np.array([42], np.float32))
z = F.identity(x) # new style
y = IdentityFunction()(z) # old style
with testing.assert_warns(DeprecationWarning):
y.backward(enable_double_backprop=True)
with pytest.raises(RuntimeError):
chainer.grad([x.grad_var], [y.grad_var])
示例12: forward
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def forward(self, x):
y0 = F.identity(x)
y10 = self.f10.apply((y0,))
y11 = self.f11.apply((y0,))
y12 = self.f12.apply((y0,))
y = self.f2.apply((y10[0], y11[0], y12[0]))
return y
示例13: get_activation
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def get_activation(activation_string):
"""Maps a string to a Python function, e.g., "relu" => `F.relu`.
Args:
activation_string: String name of the activation function.
Returns:
A Python function corresponding to the activation function. If
`activation_string` is None, empty, or "linear", this will return F.identity.
If `activation_string` is not a string, it will return `activation_string`.
Raises:
ValueError: The `activation_string` does not correspond to a known
activation.
"""
# We assume that anything that"s not a string is already an activation
# function, so we just return it.
if not isinstance(activation_string, six.string_types):
return activation_string
if not activation_string:
return F.identity
act = activation_string.lower()
if act == "linear":
return F.identity
elif act == "relu":
return F.relu
elif act == "gelu":
return gelu
elif act == "tanh":
return F.tanh
else:
raise ValueError("Unsupported activation: %s" % act)
示例14: __init__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def __init__(self, in_channels, depthlist, stride=1, dilate=1,
skip_type='conv', activ_first=True, bn_kwargs={},
dw_activ_list=[None, None, None],
pw_activ_list=[F.relu, F.relu, None]):
super(XceptionBlock, self).__init__()
self.skip_type = skip_type
self.activ_first = activ_first
self.separable2_activ = pw_activ_list[1]
with self.init_scope():
self.separable1 = SeparableConv2DBNActiv(
in_channels, depthlist[0], 3, 1,
dilate, dilate, nobias=True, bn_kwargs=bn_kwargs,
dw_activ=dw_activ_list[0], pw_activ=pw_activ_list[0])
self.separable2 = SeparableConv2DBNActiv(
depthlist[0], depthlist[1], 3, 1,
dilate, dilate, nobias=True, bn_kwargs=bn_kwargs,
dw_activ=dw_activ_list[1], pw_activ=F.identity)
self.separable3 = SeparableConv2DBNActiv(
depthlist[1], depthlist[2], 3, stride,
dilate, dilate, nobias=True, bn_kwargs=bn_kwargs,
dw_activ=dw_activ_list[2], pw_activ=pw_activ_list[2])
if skip_type == 'conv':
self.conv = Conv2DBNActiv(
in_channels, depthlist[2], 1, activ=F.identity,
nobias=True, stride=stride, bn_kwargs=bn_kwargs)
示例15: __init__
# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import identity [as 别名]
def __init__(self, in_channels, out_channels, ksize,
stride=1, pad=0, dilate=1, nobias=False,
dw_initialW=None, pw_initialW=None,
dw_initial_bias=None, pw_initial_bias=None,
dw_activ=identity, pw_activ=relu, bn_kwargs={}):
self.dw_activ = identity if dw_activ is None else dw_activ
self.pw_activ = identity if pw_activ is None else pw_activ
super(SeparableConv2DBNActiv, self).__init__()
with self.init_scope():
self.depthwise = Convolution2D(
in_channels, in_channels, ksize=ksize, stride=stride,
pad=pad, dilate=dilate, groups=in_channels,
nobias=nobias, initialW=dw_initialW)
self.pointwise = Convolution2D(
in_channels, out_channels, 1,
nobias=nobias, initialW=pw_initialW)
if 'comm' in bn_kwargs:
self.dw_bn = MultiNodeBatchNormalization(
out_channels, **bn_kwargs)
self.pw_bn = MultiNodeBatchNormalization(
out_channels, **bn_kwargs)
else:
self.dw_bn = BatchNormalization(in_channels, **bn_kwargs)
self.pw_bn = BatchNormalization(out_channels, **bn_kwargs)