def test_face_pairs_to_array_with_single_augmenter(dummy_pairs): resolution = (50, 50) a, b = to_array(dummy_pairs, resolution, augmenter=None) assert not np.all(a == 0) assert not np.all(b == 0) a_augmented, b_augmented = \ to_array(dummy_pairs, resolution, augmenter=augmenter) assert np.all(a_augmented == 0) assert np.all(b_augmented == 0)
def test_face_pairs_to_array_with_augmenter_only_first(dummy_pairs): resolution = (50, 50) a, b = to_array(dummy_pairs, resolution, augmenter=None) assert not np.all(a == 0) assert not np.all(b == 0) a_augmented, b_augmented = \ to_array(dummy_pairs, resolution, augmenter=(augmenter, None)) assert np.all(a_augmented == 0) assert np.all(b == b_augmented)
def test_face_images_to_array_with_augmenter(dummy_images): resolution = (50, 50) expected_shape = (len(dummy_images), *reversed(resolution), 3) array = to_array(dummy_images, resolution, augmenter=None) assert array.shape == expected_shape assert not np.all(array == 0) augmented = to_array(dummy_images, resolution, augmenter=augmenter) assert augmented.shape == expected_shape assert np.all(augmented == 0)
def test_face_triplets_to_array_with_augmenter_only_anchor(dummy_triplets): resolution = (50, 50) anchors, positives, negatives = to_array(dummy_triplets, resolution, augmenter=None) assert not np.all(anchors == 0) assert not np.all(positives == 0) assert not np.all(negatives == 0) anchors_augmented, positives_augmented, negatives_augmented = to_array( dummy_triplets, resolution, augmenter=(augmenter, None, None)) assert np.all(anchors_augmented == 0) assert np.all(positives == positives_augmented) assert np.all(negatives == negatives_augmented)
def test_face_triplets_to_array_with_single_augmenter(dummy_triplets): resolution = (50, 50) anchors, positives, negatives = to_array(dummy_triplets, resolution, augmenter=None) assert not np.all(anchors == 0) assert not np.all(positives == 0) assert not np.all(negatives == 0) anchors_augmented, positives_augmented, negatives_augmented = to_array( dummy_triplets, resolution, augmenter=augmenter) assert np.all(anchors_augmented == 0) assert np.all(positives_augmented == 0) assert np.all(negatives_augmented == 0)
def test_face_pairs_to_array_with_augmenters(dummy_pairs): resolution = (50, 50) expected_shape = (len(dummy_pairs), *reversed(resolution), 3) a, b = to_array(dummy_pairs, resolution, augmenter=None) assert a.shape == expected_shape assert b.shape == expected_shape assert not np.all(a == 0) assert not np.all(b == 0) a_augmented, b_augmented = \ to_array(dummy_pairs, resolution, augmenter=(augmenter, augmenter)) assert a_augmented.shape == expected_shape assert b_augmented.shape == expected_shape assert np.all(a_augmented == 0) assert np.all(b_augmented == 0)
def test_face_images_to_array_with_various_resolutions(dummy_images, scratch): face_images = [] for i, dummy_image in enumerate(dummy_images): image = dummy_image.get_image(normalize=False) dimensions = (50 + i, 100) image = cv2.resize(image, dimensions) image_path = os.path.join(scratch, f'tmp_{i}.jpg') cv2.imwrite(image_path, image) face_images.append(FaceImage(image_path, dummy_images[0].identity)) # Should raise an exception, because we do not allow `to_array` to accept # images of various shapes. with pytest.raises(ValueError): to_array(face_images)
def test_face_triplets_to_array(dummy_triplets): resolution = (50, 100) anchors, positives, negatives = to_array(dummy_triplets, resolution=resolution) expected_shape = (len(dummy_triplets), *resolution, 3) assert anchors.shape == expected_shape assert positives.shape == expected_shape assert negatives.shape == expected_shape
def batches(): random.shuffle(triplets) for i in range(0, len(triplets), BATCH_SIZE): batch = triplets[i:i + BATCH_SIZE] if len(batch) != BATCH_SIZE: break x = to_array(batch, resolution=BASE_MODEL.resolution) y = np.zeros(shape=(BATCH_SIZE, 1)) yield x, y
def generator(): while True: data = random.sample(triplets, len(triplets)) for i in range(0, len(data), batch_size): batch = data[i:i + batch_size] inputs = to_array(batch, resolution=self.resolution, normalize=True, augmenter=augmenter) y = np.zeros(shape=(len(batch), 1)) yield inputs, y
def test_face_triplets_to_array_with_augmenters(dummy_triplets): resolution = (50, 50) expected_shape = (len(dummy_triplets), *reversed(resolution), 3) anchors, positives, negatives = to_array(dummy_triplets, resolution, augmenter=None) assert anchors.shape == expected_shape assert positives.shape == expected_shape assert negatives.shape == expected_shape assert not np.all(anchors == 0) assert not np.all(positives == 0) assert not np.all(negatives == 0) anchors_augmented, positives_augmented, negatives_augmented = to_array( dummy_triplets, resolution, augmenter=(augmenter, augmenter, augmenter)) assert anchors_augmented.shape == expected_shape assert positives_augmented.shape == expected_shape assert negatives_augmented.shape == expected_shape assert np.all(anchors_augmented == 0) assert np.all(positives_augmented == 0) assert np.all(negatives_augmented == 0)
def test_face_pairs_to_array(dummy_pairs): resolution = (50, 100) left, right = to_array(dummy_pairs, resolution=resolution) expected_shape = (len(dummy_pairs), *resolution, 3) assert left.shape == expected_shape assert right.shape == expected_shape
def test_zero_face_images_to_array(): with pytest.raises(ValueError): to_array([])
def test_face_images_to_array(dummy_images): resolution = (50, 100) array = to_array(dummy_images, resolution=resolution) assert array.shape == (len(dummy_images), *resolution, 3)