Esempio n. 1
0
class IqmFacePad(FacePad):
    def __init__(self, svm_model_path, threshold, name='IqmFacePad'):
        self.features_extractor = IqmFeaturesExtractor()
        self.classifier = RbfSvc(name='RbfSvc')
        self.classifier.load(svm_model_path)
        self.scores = []
        self.threshold = threshold
        self.finished = False
        super(IqmFacePad, self).__init__(name, threshold)

    def process(self, im):
        dict_images = {'0': im}
        dict_features = self.features_extractor.run(dict_images)
        X = {'features': np.reshape(dict_features['0'], (1, dict_features['0'].shape[0]))}
        X = self.classifier.run(X)
        score = X['scores'][0]
        self.scores.append(score)
        self.finished = True

    def is_finished(self):
        return self.finished

    def reset(self):
        self.scores = []
        self.finished = False

    def get_decision(self):
        average_score = np.mean(self.scores)
        self.scores = []
        if average_score < self.threshold:
            return 'ATTACK', average_score
        else:
            return 'NO_ATTACK', average_score
    def test_transform_calls_sklearn_transform(self):
        features = self.X['features'].copy()
        svc = RbfSvc()

        svc.run(self.X)

        np.testing.assert_array_equal(SVC.decision_function.call_args[0][0],
                                      features)
Esempio n. 3
0
 def __init__(self, svm_model_path, threshold, name='IqmFacePad'):
     self.features_extractor = IqmFeaturesExtractor()
     self.classifier = RbfSvc(name='RbfSvc')
     self.classifier.load(svm_model_path)
     self.scores = []
     self.threshold = threshold
     self.finished = False
     super(IqmFacePad, self).__init__(name, threshold)
    def test_save_model(self):
        svc = RbfSvc(name='TestSvc')

        svc.save(self.base_path)

        h5py.File.assert_called_once_with(
            os.path.join(self.base_path, 'processors/TestSvc.h5'), 'w')
        self.h5f.create_dataset.assert_called_once_with(
            'data', data=np.array('Model dump'))
    def test_load_model(self):
        svc = RbfSvc(name='TestSvc')
        svc.load(self.base_path)

        h5py.File.assert_called_once_with(
            os.path.join(self.base_path, 'processors/TestSvc.h5'), 'r')
        if sys.version_info[0] < 3:
            pickle.loads.assert_called_once_with('Model')
        else:
            pickle.loads.assert_called_once_with('Model', encoding='latin1')

        self.assertEquals('Model', svc._model)
    def test_fit_calls_sklearn_fit(self):
        svc = RbfSvc()
        svc.fit(self.X)

        labels = copy.deepcopy(self.X['labels'])
        expected_labels = copy.deepcopy(labels)
        expected_labels[labels > 0] = 0
        expected_labels[labels == 0] = 1

        np.testing.assert_array_equal(SVC.fit.call_args[0][0],
                                      self.X['features'])
        np.testing.assert_array_equal(SVC.fit.call_args[0][1], expected_labels)
def get_pipeline_average_features_scaled_rbfsvc(name):
    pipeline = Pipeline(
        name,
        [AverageFeatures(),
         FeaturesScaleNormalizer(),
         RbfSvc(name='RbfSvc')])
    return pipeline
 def test_constructor_calls_sklearn_constructor(self):
     RbfSvc(c=0.94, gamma=0.1)
     SVC.__init__.assert_called_once_with(C=0.94, gamma=0.1)