# Path: seya/utils.py
# def apply_model(model, X):
#     tmp = model.layers[0].get_input
#     model.layers[0].get_input = lambda _: X
#     Y = model.get_output()
#     model.layers[0].get_input = tmp
# 
#     return Y


import numpy as np
import theano
import theano.tensor as T
from keras.layers.core import Layer
from ..utils import apply_model

    """
    def __init__(self,
                 localization_net,
                 downsample_factor=1,
                 return_theta=False,
                 **kwargs):
        self.downsample_factor = downsample_factor
        self.locnet = localization_net
        self.return_theta = return_theta
        super(SpatialTransformer, self).__init__(**kwargs)

    def build(self):
        if hasattr(self, 'previous'):
            self.locnet.set_previous(self.previous)
        self.locnet.build()
        self.trainable_weights = self.locnet.trainable_weights
        self.regularizers = self.locnet.regularizers
        self.constraints = self.locnet.constraints
        self.input = self.locnet.input  # This must be T.tensor4()

    @property
    def output_shape(self):
        input_shape = self.input_shape
        return (None, input_shape[1],
                int(input_shape[2] / self.downsample_factor),
                int(input_shape[3] / self.downsample_factor))

    def get_output(self, train=False):
        X = self.get_input(train)

# Path: seya/utils.py
# def apply_model(model, X):
#     tmp = model.layers[0].get_input
#     model.layers[0].get_input = lambda _: X
#     Y = model.get_output()
#     model.layers[0].get_input = tmp
# 
#     return Y


# Path: seya/layers/attention.py
import numpy as np
import theano
import theano.tensor as T
from keras.layers.core import Layer
from ..utils import apply_model


    """
    def __init__(self,
                 localization_net,
                 downsample_factor=1,
                 return_theta=False,
                 **kwargs):
        self.downsample_factor = downsample_factor
        self.locnet = localization_net
        self.return_theta = return_theta
        super(SpatialTransformer, self).__init__(**kwargs)

    def build(self):
        if hasattr(self, 'previous'):
            self.locnet.set_previous(self.previous)
        self.locnet.build()
        self.trainable_weights = self.locnet.trainable_weights
        self.regularizers = self.locnet.regularizers
        self.constraints = self.locnet.constraints
        self.input = self.locnet.input  # This must be T.tensor4()

    @property
    def output_shape(self):
        input_shape = self.input_shape
        return (None, input_shape[1],
                int(input_shape[2] / self.downsample_factor),
                int(input_shape[3] / self.downsample_factor))

    def get_output(self, train=False):
        X = self.get_input(train)

        theta = apply_model(self.locnet, X)