Charlie Li
commited on
Commit
·
015a301
1
Parent(s):
0c738cb
pregenerate some samples
Browse files
app.py
CHANGED
@@ -51,6 +51,41 @@ sketches_base64_strings = {
|
|
51 |
name: get_base64_encoded_gif(f"sketches/{name}") for name in sketches
|
52 |
}
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
def demo(Dataset, Model, Output_Format):
|
56 |
if Model == "Small-i":
|
|
|
51 |
name: get_base64_encoded_gif(f"sketches/{name}") for name in sketches
|
52 |
}
|
53 |
|
54 |
+
datasets = ["IAM", "IMGUR5K", "HierText"]
|
55 |
+
models = ["Small-i", "Large-i", "Small-p"]
|
56 |
+
query_modes = ["d+t", "r+d", "vanilla"]
|
57 |
+
|
58 |
+
|
59 |
+
def pregenerate_videos():
|
60 |
+
for Dataset in datasets:
|
61 |
+
for Model in models:
|
62 |
+
inkml_path_base = f"./derendering_supp/{Model.lower()}_{Dataset}_inkml"
|
63 |
+
for mode in query_modes:
|
64 |
+
path = f"./derendering_supp/{Dataset}/images_sample"
|
65 |
+
if not os.path.exists(path):
|
66 |
+
continue
|
67 |
+
samples = os.listdir(path)
|
68 |
+
selected_samples = random.sample(samples, len(samples) // 3)
|
69 |
+
for name in tqdm(
|
70 |
+
selected_samples, desc=f"Generating {Model}-{Dataset}-{mode} videos"
|
71 |
+
):
|
72 |
+
example_id = name.strip(".png")
|
73 |
+
inkml_file = os.path.join(
|
74 |
+
inkml_path_base, mode, f"{example_id}.inkml"
|
75 |
+
)
|
76 |
+
if not os.path.exists(inkml_file):
|
77 |
+
continue
|
78 |
+
video_filename = f"{Model}_{Dataset}_{mode}_{example_id}.mp4"
|
79 |
+
video_filepath = video_cache_dir / video_filename
|
80 |
+
if not video_filepath.exists():
|
81 |
+
img_path = os.path.join(path, name)
|
82 |
+
img = load_and_pad_img_dir(img_path)
|
83 |
+
ink = inkml_to_ink(inkml_file)
|
84 |
+
plot_ink_to_video(ink, str(video_filepath), input_image=img)
|
85 |
+
|
86 |
+
|
87 |
+
pregenerate_videos()
|
88 |
+
|
89 |
|
90 |
def demo(Dataset, Model, Output_Format):
|
91 |
if Model == "Small-i":
|