Beispiel #1
0
 def get_window_nonzeros(self, pos, shape):
   """ Returns a list of the nonzero values within the given window. """
   values = self.node_values
   
   # Assert valid window
   assert (pos[0] + shape[0]) <= self.image_shape[0]
   assert (pos[1] + shape[1]) <= self.image_shape[1]
   
   # First compute the number of elements in the array
   args = [pos[0], pos[1], shape[0], shape[1],
           self.node_start_pos,
           self.node_counts,
           values, 
           self.num_vals_buf]
   c_methods.get_num_window_nonzeros(*DynamicArray.csafe(args))
   
   # Create the array, and assign all values to it
   nonzeros = numpy.empty((self.num_vals_buf[0],3), 'int')
   args = [pos[0], pos[1], shape[0], shape[1],
           self.node_start_pos,
           self.node_counts,
           values,
           nonzeros]
   c_methods.get_window_nonzeros(*DynamicArray.csafe(args))
   
   return nonzeros
Beispiel #2
0
 def get_window_values(self, pos, shape, values=None):
   """ Returns a numpy array containing all values within the window at the 
   given position and with width, height = shape. If values is not None,
   then the values given will be used instead of self.node_values. """
   if values is None:
     values = self.node_values
   
   # Assert valid window
   assert (pos[0] + shape[0]) <= self.image_shape[0]
   assert (pos[1] + shape[1]) <= self.image_shape[1]
   
   # First compute the number of elements in the array
   c_methods.get_num_window_values(pos[0], pos[1], shape[0], shape[1],
                                   self.node_counts, self.num_vals_buf)
   
   # Create the array, and assign all values to it
   window_values = numpy.empty((self.num_vals_buf[0],), 'float32')
   args = [pos[0], pos[1], shape[0], shape[1],
           self.node_start_pos,
           self.node_counts,
           values, 
           window_values]
   c_methods.get_window_values(*DynamicArray.csafe(args))
   
   return window_values
Beispiel #3
0
  def do_inference(self):
    """ Computes the values of all nodes given the input activations. """

    args = [ self.num_nodes,
             self.node_values,
             self.node_types,
             self.cxn_start_pos,
             self.node_cxns,
             
             self.child_region.node_start_pos,
             self.child_region.node_values ]

    c_methods.do_inference(*DynamicArray.csafe(args))
Beispiel #4
0
  def do_inference(self, image):
    """ Convolves the input image with each mask, 
    and stores the result in the AndOrRegion nodes. """
    assert image.shape == self.image_shape
    
    args = [ image,
             self.num_masks,
             self.padded_masks,
             self.mask_shapes,
             self.threshold,
             self.node_values,
             self.node_start_pos ]

    c_methods.gabor_transform(*DynamicArray.csafe(args))