Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
 def _first_glimpse_sensor(self, x_t):
     """
     Compute first glimpse position using down-sampled image.
     """
     downsampled_img = theano.tensor.signal.downsample.max_pool_2d(x_t, (4,4))
     downsampled_img = downsampled_img.flatten()
     first_l = T.dot(downsampled_img, self.W_f)
     if self.disable_reinforce:
         wf_grad = self.W_f
         if self.random_glimpse:
             first_l = self.srng.uniform((2,), low=-1.7, high=1.7)
     else:
         sampled_l_t = self._sample_gaussian(first_l, self.cov)
         sampled_pdf = self._multi_gaussian_pdf(disconnected_grad(sampled_l_t), first_l)
         wf_grad = T.grad(T.log(sampled_pdf), self.W_f)
         first_l = sampled_l_t
     return first_l, wf_grad
Exemplo n.º 4
0
 def _first_glimpse_sensor(self, x_t):
     """
     Compute first glimpse position using down-sampled image.
     """
     downsampled_img = theano.tensor.signal.downsample.max_pool_2d(
         x_t, (4, 4))
     downsampled_img = downsampled_img.flatten()
     first_l = T.dot(downsampled_img, self.W_f)
     if self.disable_reinforce:
         wf_grad = self.W_f
         if self.random_glimpse:
             first_l = self.srng.uniform((2, ), low=-1.7, high=1.7)
     else:
         sampled_l_t = self._sample_gaussian(first_l, self.cov)
         sampled_pdf = self._multi_gaussian_pdf(
             disconnected_grad(sampled_l_t), first_l)
         wf_grad = T.grad(T.log(sampled_pdf), self.W_f)
         first_l = sampled_l_t
     return first_l, wf_grad