Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
chainer.Variable: Subsampled vector of xs.
chainer.Variable: Subsampled vector of ilens.
"""
logging.info(self.__class__.__name__ + ' input lengths: ' + str(ilens))
# x: utt x frame x dim
xs = F.pad_sequence(xs)
# x: utt x 1 (input channel num) x frame x dim
xs = F.swapaxes(
xs.reshape(xs.shape[0], xs.shape[1], self.in_channel, xs.shape[2] // self.in_channel), 1, 2)
xs = F.relu(self.conv1_1(xs))
xs = F.relu(self.conv1_2(xs))
xs = F.max_pooling_2d(xs, 2, stride=2)
xs = F.relu(self.conv2_1(xs))
xs = F.relu(self.conv2_2(xs))
xs = F.max_pooling_2d(xs, 2, stride=2)
# change ilens accordingly
ilens = self.xp.array(self.xp.ceil(self.xp.array(
ilens, dtype=np.float32) / 2), dtype=np.int32)
ilens = self.xp.array(self.xp.ceil(self.xp.array(
ilens, dtype=np.float32) / 2), dtype=np.int32)
# x: utt_list of frame (remove zeropaded frames) x (input channel num x dim)
xs = F.swapaxes(xs, 1, 2)
xs = xs.reshape(xs.shape[0], xs.shape[1], xs.shape[2] * xs.shape[3])
xs = [xs[i, :ilens[i], :] for i in range(len(ilens))]
def check_forward(self, xs_data):
xs = [chainer.Variable(x) for x in xs_data]
y = functions.stack(xs, axis=self.axis)
if hasattr(numpy, 'stack'):
# run test only with numpy>=1.10
expect = numpy.stack(self.xs, axis=self.axis)
testing.assert_allclose(y.data, expect)
y_data = cuda.to_cpu(y.data)
self.assertEqual(y_data.shape[self.axis], 2)
numpy.testing.assert_array_equal(
y_data.take(0, axis=self.axis), self.xs[0])
numpy.testing.assert_array_equal(
y_data.take(1, axis=self.axis), self.xs[1])
def check_backward(self, x_data):
x = chainer.Variable(x_data)
y = functions.transpose(x, self.axes)
y.grad = y.data
y.backward()
testing.assert_allclose(x.data, x.grad, atol=0, rtol=0)
def __call__(self, x):
x = F.relu(self.bn1(self.conv1(x)))
x = F.max_pooling_2d(x, 2, 2)
x = F.relu(self.bn2(self.conv2(x)))
x = F.max_pooling_2d(x, 2, 2)
return self.fc(x)
def __call__(self, variables):
in_audio, context, nx_step = variables
self.loss = loss = 0
state = self.state
batchsize, sequence = in_audio.shape[0:2]
for i in range(sequence):
h = self.audiofeat(in_audio[:, i])
state, y = self.forward(state, context, h)
loss += F.mean_squared_error(nx_step[:, i], y) # F.mean_squared_error mean_absolute_error
context = y
self.loss = loss
chainer.report({'loss': loss
}, self)
stdout.write('loss={:.04f}\r'.format(float(chainer.cuda.to_cpu(loss.data))))
stdout.flush()
return self.loss
embed (callable): A :func:`~chainer.functions.embed_id` function
or :class:`~chainer.links.EmbedID` link.
xs (list of :class:`~chainer.Variable` or :class:`numpy.ndarray` or \
:class:`cupy.ndarray`): i-th element in the list is an input variable,
which is a :math:`(L_i, )`-shaped int array.
dropout (float): Dropout ratio.
Returns:
list of ~chainer.Variable: Output variables. i-th element in the
list is an output variable, which is a :math:`(L_i, N)`-shaped
float array. :math:`(N)` is the number of dimensions of word embedding.
"""
x_len = [len(x) for x in xs]
x_section = numpy.cumsum(x_len[:-1])
ex = embed(F.concat(xs, axis=0))
ex = F.dropout(ex, ratio=dropout)
exs = F.split_axis(ex, x_section, 0)
return exs
def __call__(self, x):
return functions.unpooling_2d(x, self.ksize, self.stride, self.pad, self.outsize, self.cover_all)
def __init__(self):
super(Vgg, self).__init__(
conv1=F.Convolution2D(3, 64, 3, stride=1, pad=1),
conv2=F.Convolution2D(64, 64, 3, stride=1, pad=1),
conv3=F.Convolution2D(64, 128, 3, stride=1, pad=1),
conv4=F.Convolution2D(128, 128, 3, stride=1, pad=1),
conv5=F.Convolution2D(128, 128, 3, stride=1, pad=1),
conv6=F.Convolution2D(128, 128, 3, stride=1, pad=1),
conv7=F.Convolution2D(128, 128, 3, stride=1, pad=1),
conv8=F.Convolution2D(128, 128, 3, stride=1, pad=1),
conv9=F.Convolution2D(128, 256, 3, stride=1, pad=1),
conv10=F.Convolution2D(256, 256, 3, stride=1, pad=1),
conv11=F.Convolution2D(256, 256, 3, stride=1, pad=1),
conv12=F.Convolution2D(256, 256, 3, stride=1, pad=1),
conv13=F.Convolution2D(256, 256, 3, stride=1, pad=1),
def __call__(self, x, test=False):
# type: (any, bool) -> any
h = x
h = chainer.functions.relu(self.bn1_1(self.conv1_1(h), test=test))
h = chainer.functions.relu(self.bn1_2(self.conv1_2(h), test=test))
h = chainer.functions.relu(self.bn2_1(self.conv2_1(h), test=test))
h = chainer.functions.relu(self.bn2_2(self.conv2_2(h), test=test))
h = chainer.functions.relu(self.bn3_1(self.conv3_1(h), test=test))
h = chainer.functions.relu(self.bn3_2(self.conv3_2(h), test=test))
return h
super(AirUnit, self).__init__()
self.resize_identity = (in_channels != out_channels) or (stride != 1)
with self.init_scope():
self.body = AirBottleneck(
in_channels=in_channels,
out_channels=out_channels,
stride=stride,
ratio=ratio)
if self.resize_identity:
self.identity_conv = conv1x1_block(
in_channels=in_channels,
out_channels=out_channels,
stride=stride,
activation=None)
self.activ = F.relu