Total Complexity | 4 |
Total Lines | 23 |
Duplicated Lines | 0 % |
Changes | 6 | ||
Bugs | 0 | Features | 0 |
1 | import theano.tensor as T |
||
5 | class Concatenate(NeuralLayer): |
||
6 | """ |
||
7 | Concatenate two tensors. |
||
8 | They should have identical dimensions except the last one. |
||
9 | """ |
||
10 | |||
11 | def __init__(self, axis=-1): |
||
12 | """ |
||
13 | :type layer1: NeuralLayer |
||
14 | :type layer2: NeuralLayer |
||
15 | """ |
||
16 | super(Concatenate, self).__init__("concate") |
||
17 | self.axis = axis |
||
18 | |||
19 | def prepare(self): |
||
20 | self.output_dim = sum(self.input_dims) |
||
21 | |||
22 | def compute_tensor(self, *xs): |
||
23 | if self.axis == -1: |
||
24 | axis = xs[0].ndim - 1 |
||
25 | else: |
||
26 | axis = self.axis |
||
27 | return T.concatenate(xs, axis=axis) |