Spaces:
Sleeping
Sleeping
Commit
·
17e9c1f
1
Parent(s):
33c9407
debug
Browse files
app.py
CHANGED
|
@@ -125,6 +125,13 @@ def draw_process(x, y, std):
|
|
| 125 |
|
| 126 |
|
| 127 |
# ReVQ: for reset strategy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
def get_codebook(quantizer):
|
| 129 |
with torch.no_grad():
|
| 130 |
codes = quantizer.embeddings.squeeze().detach()
|
|
@@ -196,7 +203,10 @@ def draw_reset_result(num_data=16, num_code=12):
|
|
| 196 |
fig_reset.suptitle("VQ Codebook Training with Reset", fontsize=24, y=1.05)
|
| 197 |
fig_nreset.suptitle("VQ Codebook Training without Reset", fontsize=24, y=1.05)
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
# end
|
| 202 |
|
|
@@ -294,8 +304,8 @@ if __name__ == "__main__":
|
|
| 294 |
gr.Slider(label="num_code", value=12, minimum=8, maximum=16, step=1),
|
| 295 |
],
|
| 296 |
outputs=[
|
| 297 |
-
gr.
|
| 298 |
-
gr.
|
| 299 |
],
|
| 300 |
title="Demo 2: Codebook Reset Strategy Visualization",
|
| 301 |
description="Visualizes codebook and data movement at different training steps."
|
|
|
|
| 125 |
|
| 126 |
|
| 127 |
# ReVQ: for reset strategy
|
| 128 |
+
def fig_to_array(fig):
|
| 129 |
+
buf = BytesIO()
|
| 130 |
+
fig.savefig(buf, format='png') # 改为 png,不用 webp
|
| 131 |
+
buf.seek(0)
|
| 132 |
+
image = Image.open(buf)
|
| 133 |
+
return np.array(image)
|
| 134 |
+
|
| 135 |
def get_codebook(quantizer):
|
| 136 |
with torch.no_grad():
|
| 137 |
codes = quantizer.embeddings.squeeze().detach()
|
|
|
|
| 203 |
fig_reset.suptitle("VQ Codebook Training with Reset", fontsize=24, y=1.05)
|
| 204 |
fig_nreset.suptitle("VQ Codebook Training without Reset", fontsize=24, y=1.05)
|
| 205 |
|
| 206 |
+
img_reset = fig_to_array(fig_reset)
|
| 207 |
+
img_nreset = fig_to_array(fig_nreset)
|
| 208 |
+
|
| 209 |
+
return img_reset, img_nreset
|
| 210 |
|
| 211 |
# end
|
| 212 |
|
|
|
|
| 304 |
gr.Slider(label="num_code", value=12, minimum=8, maximum=16, step=1),
|
| 305 |
],
|
| 306 |
outputs=[
|
| 307 |
+
gr.Image(label="With Reset"),
|
| 308 |
+
gr.Image(label="Without Reset")
|
| 309 |
],
|
| 310 |
title="Demo 2: Codebook Reset Strategy Visualization",
|
| 311 |
description="Visualizes codebook and data movement at different training steps."
|