本文整理汇总了Python中chainer.ChainList方法的典型用法代码示例。如果您正苦于以下问题:Python chainer.ChainList方法的具体用法?Python chainer.ChainList怎么用?Python chainer.ChainList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chainer
的用法示例。
在下文中一共展示了chainer.ChainList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_chainlist
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def test_chainlist(self):
ch = chainer.ChainList(
chainer.links.Linear(3, 4),
chainer.links.Linear(5),
chainer.links.PReLU(),
)
self.assertEqual(
names_of_links(ch),
{'/0', '/1', '/2'})
to_factorized_noisy(ch)
self.assertEqual(
names_of_links(ch),
{
'/0', '/0/mu', '/0/sigma',
'/1', '/1/mu', '/1/sigma', '/2'})
示例2: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self, n_actions, n_input_channels=4,
activation=F.relu, bias=0.1):
self.n_actions = n_actions
self.n_input_channels = n_input_channels
self.activation = activation
super().__init__()
with self.init_scope():
self.conv_layers = chainer.ChainList(
L.Convolution2D(n_input_channels, 32, 8, stride=4,
initial_bias=bias),
L.Convolution2D(32, 64, 4, stride=2, initial_bias=bias),
L.Convolution2D(64, 64, 3, stride=1, initial_bias=bias))
self.a_stream = MLP(3136, n_actions, [512])
self.v_stream = MLP(3136, 1, [512])
示例3: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self, ch=512):
super().__init__()
self.ch = ch
with self.init_scope():
self.l = chainer.ChainList(
EqualizedLinear(ch, ch),
LinkLeakyRelu(),
EqualizedLinear(ch, ch),
LinkLeakyRelu(),
EqualizedLinear(ch, ch),
LinkLeakyRelu(),
EqualizedLinear(ch, ch),
LinkLeakyRelu(),
EqualizedLinear(ch, ch),
LinkLeakyRelu(),
EqualizedLinear(ch, ch),
LinkLeakyRelu(),
EqualizedLinear(ch, ch),
LinkLeakyRelu(),
EqualizedLinear(ch, ch),
LinkLeakyRelu(),
)
self.ln = len(self.l)
示例4: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self, base, n_base_output, scales):
super(FPN, self).__init__()
with self.init_scope():
self.base = base
self.inner = chainer.ChainList()
self.outer = chainer.ChainList()
init = {'initialW': initializers.GlorotNormal()}
for _ in range(n_base_output):
self.inner.append(L.Convolution2D(256, 1, **init))
self.outer.append(L.Convolution2D(256, 3, pad=1, **init))
self.scales = scales
# hacks
self.n_base_output = n_base_output
self.n_base_output_minus1 = n_base_output - 1
self.scales_minus_n_base_output = len(scales) - n_base_output
示例5: setUp
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def setUp(self):
self.l1 = chainer.Link()
with self.l1.init_scope():
self.l1.x = chainer.Parameter(shape=(2, 3))
self.l1.y = chainer.Parameter()
self.l2 = chainer.Link()
with self.l2.init_scope():
self.l2.x = chainer.Parameter(shape=2)
self.l3 = chainer.Link()
with self.l3.init_scope():
self.l3.x = chainer.Parameter(shape=3)
self.l4 = chainer.Link()
self.l5 = chainer.Link()
self.l6 = chainer.Link()
self.c1 = chainer.ChainList(self.l1)
self.c1.add_link(self.l2)
self.c2 = chainer.ChainList(self.c1)
self.c2.append(self.l3)
self.c3 = chainer.ChainList(self.l4)
示例6: test_copyparams
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def test_copyparams(self):
l1 = chainer.Link()
with l1.init_scope():
l1.x = chainer.Parameter(shape=(2, 3))
l1.y = chainer.Parameter()
l2 = chainer.Link()
with l2.init_scope():
l2.x = chainer.Parameter(shape=2)
l3 = chainer.Link()
with l3.init_scope():
l3.x = chainer.Parameter(shape=3)
c1 = chainer.ChainList(l1, l2)
c2 = chainer.ChainList(c1, l3)
l1.x.data.fill(0)
l2.x.data.fill(1)
l3.x.data.fill(2)
self.c2.copyparams(c2)
numpy.testing.assert_array_equal(self.l1.x.data, l1.x.data)
numpy.testing.assert_array_equal(self.l2.x.data, l2.x.data)
numpy.testing.assert_array_equal(self.l3.x.data, l3.x.data)
示例7: test_serialize
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def test_serialize(self):
l1 = chainer.Link()
with l1.init_scope():
l1.y = chainer.Parameter(shape=(1, 1))
l2 = chainer.Link()
with l2.init_scope():
l2.x = chainer.Parameter(0, 2)
c1 = chainer.ChainList(l1, l2)
mocks = {'0': mock.MagicMock(), '1': mock.MagicMock()}
serializer = mock.MagicMock()
serializer.__getitem__.side_effect = lambda k: mocks[k]
serializer.return_value = None
mocks['0'].return_value = None
mocks['1'].return_value = None
c1.serialize(serializer)
self.assertEqual(serializer.call_count, 0)
self.assertEqual(serializer.__getitem__.call_count, 2)
serializer.__getitem__.assert_any_call('0')
serializer.__getitem__.assert_any_call('1')
mocks['0'].assert_called_with('y', l1.y.data)
mocks['1'].assert_called_with('x', l2.x.data)
示例8: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self, n_in_node, edge_types, msg_hid, msg_out, n_hid, do_prob=0., skip_first=False):
super(MLPDecoder, self).__init__()
w = chainer.initializers.LeCunUniform(scale=(1. / np.sqrt(3)))
b = self._bias_initializer
with self.init_scope():
self.msg_fc1 = chainer.ChainList(
*[L.Linear(2 * n_in_node, msg_hid) for _ in range(edge_types)])
self.msg_fc2 = chainer.ChainList(
*[L.Linear(msg_hid, msg_out) for _ in range(edge_types)])
self.out_fc1 = L.Linear(n_in_node + msg_out, n_hid, initialW=w, initial_bias=b)
self.out_fc2 = L.Linear(n_hid, n_hid, initialW=w, initial_bias=b)
self.out_fc3 = L.Linear(n_hid, n_in_node, initialW=w, initial_bias=b)
self.msg_out_shape = msg_out
self.skip_first_edge_type = skip_first
logger = logging.getLogger(__name__)
logger.info('Using learned interaction net decoder.')
self.dropout_prob = do_prob
示例9: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self, n_in_node, edge_types, n_hid, do_prob=0., skip_first=False):
super(RNNDecoder, self).__init__()
self.msg_fc1 = chainer.ChainList(
[L.Linear(2 * n_hid, n_hid) for _ in range(edge_types)])
self.msg_fc2 = chainer.ChainList(
[L.Linear(n_hid, n_hid) for _ in range(edge_types)])
self.msg_out_shape = n_hid
self.skip_first_edge_type = skip_first
self.hidden_r = L.Linear(n_hid, n_hid, bias=False)
self.hidden_i = L.Linear(n_hid, n_hid, bias=False)
self.hidden_h = L.Linear(n_hid, n_hid, bias=False)
self.input_r = L.Linear(n_in_node, n_hid, bias=True)
self.input_i = L.Linear(n_in_node, n_hid, bias=True)
self.input_n = L.Linear(n_in_node, n_hid, bias=True)
self.out_fc1 = L.Linear(n_hid, n_hid)
self.out_fc2 = L.Linear(n_hid, n_hid)
self.out_fc3 = L.Linear(n_hid, n_in_node)
print('Using learned recurrent interaction net decoder.')
self.dropout_prob = do_prob
示例10: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self,
input_dim,
num_layers=1,
activation=F.relu):
super(Highway, self).__init__()
self._input_dim = input_dim
with self.init_scope():
self._layers = chainer.ChainList(*[L.Linear(input_dim, input_dim * 2)
for _ in range(num_layers)])
self._activation = activation
for layer in self._layers:
# We should bias the highway layer to just carry its input forward. We do that by
# setting the bias on `B(x)` to be positive, because that means `g` will be biased to
# be high, to we will carry the input forward. The bias on `B(x)` is the second half
# of the bias vector in each Linear layer.
layer.b.data[input_dim:] = 1.
示例11: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(
self, n_class, aspect_ratios,
initialW=None, initial_bias=None):
self.n_class = n_class
self.aspect_ratios = aspect_ratios
super(Multibox, self).__init__()
with self.init_scope():
self.loc = chainer.ChainList()
self.conf = chainer.ChainList()
if initialW is None:
initialW = initializers.LeCunUniform()
if initial_bias is None:
initial_bias = initializers.Zero()
init = {'initialW': initialW, 'initial_bias': initial_bias}
for ar in aspect_ratios:
n = (len(ar) + 1) * 2
self.loc.add_link(L.Convolution2D(n * 4, 3, pad=1, **init))
self.conf.add_link(L.Convolution2D(
n * self.n_class, 3, pad=1, **init))
示例12: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self, n_vocab, n_layers, n_units, typ="lstm"):
super(RNNLM, self).__init__()
with self.init_scope():
self.embed = DL.EmbedID(n_vocab, n_units)
self.rnn = (
chainer.ChainList(
*[L.StatelessLSTM(n_units, n_units) for _ in range(n_layers)]
)
if typ == "lstm"
else chainer.ChainList(
*[L.StatelessGRU(n_units, n_units) for _ in range(n_layers)]
)
)
self.lo = L.Linear(n_units, n_vocab)
for param in self.params():
param.data[...] = np.random.uniform(-0.1, 0.1, param.data.shape)
self.n_layers = n_layers
self.n_units = n_units
self.typ = typ
示例13: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self, use_reconstruction=False):
super(CapsNet, self).__init__()
self.n_iterations = 3 # dynamic routing
self.n_grids = 6 # grid width of primary capsules layer
self.n_raw_grids = self.n_grids
self.use_reconstruction = use_reconstruction
with self.init_scope():
self.conv1 = L.Convolution2D(1, 256, ksize=9, stride=1,
initialW=init)
self.conv2 = L.Convolution2D(256, 32 * 8, ksize=9, stride=2,
initialW=init)
self.Ws = chainer.ChainList(
*[L.Convolution2D(8, 16 * 10, ksize=1, stride=1, initialW=init)
for i in range(32)])
self.fc1 = L.Linear(16 * 10, 512, initialW=init)
self.fc2 = L.Linear(512, 1024, initialW=init)
self.fc3 = L.Linear(1024, 784, initialW=init)
_count_params(self, n_grids=self.n_grids)
self.results = {'N': 0., 'loss': [], 'correct': [],
'cls_loss': [], 'rcn_loss': []}
示例14: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self, out_dim, in_dim=3, max_level=10, dropout_ratio=-1,
use_bn=True, compute_accuracy=True, cdim=3):
super(KDNetCls, self).__init__()
if max_level <= 10:
# depth 10
ch_list = [in_dim] + [32, 64, 64, 128, 128, 256, 256,
512, 512, 128]
ch_list = ch_list[:max_level + 1]
elif max_level <= 15:
# depth 15
ch_list = [in_dim] + [16, 16, 32, 32, 64, 64, 128, 128, 256, 256,
512, 512, 1024, 1024, 128]
ch_list = ch_list[:max_level + 1]
else:
raise NotImplementedError('depth {} is not implemented yet'
.format(max_level))
with self.init_scope():
self.kdconvs = chainer.ChainList(
*[KDConv(ch_list[i], ch_list[i+1], use_bn=use_bn, cdim=cdim)
for i in range(len(ch_list)-1)])
self.linear = links.Linear(ch_list[-1], out_dim)
self.compute_accuracy = compute_accuracy
self.max_level = max_level
self.dropout_ratio = dropout_ratio
示例15: __init__
# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import ChainList [as 别名]
def __init__(self, mlp, mlp2, in_channels=None, use_bn=True,
activation=functions.relu, residual=False):
# k is number of sampled point (num_region)
super(SetAbstractionGroupAllModule, self).__init__()
# Feature Extractor channel list
assert isinstance(mlp, list)
fe_ch_list = [in_channels] + mlp
# Head channel list
if mlp2 is None:
mlp2 = []
assert isinstance(mlp2, list)
head_ch_list = [mlp[-1]] + mlp2
with self.init_scope():
self.sampling_grouping = SamplingGroupingAllModule()
self.feature_extractor_list = chainer.ChainList(
*[ConvBlock(fe_ch_list[i], fe_ch_list[i+1], ksize=1,
use_bn=use_bn, activation=activation,
residual=residual
) for i in range(len(mlp))])
self.head_list = chainer.ChainList(
*[ConvBlock(head_ch_list[i], head_ch_list[i + 1], ksize=1,
use_bn=use_bn, activation=activation,
residual=residual
) for i in range(len(mlp2))])
self.use_bn = use_bn