예제 #1
0
 def testCrossValidateSvm(self):
   glab.SetCorpus(EXAMPLE_LARGE_CORPUS)
   glab.ImprintS2Prototypes(NUM_PROTOTYPES)
   glab.CrossValidateSvm()
   e = glab.GetExperiment()
   self.assertEqual(e.train_results, None)
   self.assertNotEqual(e.test_results['accuracy'], None)
예제 #2
0
 def testImprintS2Prototypes(self):
   glab.SetCorpus(EXAMPLE_CORPUS)
   glab.ImprintS2Prototypes(NUM_PROTOTYPES)
   e = glab.GetExperiment()
   # S2 kernels are stored as a list of arrays, with one list entry per kernel
   # size. Check that we've imprinted NUM_PROTOTYPES patches for each kernel
   # size.
   self.assertEqual(map(len, e.model.s2_kernels),
       [ NUM_PROTOTYPES ] * len(e.model.s2_kernels) )
예제 #3
0
 def testStoreExperiment_notEmpty(self):
   temp_dir = TempDir()
   glab.SetCorpus(EXAMPLE_CORPUS)
   glab.ImprintS2Prototypes(10)
   glab.RunSvm()
   old_exp = glab.GetExperiment()
   exp_path = pjoin(temp_dir.dir, 'dat')
   glab.StoreExperiment(exp_path)
   new_exp = glab.LoadExperiment(exp_path)
   self.assertEqual(new_exp, old_exp)
예제 #4
0
 def _testSetCorpus(self, images, expected_classes):
   root = MockDirs(**images)
   glab.SetCorpus(root.dir, classes = expected_classes)
   e = glab.GetExperiment()
   self.assertEqual(e.corpus, root.dir)
   self.assertNotEqual(e.classes, None)
   if expected_classes == None:
     self.assertEqual(sorted(e.classes), sorted(images.keys()))
   else:
     self.assertEqual(e.classes, expected_classes)
   for idx in range(len(e.classes)):
     actual_images = sorted(map(os.path.basename,
         e.train_images[idx] + e.test_images[idx]))
     expected_images = sorted(images[e.classes[idx]])
     self.assertEqual(actual_images, expected_images)
예제 #5
0
 def testMakeNormalRandomS2Prototypes(self):
   glab.SetCorpus(EXAMPLE_CORPUS)
   glab.MakeNormalRandomS2Prototypes(NUM_PROTOTYPES)
   e = glab.GetExperiment()
   self.assertEqual(map(len, e.model.s2_kernels),
       [ NUM_PROTOTYPES ] * len(e.model.s2_kernels) )
예제 #6
0
 def testRunSvm(self):
   glab.SetCorpus(EXAMPLE_CORPUS)
   glab.RunSvm()
   e = glab.GetExperiment()
   self.assertNotEqual(e.train_results['accuracy'], None)
   self.assertNotEqual(e.test_results['accuracy'], None)