examples/attention_models/baseline_model.py
def _glimpse_sensor(self, x_t, l_p):
        """
        Parameters:
            x_t - 28x28 image
            l_p - 2x1 focus vector
        Returns:
            4x12 matrix
        """
        # Turn l_p to the left-top point of rectangle
        l_p = l_p * 14 + 14 - 2
        l_p = T.cast(T.round(l_p), "int32")

        l_p = l_p * (l_p >= 0)
        l_p = l_p * (l_p < 24) + (l_p >= 24) * 23
        l_p2 = l_p - 2
        l_p2 = l_p2 * (l_p2 >= 0)
        l_p2 = l_p2 * (l_p2 < 20) + (l_p2 >= 20) * 19
        l_p3 = l_p - 6
        l_p3 = l_p3 * (l_p3 >= 0)
        l_p3 = l_p3 * (l_p3 < 16) + (l_p3 >= 16) * 15
        glimpse_1 = x_t[l_p[0]: l_p[0] + 4][:, l_p[1]: l_p[1] + 4]
        glimpse_2 = x_t[l_p2[0]: l_p2[0] + 8][:, l_p2[1]: l_p2[1] + 8]
        glimpse_2 = theano.tensor.signal.downsample.max_pool_2d(glimpse_2, (2,2))
        glimpse_3 = x_t[l_p3[0]: l_p3[0] + 16][:, l_p3[1]: l_p3[1] + 16]
        glimpse_3 = theano.tensor.signal.downsample.max_pool_2d(glimpse_3, (4,4))
        return T.concatenate([glimpse_1, glimpse_2, glimpse_3])
def _glimpse_sensor(self, x_t, l_p):
        """
        Parameters:
            x_t - 28x28 image
            l_p - 2x1 focus vector
        Returns:
            4x12 matrix
        """
        # Turn l_p to the left-top point of rectangle
        l_p = l_p * 14 + 14 - 2
        l_p = T.cast(T.round(l_p), "int32")

        l_p = l_p * (l_p >= 0)
        l_p = l_p * (l_p < 24) + (l_p >= 24) * 23
        l_p2 = l_p - 2
        l_p2 = l_p2 * (l_p2 >= 0)
        l_p2 = l_p2 * (l_p2 < 20) + (l_p2 >= 20) * 19
        l_p3 = l_p - 6
        l_p3 = l_p3 * (l_p3 >= 0)
        l_p3 = l_p3 * (l_p3 < 16) + (l_p3 >= 16) * 15
        glimpse_1 = x_t[l_p[0]: l_p[0] + 4][:, l_p[1]: l_p[1] + 4]
        glimpse_2 = x_t[l_p2[0]: l_p2[0] + 8][:, l_p2[1]: l_p2[1] + 8]
        glimpse_2 = theano.tensor.signal.downsample.max_pool_2d(glimpse_2, (2,2))
        glimpse_3 = x_t[l_p3[0]: l_p3[0] + 16][:, l_p3[1]: l_p3[1] + 16]
        glimpse_3 = theano.tensor.signal.downsample.max_pool_2d(glimpse_3, (4,4))
        return T.concatenate([glimpse_1, glimpse_2, glimpse_3])
def _glimpse_sensor ( self , x_t , l_p ) : # Turn l_p to the left-top point of rectangle l_p = l_p * 14 + 14 - 2 l_p = T . cast ( T . round ( l_p ) , "int32" ) l_p = l_p * ( l_p >= 0 ) l_p = l_p * ( l_p < 24 ) + ( l_p >= 24 ) * 23 l_p2 = l_p - 2 l_p2 = l_p2 * ( l_p2 >= 0 ) l_p2 = l_p2 * ( l_p2 < 20 ) + ( l_p2 >= 20 ) * 19 l_p3 = l_p - 6 l_p3 = l_p3 * ( l_p3 >= 0 ) l_p3 = l_p3 * ( l_p3 < 16 ) + ( l_p3 >= 16 ) * 15 glimpse_1 = x_t [ l_p [ 0 ] : l_p [ 0 ] + 4 ] [ : , l_p [ 1 ] : l_p [ 1 ] + 4 ] glimpse_2 = x_t [ l_p2 [ 0 ] : l_p2 [ 0 ] + 8 ] [ : , l_p2 [ 1 ] : l_p2 [ 1 ] + 8 ] glimpse_2 = theano . tensor . signal . downsample . max_pool_2d ( glimpse_2 , ( 2 , 2 ) ) glimpse_3 = x_t [ l_p3 [ 0 ] : l_p3 [ 0 ] + 16 ] [ : , l_p3 [ 1 ] : l_p3 [ 1 ] + 16 ] glimpse_3 = theano . tensor . signal . downsample . max_pool_2d ( glimpse_3 , ( 4 , 4 ) ) return T . concatenate ( [ glimpse_1 , glimpse_2 , glimpse_3 ] )
Parameters:
            x_t - 28x28 image
            l_p - 2x1 focus vector
        Returns:
            4x12 matrix
Parameters : x_t - 28x28 image l_p - 2x1 focus vector Returns : 4x12 matrix