def train(self):
   """ Store a copy of every image in the iterator. """
   Experiment.train(self)
   start = time.time()
   
   num_images = len(self.image_iterator)
   print "Num images:", num_images
   assert num_images > 0
   
   gabor = self.gabor_region = GaborRegion((144, 192), rotations=3, 
                                           initial_wavelength=3, 
                                           num_wavelengths=2)
   
   kmeans = KmeansRegion(max(1,int(float(num_images) * self.compression)),
                         self.window_sampler)
   and_region = AndOrRegion(kmeans.image_shape, num_images)
   
   
   # Regions = [ GaborRegion, Kmeans, AndRegion, OrRegion (classifier) ]
   self.network = AndOrNetwork([gabor, kmeans, and_region])
   classifier = self.network.get_classifier()
   
   self.categories = []
   print "Extracting windows..."
   i = 0
   while self.image_iterator.has_next():
     image, category, img_idx = self.image_iterator.next()
     self.categories.append(category)
     gabor.do_inference(numpy.array(image))
     kmeans.do_learning()
     i += 1
     
   print "Training K-means..."
   kmeans.prepare_for_inference()
   
   # Send all of the images through the feature learner to save the image
   # activations.
   print "Storing classifier features..."
   self.image_iterator.reset()
   while self.image_iterator.has_next():
     image, category, img_idx = self.image_iterator.next()
     gabor.do_inference(numpy.array(image))
     kmeans.do_inference()
     cxns = kmeans.get_active_nodes()
     pos = and_region.create_node((0,0), cxns = cxns)
     classifier.create_node(category, pos)
   
   print "Preparing for inference..."
   self.network.prepare_for_inference(2)