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")
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title("Reconstruction Error per Epoch", fontsize=16)
ax.set_xlabel("epoch num", fontsize=12)
ax.set_ylabel("error [deg]", fontsize=12)
ax.set_xlim(0, epochLim)

for color, resultname, label in zip(colors, resultnames, labels):
    result_epochs = [
        n.name for n in pathlib.Path("../{}/Result/{}/Model/".format(
            task, resultname)).iterdir()
    ]
    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)
Ejemplo n.º 3
0
from mymodules.myutils.imageutils import MAX_16BIT
import mymodules.myutils.mplutils as myplt

# load Params
#------------------------
with open("./parameters_visualize.yml") as f:
    params = yaml.load(f)["recError_per_image"]

task = params["task"]
gtfolder = params["gtfolder"]
resultname = params["resultname"]
epochnum = params["epochnum"]
maskFlag = params["maskFlag"]
saveFlag = params["saveFlag"]

gtpaths = returnGTPaths(task, gtfolder)
s0paths = returnS0Paths(task, gtfolder)
recpaths = returnRecPaths(task, resultname, epochnum, gtfolder)

if saveFlag:
    savefile = pathlib.Path("../{}/Result/{}/Inference/epoch-{}/{}/{}".format(
        task, resultname, epochnum, gtfolder, saveFlag))
    savefile.mkdir()

if maskFlag:
    raise ValueError("maskFlag shoud be False")

# main process
#------------------------
x, y = [], []  # for plot scatter graph
for gtpath in gtpaths: