예제 #1
0
    class input:

        path = DataManager.get_path()

        if os.path.exists(path + 'test_images/'):
            path += 'test_images/'
        else:
            path += 'train_images/'
        print("Path to images: ", path)

        if glob.glob(path+'*.jpeg'):
            tiff_format = False
        else:
            tiff_format = True
        print("Image tiff-format: ", tiff_format)


        tiff_level = 1                   # only if tiff_format is Ture
        resize_ratio = 1                 # 1 (N x N) or 2 (-> N//2 x N//2)
        input_shape = (1280, 1280, 3)
        patch_size = 256
        sample_size = 25
        preprocess_mode = 'float'
        objective = 'bce'
        label_smoothing = 0.0            # only if objective is 'cce'
    img_masked = remove_penmarks(img_path)
    img_masked = Image.fromarray(img_masked)
    #img_masked.save(img_path, subsampling=0, quality=100)


def main(path, marked_images):
    paths = path + marked_images + '.jpeg'
    with multiprocessing.Pool() as pool:
        for c in tqdm.tqdm(pool.imap(save_masked_image, paths),
                           total=len(paths)):
            pass


if __name__ == '__main__':
    marked_images = np.load('input_/marked_images.npy', allow_pickle=True)
    path = DataManager.get_path() + 'train_images/'
    print(
        f"[Old] images with marks in {path} ({len(marked_images)} of them) "
        "will be overwritten by the newly generated images (with marks removed)\n"
        "Are you sure you want to continue? (y/n)")
    c = input()

    if c.lower() == 'y' or c.lower() == 'yes':
        if Config.input.tiff_format:
            print("Requires images to be .jpeg format")
            print("Script cancelled")
        else:
            main(path, marked_images)
    else:
        print("Script cancelled")