示例#1
0
 def test_predict_return_data_types(self):
     self.test_engine.fit([self.bubbles1], [0])
     image = imread(self.bubbles1)
     bbs, extra = self.test_engine.find_faces(image, limit=1)
     embeddings = self.test_engine.compute_embeddings(image, bbs, **extra)
     data = self.test_engine.predict(embeddings)
     self.assertEqual(len(data), 2)
     self.assertIsInstance(data, tuple)
     self.assertIsInstance(data[0], list)
     self.assertIsInstance(data[1], list)
示例#2
0
def get_face_dataset(dir, engine, shuffle=False):
    """Generator of FaceImages"""
    from face_engine.exceptions import FaceNotFoundError
    from face_engine.tools import imread
    dataset = get_image_dataset(dir, shuffle)
    if shuffle:
        np.random.shuffle(dataset)
    for image in dataset:
        bounding_boxes = []
        embeddings = []
        image_paths = image.image_paths
        for i, image_path in enumerate(image_paths):
            img = imread(image_path)
            try:
                bounding_box = engine.find_face(img)[1]
                bounding_boxes.append(bounding_box)
                embeddings.append(engine.compute_embedding(img, bounding_box))
            except FaceNotFoundError:
                del image_paths[i]
                continue
        yield FaceImage(image.name, image_paths, bounding_boxes, embeddings)
示例#3
0
 def test_compute_embeddings_vector_dimension(self):
     bubbles1 = imread(self.bubbles1)
     bbs, _ = self.test_engine.find_faces(bubbles1)
     embeddings = self.test_engine.compute_embeddings(bubbles1, bbs)
     self.assertEqual(embeddings.size,
                      self.test_engine._embedder.embedding_dim)
示例#4
0
 def test_find_faces_with_image_content(self):
     content = imread(self.family)
     data = self.test_engine.find_faces(content)
     self.assertIsNotNone(data)
示例#5
0
 def test_predict_before_fit_raises_train_error(self):
     image = imread(self.bubbles1)
     bbs, extra = self.test_engine.find_faces(image)
     embeddings = self.test_engine.compute_embeddings(image, bbs, **extra)
     with self.assertRaises(TrainError):
         self.test_engine.predict(embeddings)
 def setUp(self):
     self.image = imread(self.bubbles1)
     self.bbs = np.array([[278, 132, 618, 471]])
     self.embedder = Embedder()
 def test_detect_raises_face_not_found_error(self):
     with self.assertRaises(FaceNotFoundError):
         self.detector.detect(imread(self.book_stack))
 def test_detect_return_multiple_bbs(self):
     bbs, _ = self.detector.detect(imread(self.family))
     self.assertGreater(len(bbs), 1)
 def test_detect_return_bbs_type(self):
     bbs, _ = self.detector.detect(imread(self.bubbles1))
     self.assertIsInstance(bbs, np.ndarray)
 def test_detect_return_data_is_tuple(self):
     data = self.detector.detect(imread(self.bubbles1))
     self.assertIsNotNone(data)