# Path: seya/utils.py
# def apply_layer(layer, X, train=False):
#     tmp = layer.get_input
#     layer.get_input = lambda _: X
#     Y = layer.get_output(train=train)
#     layer.get_input = tmp
#     return Y


import numpy as np
import theano.tensor as T
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.layers.recurrent import Recurrent
from keras.layers.core import MaskedLayer
from keras import initializations
from keras import activations
from keras import backend as K
from seya.utils import apply_layer
        # hidden to hidden connections
        self.conv_h.build()
        self.conv_z.build()
        self.conv_r.build()
        # input to hidden connections
        self.conv_x_h.build()
        self.conv_x_z.build()
        self.conv_x_r.build()

        self.max_pool = MaxPooling2D(pool_size=self.subsample)

        self.trainable_weights = self.conv_h.trainable_weights + self.conv_z.trainable_weights + self.conv_r.trainable_weights + \
            self.conv_x_h.trainable_weights + self.conv_x_z.trainable_weights + self.conv_x_r.trainable_weights

        if self.initial_weights is not None:
            self.set_weights(self.initial_weights)
            del self.initial_weights

    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)


# Path: seya/utils.py
# def apply_layer(layer, X, train=False):
#     tmp = layer.get_input
#     layer.get_input = lambda _: X
#     Y = layer.get_output(train=train)
#     layer.get_input = tmp
#     return Y


# Path: seya/layers/conv_rnn.py
import numpy as np
import theano.tensor as T
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.layers.recurrent import Recurrent
from keras.layers.core import MaskedLayer
from keras import initializations
from keras import activations
from keras import backend as K
from seya.utils import apply_layer

        # hidden to hidden connections
        self.conv_h.build()
        self.conv_z.build()
        self.conv_r.build()
        # input to hidden connections
        self.conv_x_h.build()
        self.conv_x_z.build()
        self.conv_x_r.build()

        self.max_pool = MaxPooling2D(pool_size=self.subsample)

        self.trainable_weights = self.conv_h.trainable_weights + self.conv_z.trainable_weights + self.conv_r.trainable_weights + \
            self.conv_x_h.trainable_weights + self.conv_x_z.trainable_weights + self.conv_x_r.trainable_weights

        if self.initial_weights is not None:
            self.set_weights(self.initial_weights)
            del self.initial_weights

    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)