當前位置: 首頁>>代碼示例>>Python>>正文


Python functions.vstack方法代碼示例

本文整理匯總了Python中chainer.functions.vstack方法的典型用法代碼示例。如果您正苦於以下問題:Python functions.vstack方法的具體用法?Python functions.vstack怎麽用?Python functions.vstack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在chainer.functions的用法示例。


在下文中一共展示了functions.vstack方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: forward

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def forward(self, xs, ilens):
        '''BLSTM forward (the modified version)

        :param xs:
        :param ilens:
        :return:
        '''
        logging.info(self.__class__.__name__ + ' input lengths: ' + str(ilens))
        # need to move ilens to cpu
        ilens = cuda.to_cpu(ilens)
        hy, cy, ys = self.nblstm(None, None, xs)
        ys = self.l_last(F.vstack(ys))  # (sum _utt frame_utt) x dim
        xs = F.split_axis(ys, np.cumsum(ilens[:-1]), axis=0)
        del hy, cy

        # final tanh operation
        xs = F.split_axis(F.tanh(F.vstack(xs)), np.cumsum(ilens[:-1]), axis=0)

        # EDIT(hamaji): Unnecessary, as `force_tuple` is True by default.
        # # 1 utterance case, it becomes an array, so need to make a utt tuple
        # if not isinstance(xs, tuple):
        #     xs = [xs]

        return xs, ilens  # x: utt list of frame x dim 
開發者ID:pfnet-research,項目名稱:chainer-compiler,代碼行數:26,代碼來源:EspNet_BLSTM.py

示例2: original

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def original(self, xs, ilens):
        '''BLSTM forward (the original implementation)

        :param xs:
        :param ilens:
        :return:
        '''
        logging.info(self.__class__.__name__ + ' input lengths: ' + str(ilens))
        # need to move ilens to cpu
        ilens = cuda.to_cpu(ilens)
        hy, cy, ys = self.nblstm(None, None, xs)
        ys = self.l_last(F.vstack(ys))  # (sum _utt frame_utt) x dim
        xs = F.split_axis(ys, np.cumsum(ilens[:-1]), axis=0)
        del hy, cy

        # final tanh operation
        xs = F.split_axis(F.tanh(F.vstack(xs)), np.cumsum(ilens[:-1]), axis=0)

        # 1 utterance case, it becomes an array, so need to make a utt tuple
        if not isinstance(xs, tuple):
            xs = [xs]

        return xs, ilens  # x: utt list of frame x dim 
開發者ID:pfnet-research,項目名稱:chainer-compiler,代碼行數:25,代碼來源:EspNet_BLSTM.py

示例3: forward

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def forward(self, xs, ilens):
        '''BLSTM forward (the modified version)

        :param xs:
        :param ilens:
        :return:
        '''
        logging.info(self.__class__.__name__ + ' input lengths: ' + str(ilens))
        # need to move ilens to cpu
        ilens = cuda.to_cpu(ilens)
        hy, cy, ys = self.nblstm(None, None, xs)
        ys = self.l_last(F.vstack(ys))  # (sum _utt frame_utt) x dim
        xs = F.split_axis(ys, np.cumsum(ilens[:-1]), 0)
        del hy, cy

        # final tanh operation
        xs = F.split_axis(F.tanh(F.vstack(xs)), np.cumsum(ilens[:-1]), 0)

        # EDIT(hamaji): Unnecessary, as `force_tuple` is True by default.
        # # 1 utterance case, it becomes an array, so need to make a utt tuple
        # if not isinstance(xs, tuple):
        #     xs = [xs]

        return xs, ilens  # x: utt list of frame x dim 
開發者ID:pfnet-research,項目名稱:chainer-compiler,代碼行數:26,代碼來源:EspNet_BLSTM.py

示例4: test_vstack

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def test_vstack(self):
        class Test():
            def forward(self):
                F.vstack([np.zeros((1, 3, 4)), np.zeros((2, 3, 4))])

        id2type = generate_id2type_from_forward(Test(), ())

        self.assertEqual(str(id2type[1]), "class Test -> NoneType")	# FunctionDef forward (line 1)
        self.assertEqual(str(id2type[5]), "NoneType")	# Expr
        self.assertEqual(str(id2type[6]), "Variable(float64, (None, 3, 4))")	# Call F.vstack([np.zeros((1, 3, 4)), np.zeros((2, 3, 4))]) (line 2)
        self.assertEqual(str(id2type[11]), "ndarray(float64, (None, 3, 4)) list")	# List [np.zeros((1, 3, 4)), np.zeros((2, 3, 4))] (line 2)
        self.assertEqual(str(id2type[12]), "ndarray(float64, (1, 3, 4))")	# Call np.zeros((1, 3, 4)) (line 2)
        self.assertEqual(str(id2type[17]), "(int, int, int)")	# Tuple (1, 3, 4) (line 2)
        self.assertEqual(str(id2type[18]), "int")	# Num 1 (line 2)
        self.assertEqual(str(id2type[19]), "int")	# Num 3 (line 2)
        self.assertEqual(str(id2type[20]), "int")	# Num 4 (line 2)
        self.assertEqual(str(id2type[22]), "ndarray(float64, (2, 3, 4))")	# Call np.zeros((2, 3, 4)) (line 2)
        self.assertEqual(str(id2type[27]), "(int, int, int)")	# Tuple (2, 3, 4) (line 2)
        self.assertEqual(str(id2type[28]), "int")	# Num 2 (line 2)
        self.assertEqual(str(id2type[29]), "int")	# Num 3 (line 2)
        self.assertEqual(str(id2type[30]), "int")	# Num 4 (line 2) 
