Ejemplo n.º 1
0
def plot_recErr_per_data(task, data_name, maskFlag, epochNums, resultname,
                         color, ax):
    gtpaths = returnGTPaths(task, data_name)
    s0paths = returnS0Paths(task, data_name)

    if maskFlag:
        maskpaths = returnMaskPaths(task, data_name)

    err_perEpoch = []
    for epochNum in epochNums:
        recpaths = returnRecPaths(task, resultname, epochNum, data_name)

        errs = np.empty(0, dtype=np.float32)
        for gtpath in gtpaths:
            s0path = find_same_id_s0(gtpath, s0paths)
            recpath = find_same_id(gtpath, recpaths)

            gt = cv2.imread(str(gtpath), -1).astype(np.float32)
            s0 = cv2.imread(str(s0path), -1).astype(np.float32)
            rec = cv2.imread(str(recpath), -1).astype(np.float32)

            # Calc masks
            noObj_mask = (np.sum(gt, axis=2) > 0)
            s0_mask = (np.sum(s0 / 3, axis=2) > params["s0threshold"])

            # Calc error
            ang_deg = calcAngError(gt, rec)

            # consider mask area
            if maskFlag:
                maskpath = find_same_id(gtpath, maskpaths)
                mask = cv2.imread(str(maskpath), -1).astype(np.float32)

                ang_deg = extractMaskArea(ang_deg, mask, maskFlag)
                noObj_mask = extractMaskArea(noObj_mask, mask, maskFlag)
                s0_mask = extractMaskArea(s0_mask, mask, maskFlag)

            ang_deg = ang_deg[noObj_mask * s0_mask]
            errs = np.append(errs, ang_deg)

        err_perEpoch.append(np.mean(errs))

    ax.plot(epochNums,
            err_perEpoch,
            label=data_name.split("/")[1],
            color=color,
            marker=shape)
    ax.legend(bbox_to_anchor=(1.05, 1), loc="upper left")
    epochNums = returnSortedEpochNum(result_epochs)

    for shape, data_name in zip(shapes, data_names):
        gtpaths = returnGTPaths(task, data_name)
        s0paths = returnS0Paths(task, data_name)

        if maskFlag:
            maskpaths = returnMaskPaths(task, data_name)

        err_perEpoch = []
        for epochNum in epochNums:
            recpaths = returnRecPaths(task, resultname, epochNum, data_name)

            errs = np.empty(0, dtype=np.float32)
            for gtpath in gtpaths:
                s0path = find_same_id_s0(gtpath, s0paths)
                recpath = find_same_id(gtpath, recpaths)

                gt = cv2.imread(str(gtpath), -1).astype(np.float32)
                s0 = cv2.imread(str(s0path), -1).astype(np.float32)
                rec = cv2.imread(str(recpath), -1).astype(np.float32)

                # Calc masks
                noObj_mask = (np.sum(gt, axis=2) > 0)
                s0_mask = (np.sum(s0 / 3, axis=2) > params["s0threshold"])

                # Calc error
                ang_deg = calcAngError(gt, rec)

                # consider mask area
                if maskFlag: