Exemplo n.º 1
0
def evaluate_crf(model, x_data, y_data):
    total = []
    for x, y in tqdm(zip(x_data, y_data), total=len(x_data)):
        x = read_image(x)
        y = read_mask(y)
        y_pred = model.predict(x)[0]  #  > THRESHOLD
        y_pred = y_pred.astype(np.float32)
        y_pred = apply_crf(x[0] * 255, y_pred)
        total.append(y_pred)
    return np.array(total)
def evaluate_crf(model, x_data, y_data):
    total = []
    for x, y in tqdm(zip(x_data, y_data), total=len(x_data)):
        x = read_image(x)
        y = read_mask(y)
        y_pred = model.predict(x)[0] > 0.5
        y_pred = y_pred.astype(np.float32)
        y_pred = apply_crf(x[0]*255, y_pred)

        value = get_metrics(y, y_pred)
        total.append(value)

    mean_value = np.mean(total, axis=0)
    print(mean_value)
def save_images(model, x_data, y_data):
    for i, (x, y) in tqdm(enumerate(zip(x_data, y_data)), total=len(x_data)):
        x = read_image(x)
        y = read_mask(y)

        ## Prediction
        y_pred_baseline = model.predict(x)[0] > 0.5
        y_pred_crf = apply_crf(x[0] * 255, y_pred_baseline.astype(np.float32))
        y_pred_tta = tta_model(model, x[0]) > 0.5
        y_pred_tta_crf = apply_crf(x[0] * 255, y_pred_tta.astype(np.float32))

        y_pred_crf = np.expand_dims(y_pred_crf, axis=-1)
        y_pred_tta_crf = np.expand_dims(y_pred_tta_crf, axis=-1)

        sep_line = np.ones((256, 10, 3)) * 255

        ## MeanIoU
        miou_baseline = get_mean_iou(y, y_pred_baseline)
        miou_crf = get_mean_iou(y, y_pred_crf)
        miou_tta = get_mean_iou(y, y_pred_tta)
        miou_tta_crf = get_mean_iou(y, y_pred_tta_crf)

        print(miou_baseline, miou_crf, miou_crf, miou_tta_crf)

        y1 = mask_to_3d(y) * 255
        y2 = mask_to_3d(y_pred_baseline) * 255.0
        y3 = mask_to_3d(y_pred_crf) * 255.0
        y4 = mask_to_3d(y_pred_tta) * 255.0
        y5 = mask_to_3d(y_pred_tta_crf) * 255.0

        # y2 = cv2.putText(y2, str(miou_baseline), (0, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 1)

        all_images = [
            x[0] * 255, sep_line, y1, sep_line, y2, sep_line, y3, sep_line, y4,
            sep_line, y5
        ]
        cv2.imwrite(f"results/{i}.png", np.concatenate(all_images, axis=1))
Exemplo n.º 4
0
        with torch.no_grad():
            # Start time
            start_time = time.time()

            ## Prediction
            pred_y, pred_m = model(image)
            pred_y = torch.sigmoid(pred_y)
            pred_m = torch.sigmoid(pred_m)
            mask = pred_y

            # End timer
            end_time = time.time() - start_time

            time_taken.append(end_time)
            print("{} - {:.10f}".format(image_name, end_time))

            mask = mask[0].cpu().numpy()
            mask = np.squeeze(mask, axis=0)
            mask = mask > 0.5
            mask = mask.astype(np.float32)
            mask = cv2.resize(mask, (W, H))
            mask = apply_crf(ori_image, mask)
            mask = mask * 255.0

            mask_path = os.path.join(MASK_PATH, image_name)
            cv2.imwrite(mask_path, mask)

    mean_time_taken = np.mean(time_taken)
    mean_fps = 1 / mean_time_taken
    print("Mean FPS: ", mean_fps)
Exemplo n.º 5
0
import argparse
from scipy import misc
import caffe
import tempfile
from math import ceil

parser = argparse.ArgumentParser()
parser.add_argument('listfile', help='one line should contain paths "img0.ext img1.ext gt.flo out.flo"')

args = parser.parse_args()

if(not os.path.exists(args.listfile)): raise BaseException('listfile does not exist: '+args.listfile)

def readTupleList(filename):
    list = []
    for line in open(filename).readlines():
        if line.strip() != '':
            list.append(line.split())

    return list

ops = readTupleList(args.listfile)

for ent in ops:
    fn_img = ent[0]
    fn_flo = ent[3]
    fn_out = fn_flo[:fn_flo.rindex('.')] + '_crf.flo'
    crf_flo = apply_crf(fn_img, fn_flo)
    write_flow(fn_out, crf_flo)
    print("Wrote to: " + fn_out)