Ejemplo n.º 1
0
print(
    f'Starting postprocessing of {batch_name} with parameter set {param_set_name}...'
)
for f in os.listdir(path_to_test_preds):
    if count == config.POST_MAX_NUM_IMAGES_TOPROCESS:
        break
    ext = os.path.splitext(f)[1]
    if ext.lower() != '.png':
        continue
    pred_img = Image.open(os.path.join(path_to_test_preds, f))
    pred_arr = util.to_array(pred_img)

    id = get_id_from_filename(f)
    img = Image.open(path_to_test_imgs + f'test_{id}.png')
    img_arr = np.asarray(img)

    if config.POST_DO_CRFPROCESSING:
        print(f'  processing {f}...')
        processed_pred = post.crf(img_arr, pred_arr)

        # add to submission
        if config.POST_WRITE_SUBMISSION:
            submission.add(prediction=processed_pred, img_id=id)
        else:
            processed_img = util.to_image(processed_pred)
            processed_img.save(out_dir + f'post_{id}.png')
        count += 1

print(f'Postprocessing finished (processed {count} predictions)')
if config.POST_WRITE_SUBMISSION:
    submission.write()