開發者ID:pfnet-research,項目名稱:chainer-compiler,代碼行數:23,代碼來源:ExtFunctions_test.py

示例5: forward

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def forward(self, xs, hs=None, activation=None):
        if hs is not None:
            hx1, cx1, hx_emb, cx_emb = hs
        else:
            hx1 = cx1 = hx_emb = cx_emb = None
        # forward to LSTM layers
        hy_emb, cy_emb, ems = self.bi_lstm_emb(hx_emb, cx_emb, xs)
        hy1, cy1, ys = self.bi_lstm1(hx1, cx1, ems)
        # main branch
        ys_stack = F.vstack(ys)
        ys = self.linear1(ys_stack)
        if activation:
            ys = activation(ys)
        ilens = [x.shape[0] for x in xs]
        ys = F.split_axis(ys, np.cumsum(ilens[:-1]), axis=0)
        # embedding branch
        ems_stack = F.vstack(ems)
        ems = F.normalize(F.tanh(self.linear2(ems_stack)))
        ems = F.split_axis(ems, np.cumsum(ilens[:-1]), axis=0)

        if not isinstance(ys, tuple):
            ys = [ys]
            ems = [ems]
        return [hy1, cy1, hy_emb, cy_emb], ys, ems 
開發者ID:hitachi-speech,項目名稱:EEND,代碼行數:26,代碼來源:models.py

示例6: forward

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def forward(self, x, y):
        y1 = F.vstack((x, y))
        return y1 
開發者ID:pfnet-research,項目名稱:chainer-compiler,代碼行數:5,代碼來源:Vstack.py

示例7: forward_expected

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def forward_expected(self, inputs):
        x = list(inputs)
        y_expect = numpy.vstack(x)
        return y_expect, 
開發者ID:chainer,項目名稱:chainer,代碼行數:6,代碼來源:test_vstack.py

示例8: forward

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def forward(self, inputs, device):
        x = list(inputs)
        y = functions.vstack(x)
        return y, 
開發者ID:chainer,項目名稱:chainer,代碼行數:6,代碼來源:test_vstack.py

示例9: check_value_check

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def check_value_check(self):
        if self.valid:
            # Check if it throws nothing
            functions.vstack(self.xs)
        else:
            with pytest.raises(type_check.InvalidType):
                functions.vstack(self.xs) 
開發者ID:chainer,項目名稱:chainer,代碼行數:9,代碼來源:test_vstack.py

示例10: __call__

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def __call__(self, xs, ts):
        hy, cy, ys = self.lstm(None, None, xs)
        ys = F.relu(self.ll1(F.vstack(ys)))
        del hy, cy
        ys = self.ll2(ys)
        loss = F.mean_squared_error(ys, ts)
        return loss

    # This is used during testing 
開發者ID:sas91,項目名稱:jhu-neural-wpe,代碼行數:11,代碼來源:dnn_model.py

示例11: predict

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def predict(self, xs):
        hy, cy, ys = self.lstm(None, None, xs)
        ys = F.relu(self.ll1(F.vstack(ys)))
        del hy, cy
        ys = self.ll2(ys)
        return ys 
開發者ID:sas91,項目名稱:jhu-neural-wpe,代碼行數:8,代碼來源:dnn_model.py

