コード例 #1
0
def main():
    data_path = '../../databases'
    PlotsDirectory = '../plots/Week3/task1/'

    if not os.path.exists(PlotsDirectory):
        os.makedirs(PlotsDirectory)

    names = ['highway', 'fall', 'traffic']
    estimation_range = [np.array([1050, 1200]), np.array([1460, 1510]), np.array([950, 1000])]
    prediction_range = [np.array([1201, 1350]), np.array([1511, 1560]), np.array([1001, 1050])]
    #alpha = [{'min': 4, 'max': 20, 'step': 1.5}, {'min': 1, 'max': 10, 'step': 1}, {'min': 1, 'max': 20, 'step': 1.5}]
    #ro = [{'min': 1, 'max': 10, 'step': 1}, {'min': 1, 'max': 10, 'step': 1}, {'min': 1, 'max': 10, 'step': 1}]

    params = { 'highway': {'alpha': 2.89, 'rho': 0.21},
               'fall': {'alpha': 3.2, 'rho': 0.05},
               'traffic': {'alpha': 3.55, 'rho': 0.16}}

    for i in range(len(names)):
        [X_est, y_est] = load_data(data_path, names[i], estimation_range[i], grayscale=True)
        [X_pred, y_pred] = load_data(data_path, names[i], prediction_range[i], grayscale=True)


        masks = task4(X_est, X_pred, params['traffic']['rho'], params['traffic']['alpha'], True)
        masksno = task4(X_est, X_pred, params['traffic']['rho'], params['traffic']['alpha'], False)

        print(names[i] + ": F1 score with shadow = " + str(evaluate(masks, y_pred, 'f1')))
        print(names[i] + ": F1 score without shadow = " + str(evaluate(masksno, y_pred, 'f1')))
コード例 #2
0
ファイル: task2.py プロジェクト: Ivancaminal72/mcv-m6
def compute_AUC(X_est, X_pred, y_pred, alpha_range, rho, pixels):
    Pr = []
    Re = []
    for alpha in alpha_range:
        #print(alpha)
        X_res = task2(X_est, X_pred, rho, alpha, pixels)
        Pr.append(evaluate(X_res, y_pred, "precision"))
        Re.append(evaluate(X_res, y_pred, "recall"))

    return metrics.auc(Re, Pr, True)
コード例 #3
0
ファイル: task5.py プロジェクト: Ivancaminal72/mcv-m6
                                          metric="precision")
            estR_w2 = EstimatorAdaptative(alpha=alpha,
                                          rho=rho[i],
                                          metric="recall")
            estP_w2.fit(X_est)
            estR_w2.fit(X_est)
            X_res_A = task3(X_est, X_pred, rho[i], alpha, True)
            X_res_B = task3(X_est, X_pred, rho[i], alpha, False)
            X_res_h4, _ = task1(X_est, X_pred, rho[i], alpha, connectivity=4)
            X_res_t2 = task2(X_est, X_pred, rho[i], alpha, pixels[i])
            X_res_sh_A = task4(X_est, X_pred, rho[i], alpha, True)
            X_res_sh_B = task4(X_est, X_pred, rho[i], alpha, False)

            Pr_w2.append(estP_w2.score(y_pred, X=X_pred))
            Re_w2.append(estR_w2.score(y_pred, X=X_pred))
            Pr_h4.append(evaluate(X_res_h4, y_pred, "precision"))
            Re_h4.append(evaluate(X_res_h4, y_pred, "recall"))
            Pr_A.append(evaluate(X_res_A, y_pred, "precision"))
            Re_A.append(evaluate(X_res_A, y_pred, "recall"))
            Pr_B.append(evaluate(X_res_B, y_pred, "precision"))
            Re_B.append(evaluate(X_res_B, y_pred, "recall"))
            Pr_t2.append(evaluate(X_res_t2, y_pred, "precision"))
            Re_t2.append(evaluate(X_res_t2, y_pred, "recall"))
            Pr_sh_A.append(evaluate(X_res_sh_A, y_pred, "precision"))
            Re_sh_A.append(evaluate(X_res_sh_A, y_pred, "recall"))
            Pr_sh_B.append(evaluate(X_res_sh_B, y_pred, "precision"))
            Re_sh_B.append(evaluate(X_res_sh_B, y_pred, "recall"))

        np.save(PlotsDirectory + names[i] + '_Pr_w2.npy', Pr_w2)
        np.save(PlotsDirectory + names[i] + '_Re_w2.npy', Re_w2)
        np.save(PlotsDirectory + names[i] + '_Pr_h4.npy', Pr_h4)
