コード例 #1
0
    def test_split_classes(self):
        data = FaceDataset()
        data.read_dataset('tests/fixtures/faces/same_faces')
        data1, data2 = data.split_classes()

        self.assertEqual(data.classes_length,
                         data1.classes_length + data2.classes_length)
コード例 #2
0
    def test_get_embeddings(self):
        data = FaceDataset()
        data.read_dataset('tests/fixtures/faces/same_faces')
        X, y = data.get_embeddings()

        self.assertTrue(isinstance(X, np.ndarray))
        self.assertEqual(X.shape[0], y.shape[0])
コード例 #3
0
    def test_save(self):
        data = FaceDataset()
        data.read_dataset('tests/fixtures/faces/newdata')

        data.save('tests/fixtures/faces/newdata/newdata.pkl')
        self.assertTrue(
            os.path.exists('tests/fixtures/faces/newdata/newdata.pkl'))
コード例 #4
0
    def test_split_instances_of_classes(self):
        data = FaceDataset()
        data.read_dataset('tests/fixtures/faces/newdata')
        data1, data2 = data.split_instances_of_classes()

        self.assertEqual(data1.classes_length, data2.classes_length)
        for cls, images in data.items():
            self.assertEqual(data[cls].length,
                             data1[cls].length + data2[cls].length)
コード例 #5
0
 def test_load(self):
     data = FaceDataset()
     data.read_dataset('tests/fixtures/faces/newdata')
     data.save('tests/fixtures/faces/newdata/newdata.pkl')
     new_data = FaceDataset.load('tests/fixtures/faces/newdata/newdata.pkl')
     self.assertEqual(data.classes_length, new_data.classes_length)
     for cls in data.get_classes():
         self.assertTrue(cls in new_data.get_classes())
         self.assertEqual(data[cls].length, new_data[cls].length)
コード例 #6
0
    def setUp(self):
        data1 = FaceDataset()
        data1.read_dataset('tests/fixtures/faces/same_faces')

        data2 = FaceDataset()
        data2.read_dataset('tests/fixtures/faces/newdata')

        data1.append(data2)
        data1.save(os.path.join('tests/fixtures/faces/testset.pkl'))
コード例 #7
0
    def test_unknown_dataset(self):
        data = FaceDataset()
        data.read_dataset('tests/fixtures/faces/same_faces')
        unk_data = data.create_unknown_class()
        self.assertEqual(unk_data.classes_length, 1)
        self.assertTrue(Config.UNKNOWN_TAG in unk_data.dataset)

        s = 0
        for _, images in unk_data.items():
            s += images.length

        self.assertEqual(unk_data[Config.UNKNOWN_TAG].length, s)
コード例 #8
0
 def test_read_dataset(self):
     data = FaceDataset()
     data.read_dataset('tests/fixtures/faces/same_faces')
     self.assertEqual(data.classes_length, 150)
     self.assertEqual(data['George_W_Bush'].length, 26)
コード例 #9
0
    parser.add_argument("-o",
                        "--output",
                        dest="output",
                        help="Path to the output folder.")
    parser.add_argument("-n",
                        "--n_clusters",
                        type=int,
                        help="Number of clusters for hierarchical clustering.")
    parser.add_argument("--analyze",
                        action='store_true',
                        help="Print clustering details.")

    args = parser.parse_args()
    logger.info(sys.argv)

    all_data = FaceDataset()
    all_data.read_dataset(args.input)

    clustering_algo = get_dbscan() if not hasattr(
        args, 'n_clusters') or not args.n_clusters else get_hierarchical(
            args.n_clusters)

    time_start = time.time()
    labels = clustering(all_data, clustering_algo, args.analyze)
    time_end = time.time()

    logger.info('The clustering took {:.3f} ms'.format(
        (time_start - time_end) * 1000.0))

    write_clusters(args.output, all_data, labels)