Beispiel #1
0
def load_mpiigaze_train_test_ds_one_eye_leave_one_out(dataset_name,
                                                      person_id,
                                                      batch_size=128,
                                                      grayscale=True,
                                                      val_split=None):
    """
    val_split argument only for consistent function interface
    """
    eye_train, headpose_train, y_train, train_subject_ids = _load_all_people(
        dataset_name, grayscale, person_id)
    eye_test, headpose_test, y_test = _load_one_person(dataset_name, person_id,
                                                       grayscale)

    test_subject_ids = np.asarray([person_id] * len(y_test))

    train_dataset = prepare_dataset((eye_train, headpose_train), y_train,
                                    batch_size)

    # don't shuffle test dataset to have consistent outcomes
    # (when ploting error per person)
    test_dataset = prepare_dataset((eye_test, headpose_test),
                                   y_test,
                                   batch_size,
                                   shuffle=False)

    return train_dataset, test_dataset, test_subject_ids
def load_mpiigaze_train_test_ds_both_leave_one_out_reject_suspicious(
        dataset_name,
        person_id,
        val_split=0.2,
        batch_size=128,
        grayscale=True):
    """
    val_split argument only for consistent function interface
    """
    right_eye_train, left_eye_train, headpose_train, y_train, train_subject_ids = _load_all_people_reject_suspicious(
        dataset_name, grayscale, person_id)
    right_eye_test, left_eye_test, headpose_test, y_test = _load_one_person(
        dataset_name, person_id, grayscale)

    if person_id == 2:
        right_eye_test, left_eye_test, headpose_test, y_test = _filter_subject_02(
            right_eye_test, left_eye_test, headpose_test, y_test)
    if person_id == 10:
        right_eye_test, left_eye_test, headpose_test, y_test = _filter_subject_10(
            right_eye_test, left_eye_test, headpose_test, y_test)

    test_subject_ids = np.asarray([person_id] * len(y_test))

    train_dataset = prepare_dataset(
        (right_eye_train, left_eye_train, headpose_train), y_train, batch_size)
    # don't shuffle test dataset to have consistent outcomes
    test_dataset = prepare_dataset(
        (right_eye_test, left_eye_test, headpose_test),
        y_test,
        batch_size,
        shuffle=False)

    return train_dataset, test_dataset, test_subject_ids
Beispiel #3
0
def load_train_test_ds_reject_suspicious(dataset_name,
                                         person_id,
                                         val_split=0.2,
                                         batch_size=128,
                                         grayscale=True,
                                         all_subjects=None):
    if all_subjects is None:
        all_subjects = list(range(0, 7)) + list(range(8, 15)) + [24, 25]

    test_subject_ids = None
    if person_id is None:
        right_images, left_images, poses, gazes, subject_ids = _load_all_people_reject_suspicious(
            dataset_name, grayscale, subjects=all_subjects)
        (right_eye_train, right_eye_test, left_eye_train, left_eye_test,
         headpose_train, headpose_test, y_train, y_test, train_subject_ids,
         test_subject_ids) = train_test_split(right_images,
                                              left_images,
                                              poses,
                                              gazes,
                                              subject_ids,
                                              test_size=val_split,
                                              random_state=42,
                                              stratify=subject_ids)
    else:
        right_images, left_images, poses, gazes = _load_one_person(
            dataset_name, person_id, grayscale)
        (right_eye_train, right_eye_test, left_eye_train, left_eye_test,
         headpose_train, headpose_test, y_train,
         y_test) = train_test_split(right_images,
                                    left_images,
                                    poses,
                                    gazes,
                                    test_size=val_split,
                                    random_state=42)
        # filter suspicious
        if person_id == 7:
            raise ValueError("Person 7 is rejected.")
        right_images, left_images, poses, gazes = _load_one_person(
            dataset_name, i, grayscale)
        if person_id == 2:
            right_images, left_images, poses, gazes = _filter_subject_02(
                right_images, left_images, poses, gazes)
        if person_id == 10:
            right_images, left_images, poses, gazes = _filter_subject_10(
                right_images, left_images, poses, gazes)

    train_dataset = prepare_dataset(
        (right_eye_train, left_eye_train, headpose_train), y_train, batch_size)
    # don't shuffle test dataset to have consistent outcomes
    test_dataset = prepare_dataset(
        (right_eye_test, left_eye_test, headpose_test),
        y_test,
        batch_size,
        shuffle=False)

    return train_dataset, test_dataset, test_subject_ids
