Carlos s
commited on
Update api/ltx_server.py
Browse files- api/ltx_server.py +37 -45
api/ltx_server.py
CHANGED
|
@@ -398,53 +398,45 @@ class VideoService:
|
|
| 398 |
return out
|
| 399 |
|
| 400 |
|
| 401 |
-
def
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
Returns:
|
| 411 |
-
List[tensor]: lista de chunks cloneados
|
| 412 |
-
"""
|
| 413 |
-
sum_latent = latents_brutos.shape[2]
|
| 414 |
-
chunks = []
|
| 415 |
|
| 416 |
-
if
|
| 417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
chunks.append(chunk)
|
| 442 |
-
print(f"[DEBUG] chunk{i}[:, :, {start-1}:{end}, :, :] = {chunk.shape[2]}")
|
| 443 |
-
else:
|
| 444 |
-
print(f"[DEBUG] numero chunks minimo")
|
| 445 |
-
print(f"[DEBUG] latents_brutos[:, :, :, :, :] = {latents_brutos.shape[2]}")
|
| 446 |
-
chunks.append(latents_brutos)
|
| 447 |
-
print("================PODA CAUSAL=================")
|
| 448 |
return chunks
|
| 449 |
|
| 450 |
def _get_total_frames(self, video_path: str) -> int:
|
|
|
|
| 398 |
return out
|
| 399 |
|
| 400 |
|
| 401 |
+
def dividir_latentes(latents, num_por_chunk: int, overlap: int = 1):
|
| 402 |
+
# latents: [B, C, T, H, W]
|
| 403 |
+
T = latents.shape[2]
|
| 404 |
+
L = num_por_chunk + overlap # janela com stop exclusivo
|
| 405 |
+
stride = num_por_chunk - overlap # avanço
|
| 406 |
+
print("================= DEBUG =================") # debug
|
| 407 |
+
print(f"[DEBUG] T={T} L={L} stride={stride}") # debug
|
| 408 |
+
print(f"[DEBUG] regra: slice [start:stop) com stop exclusivo") # debug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
|
| 410 |
+
if T <= L:
|
| 411 |
+
start = max(0, T - L)
|
| 412 |
+
stop = start + L
|
| 413 |
+
chunk = latents[:, :, start:stop, :, :].clone().detach()
|
| 414 |
+
print(f"[DEBUG] único chunk: [:, :, {start}:{stop}, :, :] len={stop-start}") # debug
|
| 415 |
+
print("=========================================") # debug
|
| 416 |
+
return [chunk]
|
| 417 |
|
| 418 |
+
starts = []
|
| 419 |
+
s = 0
|
| 420 |
+
while s + L <= T:
|
| 421 |
+
starts.append(s)
|
| 422 |
+
s += stride
|
| 423 |
+
if starts[-1] + L < T:
|
| 424 |
+
starts.append(T - L)
|
| 425 |
+
|
| 426 |
+
# remove duplicata contígua
|
| 427 |
+
uniq = []
|
| 428 |
+
for st in starts:
|
| 429 |
+
if not uniq or uniq[-1] != st:
|
| 430 |
+
uniq.append(st)
|
| 431 |
+
|
| 432 |
+
chunks = []
|
| 433 |
+
for i, st in enumerate(uniq):
|
| 434 |
+
sp = st + L
|
| 435 |
+
chunk = latents[:, :, st:sp, :, :].clone().detach()
|
| 436 |
+
print(f"[DEBUG] chunk{i}: [:, :, {st}:{sp}, :, :] len={sp-st}") # debug
|
| 437 |
+
chunks.append(chunk)
|
| 438 |
+
|
| 439 |
+
print("=========================================") # debug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
return chunks
|
| 441 |
|
| 442 |
def _get_total_frames(self, video_path: str) -> int:
|