当前位置: 首页>>代码示例>>Python>>正文


Python Experiment.train方法代码示例

本文整理汇总了Python中experiment.Experiment.train方法的典型用法代码示例。如果您正苦于以下问题:Python Experiment.train方法的具体用法?Python Experiment.train怎么用?Python Experiment.train使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在experiment.Experiment的用法示例。


在下文中一共展示了Experiment.train方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: train

# 需要导入模块: from experiment import Experiment [as 别名]
# 或者: from experiment.Experiment import train [as 别名]
 def train(self):
   """ Store a copy of every image in the iterator. """
   Experiment.train(self)
   start = time.time()
   
   gabor = GaborRegion((144, 192), rotations=3, 
                       initial_wavelength=3, 
                       num_wavelengths=2)
   
   # Regions = [ GaborRegion, AndRegion, OrRegion (classifier) ]
   self.network = AndOrNetwork((144,192), num_regions=1, 
                               input_region = gabor)
   and_region = self.network.regions[1]
   classifier = self.network.get_classifier()
   
   i = 0
   while self.image_iterator.has_next():
     image, category, img_idx = self.image_iterator.next()
     gabor.do_inference(numpy.array(image))
     active_nodes = gabor.get_active_nodes()
     pos = and_region.create_node((0,0), cxns = active_nodes)
     classifier.create_node(category, pos)
     i += 1
     if i % self.PRINT_INCR == 0: print "Iter:", i
     
   and_region.prepare_for_inference()
   classifier.prepare_for_inference()
   
   num_cxns = and_region.get_num_cxns() + classifier.get_num_cxns()
   print "Number of connections:", num_cxns
   elapsed = (time.time() - start)
   print "Training time:", elapsed
   print "Time per category:", (elapsed / i)
   print colored("Training complete", "green")
开发者ID:kkansky,项目名称:and_or_images,代码行数:36,代码来源:brute_force.py

示例2: train

# 需要导入模块: from experiment import Experiment [as 别名]
# 或者: from experiment.Experiment import train [as 别名]
 def train(self):
   """ Store a copy of every image in the iterator. """
   Experiment.train(self)
   start = time.time()
   
   self.image_shape = (144, 192)
   
   gabor = GaborRegion(self.image_shape, rotations=3, 
                       initial_wavelength=3, 
                       num_wavelengths=2)
   
   # Regions = [ GaborRegion, AndRegion, OrRegion (classifier) ]
   self.network = AndOrNetwork((144,192), num_regions=2, 
                               input_region = gabor)
   f1 = self.network.regions[1]
   f2 = self.network.regions[2]
   classifier = self.network.get_classifier()
   
   self.gabor_acts = gabor.precompute_image_activations(self.image_iter)
   windows = self.get_windows()
   
   for window in windows:
     
   
   
   self.network.prepare_for_inference(1)
   elapsed = (time.time() - start)
   
   total_cxns = 0
   for i, r in enumerate(self.network.regions[1:]):
     num_cxns = r.get_num_cxns()
     print "Region %s cxns: %s" % (i, num_cxns)
     total_cxns += num_cxns
   
   print "Total connections:", total_cxns
   print "Training time:", elapsed
   print "Time per category:", (elapsed / i)
   print colored("Training complete", "green")
     
 def test(self):
   """ Test that every image is correctly recognized. """
   Experiment.test(self)
   start = time.time()
   
   classifier = self.network.get_classifier()
   i = 0
   while self.image_iterator.has_next():
     image, category = self.image_iterator.next()
     recognized = self.network.do_inference(numpy.array(image), category)
     if not recognized:
       active_cats = classifier.get_active_categories()
       print colored("Failed: " + category + " recognized as "+repr(active_cats), 'red')
     i += 1
     if i % self.PRINT_INCR == 0: print "Iter:", i
   
   elapsed = (time.time() - start)
   print "Testing time:", elapsed
   print "Time per category:", (elapsed / i)
   print colored("Testing complete", "green")
开发者ID:kkansky,项目名称:and_or_images,代码行数:61,代码来源:window_grid.py

示例3: train

# 需要导入模块: from experiment import Experiment [as 别名]
# 或者: from experiment.Experiment import train [as 别名]
 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)
开发者ID:kkansky,项目名称:and_or_images,代码行数:51,代码来源:kmeans_compression.py

示例4: train

# 需要导入模块: from experiment import Experiment [as 别名]
# 或者: from experiment.Experiment import train [as 别名]
 def train(self):
   """ This does all learning, iterating through the images one at a time. """
   Experiment.train(self)
   
   window_sampler = TiledWindowSampler(self.image_iter.get_image_size(),
                                       self.feature_size)
   
   image_sensor = ImageSensorRegion((1,) + self.image_iter.get_image_size())
   learner = ParticleFeatureLearner(image_sensor, window_sampler)
   
   activations = []
   while self.image_iter.has_next():
     image = self.image_iter.next()
     image_sensor.do_inference(image)
     activations.append(image_sensor.node_values.copy())
     
   learner.compute_features(activations)
开发者ID:kkansky,项目名称:and_or_images,代码行数:19,代码来源:grid_particle_learning.py

示例5: main

# 需要导入模块: from experiment import Experiment [as 别名]
# 或者: from experiment.Experiment import train [as 别名]
def main():
  """ This is the main entry point for training and testing your classifier. """
  classifier = Classifier()
  experiment = Experiment(classifier)
  experiment.train('training')
  
  # Sanity check. Should get 100% on the training images. 
  report = experiment.test('training')
  report.print_summary()
  
  Pdb.set_trace()

  test_datasets = 'translations rotations scales noise occlusion distortion blurry_checkers'
  final_report = ClassificationReport("All Datasets")
  
  # Print the classification results of each test
  for dataset in test_datasets.split():
    report = experiment.test('testing/' + dataset)
    report.print_summary()
    #report.print_errors() # Uncomment this to print the error images for debugging. 
    final_report.extend(report)
  
  final_report.print_summary()
开发者ID:mrastegari,项目名称:Basic_Image_Classification,代码行数:25,代码来源:main.py

示例6: MySuite

# 需要导入模块: from experiment import Experiment [as 别名]
# 或者: from experiment.Experiment import train [as 别名]
class MySuite(PyExperimentSuite):

    def reset(self, params, rep):
        train_dir = params['train_dir']
        test_dir = params['test_dir']
        model_type = params["model"]
        update = params["update"]
        avg = params["avg"]
        C = params["aggressiveness"] # only for PA
        self._exp = Experiment(train_dir,
                               test_dir,
                               model_type=model_type,
                               update=update,
                               avg=avg,
                               C=C)        
        # settings for training
        self._epochs = params["epochs"]
        return
        
    
    def iterate(self, params, rep, n):        
        self._exp.train( self._epochs )
        res = self._exp.test()
        return res
开发者ID:chloebt,项目名称:attelo,代码行数:26,代码来源:exp_suite.py


注:本文中的experiment.Experiment.train方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。