示例12: __call__

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def __call__(self, xs, ilens):
        """RNNP forward.

        Args:
            xs (chainer.Variable): Batch of padded charactor ids. (B, Tmax)
            ilens (chainer.Variable): Batch of length of each input batch. (B,)

        Returns:
            xs (chainer.Variable):subsampled vector of xs.
            chainer.Variable: Subsampled vector of ilens.

        """
        logging.info(self.__class__.__name__ + " input lengths: " + str(ilens))

        for layer in six.moves.range(self.elayers):
            if "lstm" in self.typ:
                _, _, ys = self[self.rnn_label + str(layer)](None, None, xs)
            else:
                _, ys = self[self.rnn_label + str(layer)](None, xs)
            # ys: utt list of frame x cdim x 2 (2: means bidirectional)
            # TODO(watanabe) replace subsample and FC layer with CNN
            ys, ilens = _subsamplex(ys, self.subsample[layer + 1])
            # (sum _utt frame_utt) x dim
            ys = self["bt" + str(layer)](F.vstack(ys))
            xs = F.split_axis(ys, np.cumsum(ilens[:-1]), axis=0)

        # final tanh operation
        xs = F.split_axis(F.tanh(F.vstack(xs)), np.cumsum(ilens[:-1]), axis=0)

        # 1 utterance case, it becomes an array, so need to make a utt tuple
        if not isinstance(xs, tuple):
            xs = [xs]

        return xs, ilens  # x: utt list of frame x dim 
開發者ID:espnet,項目名稱:espnet,代碼行數:36,代碼來源:encoders.py

示例13: lifted_struct_loss

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def lifted_struct_loss(f_a, f_p, alpha=1.0):
    """Lifted struct loss function.

    Args:
        f_a (~chainer.Variable): Feature vectors as anchor examples.
            All examples must be different classes each other.
        f_p (~chainer.Variable): Positive examples corresponding to f_a.
            Each example must be the same class for each example in f_a.
        alpha (~float): The margin parameter.

    Returns:
        ~chainer.Variable: Loss value.

    See: `Deep Metric Learning via Lifted Structured Feature Embedding \
        <http://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/\
        Song_Deep_Metric_Learning_CVPR_2016_paper.pdf>`_

    """
    assert f_a.shape == f_p.shape, 'f_a and f_p must have same shape.'
    n = 2 * f_a.shape[0]  # use shape[0] due to len(Variable) returns its size
    f = F.vstack((f_a, f_p))
    D_sq = squared_distance_matrix(f)

    pairs_p = np.arange(n).reshape(2, -1)  # indexes of positive pairs
    row = []
    col = []
    for i, j in pairs_p.T:
        row.append([i] * (n - 2) + [j] * (n - 2))
        col.append(np.tile(np.delete(np.arange(n), (i, j)), 2))
    row = np.ravel(row)
    col = np.ravel(col)
    pairs_n = np.vstack((row, col))

    distances_p = F.sqrt(D_sq[pairs_p[0], pairs_p[1]])
    distances_n = F.sqrt(D_sq[pairs_n[0], pairs_n[1]])
    distances_n = distances_n.reshape((n // 2, -1))
    loss_ij = F.logsumexp(alpha - distances_n, axis=1) + distances_p
    return F.sum(F.relu(loss_ij) ** 2) / n 
開發者ID:ronekko,項目名稱:deep_metric_learning,代碼行數:40,代碼來源:lifted_struct_loss.py

示例14: test_output

# 需要導入模塊: from chainer import functions [as 別名]
# 或者: from chainer.functions import vstack [as 別名]
def test_output(self):
        class Model(chainer.Chain):
            def __init__(self):
                super().__init__()
                with self.init_scope():
                    self.l1 = L.Convolution2D(None, 16, 5, 1, 2)
                    self.l2 = L.Convolution2D(16, 8, 5, 1, 2)

            def forward(self, *xs, **kwxs):
                if kwxs:
                    h = F.vstack(list(kwxs.values()))
                elif len(xs) > 1:
                    h = F.vstack(xs)
                else:
                    h = xs[0]
                h2 = self.l1(h)
                h3 = F.relu(h2)
                h4 = self.l2(h3)
                return F.relu(h4)

        def check_input_shape(onnx_model, path):
            assert [v.type.tensor_type.shape.dim[0] == 'b' for
                    v in onnx_model.graph.input]
            assert [v.type.tensor_type.shape.dim[0] == 'b' for
                    v in onnx_model.graph.output]

        if isinstance(self.x_shape, tuple):
            xs = np.zeros(self.x_shape, dtype=np.float32)
        elif isinstance(self.x_shape, list):
            xs = tuple(
                np.zeros(shape, dtype=np.float32) for shape in self.x_shape)
        else:
            assert isinstance(self.x_shape, dict)
            xs = {k: np.zeros(shape, dtype=np.float32) for
                  k, shape in self.x_shape.items()}

        name = 'customized_input_shape'
        if hasattr(self, 'condition'):
            name += '_{}'.format(self.condition)

        self.expect(
            Model(), xs, name=name, input_shapes=self.shape_option,
            custom_model_test_func=check_input_shape) 
開發者ID:chainer,項目名稱:chainer,代碼行數:45,代碼來源:test_inout.py


注:本文中的chainer.functions.vstack方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。