examples/attention_models/first_glimpse_model.py
def _core_network(self, l_p, h_p, x_t):
        """
        Parameters:
            x_t - 28x28 image
            l_p - 2x1 focus vector
            h_p - 256x1 vector
        Returns:
            h_t, 256x1 vector
        """
        g_t = self._glimpse_network(x_t, l_p)
        h_t = self._tanh(T.dot(g_t, self.W_h_g) + T.dot(h_p, self.W_h) + self.B_h)
        l_t = self._location_network(h_t)

        if not self.disable_reinforce:
            sampled_l_t = self._sample_gaussian(l_t, self.cov)
            sampled_pdf = self._multi_gaussian_pdf(disconnected_grad(sampled_l_t), l_t)
            wl_grad = T.grad(T.log(sampled_pdf), self.W_l)
        else:
            sampled_l_t = l_t
            wl_grad = self.W_l

        if self.random_glimpse and self.disable_reinforce:
            sampled_l_t = self.srng.uniform((2,), low=-1.7, high=1.7)

        a_t = self._action_network(h_t)

        return sampled_l_t, h_t, a_t, wl_grad
def _core_network(self, l_p, h_p, x_t):
        """
        Parameters:
            x_t - 28x28 image
            l_p - 2x1 focus vector
            h_p - 256x1 vector
        Returns:
            h_t, 256x1 vector
        """
        g_t = self._glimpse_network(x_t, l_p)
        h_t = self._tanh(T.dot(g_t, self.W_h_g) + T.dot(h_p, self.W_h) + self.B_h)
        l_t = self._location_network(h_t)

        if not self.disable_reinforce:
            sampled_l_t = self._sample_gaussian(l_t, self.cov)
            sampled_pdf = self._multi_gaussian_pdf(disconnected_grad(sampled_l_t), l_t)
            wl_grad = T.grad(T.log(sampled_pdf), self.W_l)
        else:
            sampled_l_t = l_t
            wl_grad = self.W_l

        if self.random_glimpse and self.disable_reinforce:
            sampled_l_t = self.srng.uniform((2,), low=-1.7, high=1.7)

        a_t = self._action_network(h_t)

        return sampled_l_t, h_t, a_t, wl_grad
def _core_network ( self , l_p , h_p , x_t ) : g_t = self . _glimpse_network ( x_t , l_p ) h_t = self . _tanh ( T . dot ( g_t , self . W_h_g ) + T . dot ( h_p , self . W_h ) + self . B_h ) l_t = self . _location_network ( h_t ) if not self . disable_reinforce : sampled_l_t = self . _sample_gaussian ( l_t , self . cov ) sampled_pdf = self . _multi_gaussian_pdf ( disconnected_grad ( sampled_l_t ) , l_t ) wl_grad = T . grad ( T . log ( sampled_pdf ) , self . W_l ) else : sampled_l_t = l_t wl_grad = self . W_l if self . random_glimpse and self . disable_reinforce : sampled_l_t = self . srng . uniform ( ( 2 , ) , low = - 1.7 , high = 1.7 ) a_t = self . _action_network ( h_t ) return sampled_l_t , h_t , a_t , wl_grad
Parameters:
            x_t - 28x28 image
            l_p - 2x1 focus vector
            h_p - 256x1 vector
        Returns:
            h_t, 256x1 vector
Parameters : x_t - 28x28 image l_p - 2x1 focus vector h_p - 256x1 vector Returns : h_t 256x1 vector