microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.5k stars 4.29k forks source link

What is the "RowStack" method for CNTK python API #2708

Closed min6434 closed 6 years ago

min6434 commented 6 years ago

I want to slice my input and group them and combine later. I used cntk.ops.slice() method to slice the input however I cannot finde RowStack method in the python API. [https://github.com/Microsoft/CNTK/issues/668] I tried combine method but I got runtime error like this.

RuntimeError: A Function instance 'Composite(Combine): Input('Input3', [#], [68]) -> Output('Block4305_Output_0', [#], [6]), Output('Block4494_Output_0', [#], [6]), Output('Block4683_Output_0', [#], [6]), Output('Block4872_Output_0', [#], [6]), Output('Block4949_Output_0', [#], [2])' with more than one output cannot be implicitly converted to a Variable.

Here is my code

from cntk.ops import slice as slice_cntk from cntk.ops import combine

    def get_model(self):
        "Get classification model"

        input_m = slice_cntk(self.feature, 0, 0, self.slice_list[0])
        input_d = slice_cntk(self.feature, 0, self.slice_list[0], self.slice_list[1])
        input_h = slice_cntk(self.feature, 0, self.slice_list[1], self.slice_list[2])
        input_sum = slice_cntk(self.feature, 0, self.slice_list[2], self.slice_list[3])
        input_acts = slice_cntk(self.feature, 0, self.slice_list[3], self.slice_list[4])

        with default_options(init=he_uniform(), activation=relu):
            modelM = Sequential([For(range(self.depth - 1), lambda: [BatchNormalization(), Dense(self.input_dim)]),
                                Dense(self.num_class)])
            modelD = Sequential([For(range(self.depth - 1), lambda: [BatchNormalization(), Dense(self.input_dim)]),
                                Dense(self.num_class)])
            modelH = Sequential([For(range(self.depth - 1), lambda: [BatchNormalization(), Dense(self.input_dim)]),
                                Dense(self.num_class)])
            modelAct = Sequential([For(range(self.depth - 1), lambda: [BatchNormalization(), Dense(self.input_dim)]),
                                Dense(self.num_class)])
            modelSum = Dense(2)
            model3 =  Sequential([For(range(self.depth - 1), lambda: [BatchNormalization(), Dense(4 * self.num_class + 2)]),
                                Dense(self.num_class, init=he_uniform(), activation=None)])

        model_m = modelM(input_m)
        model_d = modelD(input_d)
        model_h = modelH(input_h)
        model_acts = modelAct(input_acts)
        model_sum = modelSum(input_sum)

        new_feature = combine([model_m, model_d, model_h, model_acts, model_sum])
        model_comb = model3(new_feature)
bencherian commented 6 years ago

You can use cntk.ops.splice and specify the appropriate axis along which you wish to combine your slices.

min6434 commented 6 years ago

So I get the error because I didn't specify the axis to combine. I will specify appropriate axis then . Thank you

min6434 commented 6 years ago

I found splice method. I works fine.