Beispiel #4
0
def load_test_own_mpiigaze_full(dataset_name,
                                person_id,
                                val_split=0.2,
                                batch_size=128,
                                grayscale=True,
                                all_subjects=None):
    if all_subjects is None:
        all_subjects = list(range(0, 7)) + list(range(
            8, 15)) + [24, 25] + list(range(30, 36))

    right_images, left_images, poses, gazes, subject_ids = _load_all_people_reject_suspicious(
        dataset_name, grayscale, subjects=all_subjects)
    indices = np.isin(subject_ids, all_subjects)

    right_images = right_images[indices]
    left_images = left_images[indices]
    poses = poses[indices]
    gazes = gazes[indices]
    test_subject_ids = subject_ids[indices]

    # don't shuffle test dataset to have consistent outcomes
    test_dataset = prepare_dataset((right_images, left_images, poses),
                                   gazes,
                                   batch_size,
                                   shuffle=False)

    return test_dataset, test_subject_ids
Beispiel #5
0
def load_hysts_mpiigaze_train_test_ds(person_id, val_split=0.2, batch_size=128):
    test_subject_ids = None
    if person_id is None:
        images, poses, gazes, subject_ids = _load_all_people()
        (eye_train, eye_test,
         headpose_train, headpose_test,
         y_train, y_test,
         train_subject_ids, test_subject_ids) = train_test_split(images, poses, gazes, subject_ids, test_size=val_split,
                                                                 random_state=42, stratify=subject_ids)
    else:
        images, poses, gazes = _load_one_person(person_id)
        (eye_train, eye_test,
         headpose_train, headpose_test,
         y_train, y_test) = train_test_split(images, poses, gazes, test_size=val_split, random_state=42)

    train_dataset = prepare_dataset((eye_train, headpose_train), y_train, batch_size)
    # don't shuffle test dataset to have consistent outcomes
    test_dataset = prepare_dataset((eye_test, headpose_test), y_test, batch_size, shuffle=False)

    return train_dataset, test_dataset, test_subject_ids
def load_mpiigaze_train_test_ds_both_from_single(dataset_name,
                                                 person_id,
                                                 val_split=0.2,
                                                 batch_size=128,
                                                 grayscale=True):
    test_subject_ids = None
    if person_id is None:
        right_images, left_images, poses, gazes, subject_ids = _load_all_people(
            dataset_name, grayscale)
        (right_eye_train, right_eye_test, left_eye_train, left_eye_test,
         headpose_train, headpose_test, y_train, y_test, train_subject_ids,
         test_subject_ids) = train_test_split(right_images,
                                              left_images,
                                              poses,
                                              gazes,
                                              subject_ids,
                                              test_size=val_split,
                                              random_state=42,
                                              stratify=subject_ids)
    else:
        right_images, left_images, poses, gazes = _load_one_person(
            dataset_name, person_id, grayscale)
        (right_eye_train, right_eye_test, left_eye_train, left_eye_test,
         headpose_train, headpose_test, y_train,
         y_test) = train_test_split(right_images,
                                    left_images,
                                    poses,
                                    gazes,
                                    test_size=val_split,
                                    random_state=42)

    train_dataset = prepare_dataset(
        (right_eye_train, left_eye_train, headpose_train), y_train, batch_size)
    # don't shuffle test dataset to have consistent outcomes
    test_dataset = prepare_dataset(
        (right_eye_test, left_eye_test, headpose_test),
        y_test,
        batch_size,
        shuffle=False)

    return train_dataset, test_dataset, test_subject_ids
def load_test_mpii_face_gaze(dataset_name, person_id, val_split=0.2, batch_size=128,
                                                 grayscale=True, all_subjects=None):
    if all_subjects is None:
        all_subjects = list(range(0, 7)) + list(range(8, 15))

    right_images, left_images, poses, gazes, test_subject_ids = load_all_full_data(dataset_name, grayscale)
    indices = np.isin(test_subject_ids, all_subjects)

    right_images = right_images[indices]
    left_images = left_images[indices]
    poses = poses[indices]
    gazes = gazes[indices]
    test_subject_ids = test_subject_ids[indices]

    # don't shuffle test dataset to have consistent outcomes
    test_dataset = prepare_dataset((right_images, left_images, poses), gazes, batch_size, shuffle=False)

    return test_dataset, test_subject_ids