Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
5647d41
1
Parent(s):
a4f1fc6
Simplified inference
Browse files
app.py
CHANGED
@@ -39,7 +39,7 @@ torch.backends.cudnn.allow_tf32 = True
|
|
39 |
# Global no_grad
|
40 |
torch.set_grad_enabled(False)
|
41 |
|
42 |
-
|
43 |
MAX_SEED = np.iinfo(np.int32).max
|
44 |
|
45 |
MODEL_ID = 'EPFL-VILAB/flextok_d18_d28_dfn'
|
@@ -79,12 +79,10 @@ def infer(img_path, seed=0, randomize_seed=False, timesteps=20, cfg_scale=7.5, p
|
|
79 |
|
80 |
# Tokenize images once
|
81 |
with get_bf16_context(enable_bf16):
|
82 |
-
|
83 |
|
84 |
# Create all token subsequences
|
85 |
-
|
86 |
-
tokens_list = tokens_list*len(k_keep_list)
|
87 |
-
subseq_list = [seq[:,:k_keep].clone() for seq, k_keep in zip(tokens_list, k_keep_list)]
|
88 |
|
89 |
# Detokenize various subsequences in parallel. Batch size is 9.
|
90 |
with get_bf16_context(enable_bf16):
|
@@ -98,7 +96,7 @@ def infer(img_path, seed=0, randomize_seed=False, timesteps=20, cfg_scale=7.5, p
|
|
98 |
# Transform to PIL images
|
99 |
all_images = [
|
100 |
(TF.to_pil_image(denormalize(reconst_k).clamp(0,1)), f'{k_keep} tokens')
|
101 |
-
for reconst_k, k_keep in zip(all_reconst,
|
102 |
]
|
103 |
|
104 |
return all_images
|
|
|
39 |
# Global no_grad
|
40 |
torch.set_grad_enabled(False)
|
41 |
|
42 |
+
K_KEEP_LIST = [1, 2, 4, 8, 16, 32, 64, 128, 256]
|
43 |
MAX_SEED = np.iinfo(np.int32).max
|
44 |
|
45 |
MODEL_ID = 'EPFL-VILAB/flextok_d18_d28_dfn'
|
|
|
79 |
|
80 |
# Tokenize images once
|
81 |
with get_bf16_context(enable_bf16):
|
82 |
+
tokens = flextok_model.tokenize(imgs)[0] # 1x256
|
83 |
|
84 |
# Create all token subsequences
|
85 |
+
subseq_list = [tokens[:,:k_keep].clone() for k_keep in K_KEEP_LIST] # [1x1, 1x2, 1x4, ..., 1x256]
|
|
|
|
|
86 |
|
87 |
# Detokenize various subsequences in parallel. Batch size is 9.
|
88 |
with get_bf16_context(enable_bf16):
|
|
|
96 |
# Transform to PIL images
|
97 |
all_images = [
|
98 |
(TF.to_pil_image(denormalize(reconst_k).clamp(0,1)), f'{k_keep} tokens')
|
99 |
+
for reconst_k, k_keep in zip(all_reconst, K_KEEP_LIST)
|
100 |
]
|
101 |
|
102 |
return all_images
|