コード例 #4
0
ファイル: task1_AUC.py プロジェクト: Ivancaminal72/mcv-m6
                               estimation_range[i],
                               grayscale=True)
    [X_pred, y_pred] = load_data(data_path,
                                 names[i],
                                 prediction_range[i],
                                 grayscale=True)

    alpha_range = np.arange(a[i].get('min'), a[i].get('max'), a[i].get('step'))

    for idx, alpha in enumerate(alpha_range):
        print(str(idx) + "/" + str(len(alpha_range)) + " " + str(alpha))
        X_res_h4, _ = task1(X_est, X_pred, rho[i], alpha, connectivity=4)
        X_res_h8, _ = task1(X_est, X_pred, rho[i], alpha, connectivity=8)

        if doROC:
            FPR_h4.append(evaluate(X_res_h4, y_pred, "fpr"))
            TPR_h4.append(evaluate(X_res_h4, y_pred, "tpr"))
            FPR_h8.append(evaluate(X_res_h8, y_pred, "fpr"))
            TPR_h8.append(evaluate(X_res_h8, y_pred, "tpr"))
        else:
            Pr_h4.append(evaluate(X_res_h4, y_pred, "precision"))
            Re_h4.append(evaluate(X_res_h4, y_pred, "recall"))
            Pr_h8.append(evaluate(X_res_h8, y_pred, "precision"))
            Re_h8.append(evaluate(X_res_h8, y_pred, "recall"))

    plt.figure()

    if doROC:
        line4, = plt.plot(np.array(FPR_h4),
                          np.array(TPR_h4),
                          'b',
コード例 #5
0
def main():
    data_path = '../../databases'
    PlotsDirectory = '../plots/Week3/task3/'

    if not os.path.exists(PlotsDirectory):
        os.makedirs(PlotsDirectory)

    names = ['highway', 'fall', 'traffic']
    estimation_range = [
        np.array([1050, 1200]),
        np.array([1460, 1510]),
        np.array([950, 1000])
    ]
    prediction_range = [
        np.array([1201, 1350]),
        np.array([1511, 1560]),
        np.array([1001, 1050])
    ]

    a = [{
        'min': 0,
        'max': 40,
        'step': 1
    }, {
        'min': 0,
        'max': 40,
        'step': 1
    }, {
        'min': 0,
        'max': 40,
        'step': 1
    }]

    params = {
        'highway': {
            'alpha': 7.25,
            'rho': 0.6
        },
        'fall': {
            'alpha': 3.2,
            'rho': 0.004
        },
        'traffic': {
            'alpha': 10.67,
            'rho': 0
        }
    }

    n_pixels = 20
    for i in range(len(names)):
        #i = 0
        [X_est, y_est] = load_data(data_path,
                                   names[i],
                                   estimation_range[i],
                                   grayscale=True)
        [X_pred, y_pred] = load_data(data_path,
                                     names[i],
                                     prediction_range[i],
                                     grayscale=True)

        mask3 = task3(X_est, X_pred, params[names[i]]['rho'],
                      params[names[i]]['alpha'], True)
        maskno3 = task3(X_est, X_pred, params[names[i]]['rho'],
                        params[names[i]]['alpha'], False)
        print(names[i] + ": F1 score new = " +
              str(evaluate(mask3, y_pred, 'f1')))
        print(names[i] + ": F1 score past = " +
              str(evaluate(maskno3, y_pred, 'f1')))

        pr = evaluate(mask3, y_pred, "precision")
        re = evaluate(mask3, y_pred, "recall")

        pr_no = evaluate(maskno3, y_pred, "precision")
        re_no = evaluate(maskno3, y_pred, "recall")