def evaluate_valid(data_op=1, op=1, reduction=1, rate=0.2):
    """
    评估函数,在三个数据集上进行评估
    :param op: 1-all 2-part
    :param data_op: 1-CK 2-Fer 3-Jaffe
    :return:
    """
    import preprocess
    from tqdm import tqdm
    from data import CK, Fer2013, Jaffe

    filters = Gabor().build_filters()
    if data_op == 1:
        _, x, y = CK().gen_train_no()
    if data_op == 2:
        _, x, y = Fer2013().gen_train_no()
    if data_op == 3:
        _, x, y = Jaffe().gen_train_no()
    train = []
    if op == 1:
        for i in tqdm(np.arange(0, x.shape[0], 1)):
            x[i] = preprocess.gray_norm(x[i])
            x[i] = preprocess.adaptive_histogram_equalization(x[i])
            res = Gabor().getGabor(x[i], filters, False, reduction)
            res = np.array(res).reshape(-1)
            res = np.append(res, y[i])
            train.append(res)
        train = np.array(train)

    if data_op != 2:
        # 需要划分
        from sklearn.model_selection import train_test_split
        x_train, x_test, y_train, y_test = train_test_split(train, train, random_state=2019, test_size=rate)
        Classifier().SVM(x_train, x_test)
    test1 = []
    test2 = []
    if data_op == 2:
        _, x, y = Fer2013().gen_valid_no(1)
        for i in tqdm(np.arange(0, x.shape[0], 1)):
            x[i] = preprocess.gray_norm(x[i])
            x[i] = preprocess.adaptive_histogram_equalization(x[i])
            res = Gabor().getGabor(x[i], filters, False, reduction)
            res = np.array(res).reshape(-1)
            res = np.append(res, y[i])
            test1.append(res)

        _, x, y = Fer2013().gen_valid_no(2)
        for i in tqdm(np.arange(0, x.shape[0], 1)):
            x[i] = preprocess.gray_norm(x[i])
            x[i] = preprocess.adaptive_histogram_equalization(x[i])
            res = Gabor().getGabor(x[i], filters, False, reduction)
            res = np.array(res).reshape(-1)
            res = np.append(res, y[i])
            test2.append(res)
        test1 = np.array(test1)
        test2 = np.array(test2)
        print("Public")
        Classifier().SVM(train, test1)
        print("Pirvate")
        Classifier().SVM(train, test2)
def evaluate1_lbp():
    filters = Gabor().build_filters()
    from tqdm import tqdm
    from data import CK, Fer2013, Jaffe
    _, x, y = Fer2013().gen_train_no()
    train = []
    for i in tqdm(np.arange(0, x.shape[0], 1)):
        res = LBP().get_lbp(x[i])
        res = np.array(res).reshape(-1)
        res = np.append(res, y[i])
        train.append(res)
    train = np.array(train)

    test = []
    _, x, y = Jaffe().gen_train_no()
    for i in tqdm(np.arange(0, x.shape[0], 1)):
        res = LBP().get_lbp(x[i])
        res = np.array(res).reshape(-1)
        res = np.append(res, y[i])
        test.append(res)
    test = np.array(train)
    Classifier().SVM(train, test)

    test = []
    _, x, y = CK().gen_train_no()
    for i in tqdm(np.arange(0, x.shape[0], 1)):
        x[i] = preprocess.gray_norm(x[i])
        x[i] = preprocess.adaptive_histogram_equalization(x[i])
        res = Gabor().getGabor(x[i], filters, False, 6)
        res = np.array(res).reshape(-1)
        res = np.append(res, y[i])
        test.append(res)
    test = np.array(train)
    Classifier().SVM(train, test)
def evaluate_lbp(data_op=1, op=1, reduction=1, rate=0.2):
    """
    评估函数,在三个数据集上进行评估
    :param op: 1-all 2-part
    :param data_op: 1-CK 2-Fer 3-Jaffe
    :return:
    """
    filters = Gabor().build_filters()
    from tqdm import tqdm
    from data import CK, Fer2013, Jaffe
    _, x, y = CK().gen_train_no()
    if data_op == 2:
        _, x, y = Fer2013().gen_train_no()
    if data_op == 3:
        _, x, y = Jaffe().gen_train_no()
    train = []
    if op == 1:
        for i in tqdm(np.arange(0, x.shape[0], 1)):
            x[i] = preprocess.gray_norm(x[i])
            x[i] = preprocess.adaptive_histogram_equalization(x[i])
            res = Gabor().getGabor(x[i], filters, False, reduction)
            res = np.array(res).reshape(-1)
            res = np.append(res, y[i])
            train.append(res)
        train = np.array(train)
    if op == 2:
        for i in tqdm(np.arange(0, x.shape[0], 1)):
            img, dets, shape_list, img_list, pt_post_list = preprocess.deal(
                x[i])
            res1 = Gabor().getGabor(img, filters, 0, 1)
            res1 = np.array(res1)
            res = []
            if len(shape_list) == 0:
                continue
            for _, pt in enumerate(shape_list[0].parts()):
                px, py = min(max(pt.x, 0), 47), min(max(pt.y, 0), 47)
                im = res1[0]
                cv2.circle(im, (px, py), 2, (255, 0, 0), 1)
                res.append(res1[:, px, py])
            res = np.array(res)
            res = np.append(res, y[i])
            train.append(res)
        train = np.array(train)
    if op == 3:
        for i in tqdm(np.arange(0, x.shape[0], 1)):
            res = LBP().get_lbp(x[i])
            res = np.array(res).reshape(-1)
            res = np.append(res, y[i])
            train.append(res)
        train = np.array(train)
    if data_op != 2:
        from sklearn.model_selection import train_test_split
        x_train, x_test, y_train, y_test = train_test_split(train,
                                                            train,
                                                            random_state=2019,
                                                            test_size=rate)
        Classifier().SVM(x_train, x_test)
    test1 = []
    test2 = []
    if data_op == 2:
        _, x, y = Fer2013().gen_valid_no(1)
        for i in tqdm(np.arange(0, x.shape[0], 1)):
            res = LBP().get_lbp(x[i])
            res = np.array(res).reshape(-1)
            res = np.append(res, y[i])
            test1.append(res)

        _, x, y = Fer2013().gen_valid_no(2)
        for i in tqdm(np.arange(0, x.shape[0], 1)):
            res = LBP().get_lbp(x[i])
            res = np.array(res).reshape(-1)
            res = np.append(res, y[i])
            test2.append(res)
        test1 = np.array(test1)
        test2 = np.array(test2)
        print("Public")
        Classifier().SVM(train, test1)
        print("Pirvate")
        Classifier().SVM(train, test2)