| 56 | |
| 57 | |
| 58 | class Res_layer(Layer): |
| 59 | def __init__(self, hidden_units): |
| 60 | super(Res_layer, self).__init__() |
| 61 | self.dense_layer = [MyDense(i, activation="relu") for i in hidden_units] |
| 62 | |
| 63 | def build(self, input_shape): |
| 64 | self.output_layer = MyDense(input_shape[-1], activation=None) |
| 65 | |
| 66 | def call(self, inputs, **kwargs): |
| 67 | if K.ndim(inputs) != 2: |
| 68 | raise ValueError("The dim of inputs should be 2, not %d" % (K.ndim(inputs))) |
| 69 | x = inputs |
| 70 | for layer in self.dense_layer: |
| 71 | x = layer(x) |
| 72 | x = self.output_layer(x) |
| 73 | output = inputs + x |
| 74 | return sgx.e_relu(output) |