Example #1
0
 def perform_learning(self, options):
     """ Perfrom the learning from the dataset. """
     # Retreiving the dataset models
     print 'Training using a {} classifier.'.format(
         options['classifier_type'])
     models = {}
     for category in self.dataset.keys():
         models[category] = []
         for google_id in self.dataset[category]:
             models[category].append(
                 SketchupModel.find_google_id(google_id))
     # Training
     classifier = self.classifiers_available[options['classifier_type']]
     self.identifier = Identifier(classifier=classifier)
     for category in models.keys():
         self.identifier.add_models(models[category], category)
     # (x, y, w) = self.identifier._get_example_matrix()
     # import matplotlib.pyplot as plt
     # import numpy as np
     # # w = np.array(w)
     # # print y
     # # print w
     # plt.plot(y, w, 'ro')
     # print self.dataset.keys()
     # plt.show()
     self.identifier.train(options['entropy'])
Example #2
0
 def test_identification_banana_vs_bowl_vs_food_can(self):
     """ Try to identify with 3 categories. """
     # Getting the dataset
     bowl_ids = ['fa61e604661d4aa66658ecd96794a1cd',
                 'f74bba9a22e044dea3769fcd5f96f4',
                 'd2e1dc9ee02834c71621c7edb823fc53']
     banana_ids = ['f6e6117261dca163713c042b393cc65b',
                   'ba0d56295321002718ddbf38fa69c501',
                   '7d78e217e0ba160fe2b248b8bb97d290']
     bowls = []
     for bowl_id in bowl_ids:
         bowls.append(SketchupModel.find_google_id(bowl_id))
     bananas = []
     for banana_id in banana_ids:
         bananas.append(SketchupModel.find_google_id(banana_id))
     # Training
     iden = Identifier()
     iden.add_models(bananas, 'banana')
     iden.add_models(bowls, 'bowl')
     iden.train()
     # Identification
     for i in range(20):
         example = Example.get_random(['banana', 'bowl'])
         pcd_file = example.pcd_file()
         print "Identification of file {}".format(example)
         cloud = PointCloud.load_pcd(pcd_file.name)
         iden.identify(cloud)
Example #3
0
 def test_exception_when_no_existing_category(self):
     """ Test that if the identifier is empty it throws. """
     pointcloud = PointCloud.load_pcd("pointcloud/fixtures/cloud.pcd")
     identifier = Identifier()
     self.assertRaises(IndexError, identifier.identify, pointcloud)
     # training will add a category :
     model = SketchupModel()
     model.google_id = "test1"
     model.mesh = file("sketchup_models/fixtures/mesh_can.tri").read()
     identifier.add_models([model], "test_category")
     try:
         identifier.identify(pointcloud)
     except IndexError:
         self.fail("identifier.identify() raised IndexError unexpectedly!")
     except:
         # can raise if Indentification failed
         pass
 def __init__(self, *args, **kwargs):
     """ Overwrite to have a default classifier. """
     if 'identifier' not in kwargs:
         default = Identifier(classifier=KNeighborsClassifier())
         kwargs['identifier'] = default
     super(EvaluationSession, self).__init__(*args, **kwargs)