def test_tensor(): h2o = Dense(4, 2) model = Tensor(input_dim=3, output_dim=4, causes_dim=2, hid2output=h2o, return_mode='both') X = tensor.tensor3() Y = apply_layer(model, X) F = function([X], Y, allow_input_downcast=True) x = np.ones((3, 10, 3)) y = F(x) assert y.shape == (10, 3, 4+2)
def step(self, x, states): batch_size = self._get_batch_size(x) input_shape = (batch_size, ) + self.reshape_dim hidden_dim = (batch_size, ) + self.output_dim nb_filter, nb_rows, nb_cols = self.output_dim h_tm1 = K.reshape(states[0], hidden_dim) x_t = K.reshape(x, input_shape) xz_t = self.conv_x_z(x_t, train=True) xr_t = self.conv_x_r(x_t, train=True) xh_t = self.conv_x_h(x_t, train=True) xz_t = apply_layer(self.max_pool, xz_t) xr_t = apply_layer(self.max_pool, xr_t) xh_t = apply_layer(self.max_pool, xh_t) z = self.inner_activation(xz_t + self.conv_z(h_tm1)) r = self.inner_activation(xr_t + self.conv_r(h_tm1)) hh_t = self.activation(xh_t + self.conv_h(r * h_tm1)) h_t = z * h_tm1 + (1 - z) * hh_t h_t = K.batch_flatten(h_t) return h_t, [h_t, ]
def step(self, x, states): input_shape = (self.batch_size, ) + self.reshape_dim hidden_dim = (self.batch_size, ) + self.output_dim nb_filter, nb_rows, nb_cols = self.output_dim h_tm1 = K.reshape(states[0], hidden_dim) x_t = K.reshape(x, input_shape) xz_t = apply_layer(self.conv_x_z, x_t) xr_t = apply_layer(self.conv_x_r, x_t) xh_t = apply_layer(self.conv_x_h, x_t) xz_t = apply_layer(self.max_pool, xz_t) xr_t = apply_layer(self.max_pool, xr_t) xh_t = apply_layer(self.max_pool, xh_t) z = self.inner_activation(xz_t + apply_layer(self.conv_z, h_tm1)) r = self.inner_activation(xr_t + apply_layer(self.conv_r, h_tm1)) hh_t = self.activation(xh_t + apply_layer(self.conv_h, r * h_tm1)) h_t = z * h_tm1 + (1 - z) * hh_t h_t = K.flatten(h_t) return h_t, [h_t, ]
def step(self, x, states): input_shape = (self.batch_size, ) + self.reshape_dim hidden_dim = (self.batch_size, ) + self.output_dim nb_filter, nb_rows, nb_cols = self.output_dim h_tm1 = K.reshape(states[0], hidden_dim) x_t = K.reshape(x, input_shape) xz_t = apply_layer(self.conv_x_z, x_t) xr_t = apply_layer(self.conv_x_r, x_t) xh_t = apply_layer(self.conv_x_h, x_t) xz_t = apply_layer(self.max_pool, xz_t) xr_t = apply_layer(self.max_pool, xr_t) xh_t = apply_layer(self.max_pool, xh_t) z = self.inner_activation(xz_t + apply_layer(self.conv_z, h_tm1)) r = self.inner_activation(xr_t + apply_layer(self.conv_r, h_tm1)) hh_t = self.activation(xh_t + apply_layer(self.conv_h, r * h_tm1)) h_t = z * h_tm1 + (1 - z) * hh_t h_t = K.flatten(h_t) return h_t, [ h_t, ]