Exemple #1
0
def test_load_lfw_pairs():
    if not os.path.exists(os.path.join(get_data_home(), 'lfw_home')):
        raise SkipTest

    lfw_pairs_train = load_lfw_pairs(subset='train')

    # this dataset is used for training supervised face verification models,
    # this is a binary classification task
    top_classes = ['Different persons', 'Same person']
    assert_array_equal(lfw_pairs_train.target_names, top_classes)

    # default slice is a rectangular shape around the face, removing
    # most of the background, for each of the 2 face pictures
    assert_equal(lfw_pairs_train.data.shape, (2200, 2, 62, 47))

    # the ordering is respecting the metadata text file of the official LFW
    # tasks
    assert_equal(lfw_pairs_train.target.shape, (2200, ))
    assert_array_equal(lfw_pairs_train.target[:5], [1, 1, 1, 1, 1])
    assert_array_equal(lfw_pairs_train.target[-5:], [0, 0, 0, 0, 0])

    # as for the people loader it is also possible to load the color channels
    # in the last dimension
    lfw_pairs_train = load_lfw_pairs(subset='train', color=True)
    assert_equal(lfw_pairs_train.data.shape, (2200, 2, 62, 47, 3))

    # the data also has a test development set and a 10-fold CV dataset for
    # final evaluation
    lfw_pairs_test = load_lfw_pairs(subset='test')
    assert_equal(lfw_pairs_test.data.shape, (1000, 2, 62, 47))

    lfw_pairs_10_folds = load_lfw_pairs(subset='10_folds')
    assert_equal(lfw_pairs_10_folds.data.shape, (6000, 2, 62, 47))
Exemple #2
0
def test_load_fake_lfw_pairs():
    lfw_pairs_train = load_lfw_pairs(data_home=SCIKIT_LEARN_DATA)

    # The data is croped around the center as a rectangular bounding box
    # arounthe the face. Colors are converted to gray levels:
    assert_equal(lfw_pairs_train.data.shape, (10, 2, 62, 47))

    # the target is whether the person is the same or not
    assert_array_equal(lfw_pairs_train.target, [1, 1, 1, 1, 1, 0, 0, 0, 0, 0])

    # names of the persons can be found using the target_names array
    expected_classes = ['Different persons', 'Same person']
    assert_array_equal(lfw_pairs_train.target_names, expected_classes)

    # It is possible to ask for the original data without any croping or color
    # conversion
    lfw_pairs_train = load_lfw_pairs(data_home=SCIKIT_LEARN_DATA,
                                     resize=None,
                                     slice_=None,
                                     color=True)
    assert_equal(lfw_pairs_train.data.shape, (10, 2, 250, 250, 3))

    # the ids and class names are the same as previously
    assert_array_equal(lfw_pairs_train.target, [1, 1, 1, 1, 1, 0, 0, 0, 0, 0])
    assert_array_equal(lfw_pairs_train.target_names, expected_classes)
Exemple #3
0
def test_load_lfw_pairs():
    if not os.path.exists(os.path.join(get_data_home(), 'lfw_home')):
        raise SkipTest

    lfw_pairs_train = load_lfw_pairs(subset='train')

    # this dataset is used for training supervised face verification models,
    # this is a binary classification task
    top_classes = ['Different persons', 'Same person']
    assert_array_equal(lfw_pairs_train.target_names, top_classes)

    # default slice is a rectangular shape around the face, removing
    # most of the background, for each of the 2 face pictures
    assert_equal(lfw_pairs_train.data.shape, (2200, 2, 62, 47))

    # the ordering is respecting the metadata text file of the official LFW
    # tasks
    assert_equal(lfw_pairs_train.target.shape, (2200,))
    assert_array_equal(lfw_pairs_train.target[:5], [1, 1, 1, 1, 1])
    assert_array_equal(lfw_pairs_train.target[-5:], [0, 0, 0, 0, 0])

    # as for the people loader it is also possible to load the color channels
    # in the last dimension
    lfw_pairs_train = load_lfw_pairs(subset='train', color=True)
    assert_equal(lfw_pairs_train.data.shape, (2200, 2, 62, 47, 3))

    # the data also has a test development set and a 10-fold CV dataset for
    # final evaluation
    lfw_pairs_test = load_lfw_pairs(subset='test')
    assert_equal(lfw_pairs_test.data.shape, (1000, 2, 62, 47))

    lfw_pairs_10_folds = load_lfw_pairs(subset='10_folds')
    assert_equal(lfw_pairs_10_folds.data.shape, (6000, 2, 62, 47))
Exemple #4
0
def test_load_fake_lfw_pairs():
    lfw_pairs_train = load_lfw_pairs(data_home=SCIKIT_LEARN_DATA)

    # The data is croped around the center as a rectangular bounding box
    # arounthe the face. Colors are converted to gray levels:
    assert_equal(lfw_pairs_train.data.shape, (10, 2, 62, 47))

    # the target is whether the person is the same or not
    assert_array_equal(lfw_pairs_train.target, [1, 1, 1, 1, 1, 0, 0, 0, 0, 0])

    # names of the persons can be found using the target_names array
    expected_classes = ['Different persons', 'Same person']
    assert_array_equal(lfw_pairs_train.target_names, expected_classes)

    # It is possible to ask for the original data without any croping or color
    # conversion
    lfw_pairs_train = load_lfw_pairs(data_home=SCIKIT_LEARN_DATA,
                                     resize=None, slice_=None, color=True)
    assert_equal(lfw_pairs_train.data.shape, (10, 2, 250, 250, 3))

    # the ids and class names are the same as previously
    assert_array_equal(lfw_pairs_train.target, [1, 1, 1, 1, 1, 0, 0, 0, 0, 0])
    assert_array_equal(lfw_pairs_train.target_names, expected_classes)
Exemple #5
0
def test_load_empty_lfw_pairs():
    lfw_people = load_lfw_pairs(data_home=SCIKIT_LEARN_EMPTY_DATA)
Exemple #6
0
def test_load_empty_lfw_pairs():
    lfw_people = load_lfw_pairs(data_home=SCIKIT_LEARN_EMPTY_DATA)