Spaces:
Paused
Paused
Update web-demos/hugging_face/app.py
Browse files- web-demos/hugging_face/app.py +20 -12
web-demos/hugging_face/app.py
CHANGED
@@ -305,7 +305,7 @@ def inpaint_video(video_state, *_args):
|
|
305 |
fps = video_state["fps"]
|
306 |
inpaint_masks = np.asarray(video_state["masks"])
|
307 |
|
308 |
-
# Маскировка
|
309 |
mask_dropdown = _args[-1]
|
310 |
if len(mask_dropdown) == 0:
|
311 |
mask_dropdown = ["mask_001"]
|
@@ -315,9 +315,10 @@ def inpaint_video(video_state, *_args):
|
|
315 |
if i not in inpaint_mask_numbers:
|
316 |
inpaint_masks[inpaint_masks == i] = 0
|
317 |
|
318 |
-
# Фиксированные
|
319 |
-
chunk_size = 20
|
320 |
-
|
|
|
321 |
fixed_dilate_radius = 4
|
322 |
fixed_raft_iter = 20
|
323 |
fixed_neighbor_length = 5
|
@@ -327,25 +328,32 @@ def inpaint_video(video_state, *_args):
|
|
327 |
inpainted_all = []
|
328 |
|
329 |
for start in range(0, total_len, chunk_size):
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
|
335 |
-
# Инференс inpainting
|
336 |
chunk_result = model.baseinpainter.inpaint(
|
337 |
chunk_frames,
|
338 |
chunk_masks,
|
339 |
ratio=fixed_resize_ratio,
|
340 |
dilate_radius=fixed_dilate_radius,
|
341 |
raft_iter=fixed_raft_iter,
|
342 |
-
subvideo_length=chunk_size,
|
343 |
neighbor_length=fixed_neighbor_length,
|
344 |
ref_stride=fixed_ref_stride
|
345 |
)
|
346 |
-
inpainted_all.extend(chunk_result)
|
347 |
|
348 |
-
|
|
|
|
|
|
|
349 |
output_path = "./result/inpaint/{}".format(video_state["video_name"])
|
350 |
video_output = generate_video_from_frames(
|
351 |
inpainted_all,
|
|
|
305 |
fps = video_state["fps"]
|
306 |
inpaint_masks = np.asarray(video_state["masks"])
|
307 |
|
308 |
+
# Маскировка
|
309 |
mask_dropdown = _args[-1]
|
310 |
if len(mask_dropdown) == 0:
|
311 |
mask_dropdown = ["mask_001"]
|
|
|
315 |
if i not in inpaint_mask_numbers:
|
316 |
inpaint_masks[inpaint_masks == i] = 0
|
317 |
|
318 |
+
# Фиксированные настройки
|
319 |
+
chunk_size = 20
|
320 |
+
padding = 5 # по 5 кадров с каждой стороны
|
321 |
+
fixed_resize_ratio = 1.0
|
322 |
fixed_dilate_radius = 4
|
323 |
fixed_raft_iter = 20
|
324 |
fixed_neighbor_length = 5
|
|
|
328 |
inpainted_all = []
|
329 |
|
330 |
for start in range(0, total_len, chunk_size):
|
331 |
+
# границы с padding
|
332 |
+
pad_start = max(0, start - padding)
|
333 |
+
pad_end = min(total_len, start + chunk_size + padding)
|
334 |
+
core_start = start - pad_start
|
335 |
+
core_end = core_start + min(chunk_size, total_len - start)
|
336 |
+
|
337 |
+
print(f"Inpainting chunk {start} → {min(start + chunk_size, total_len)} with context [{pad_start}:{pad_end}]")
|
338 |
+
|
339 |
+
chunk_frames = frames[pad_start:pad_end]
|
340 |
+
chunk_masks = inpaint_masks[pad_start:pad_end]
|
341 |
|
|
|
342 |
chunk_result = model.baseinpainter.inpaint(
|
343 |
chunk_frames,
|
344 |
chunk_masks,
|
345 |
ratio=fixed_resize_ratio,
|
346 |
dilate_radius=fixed_dilate_radius,
|
347 |
raft_iter=fixed_raft_iter,
|
348 |
+
subvideo_length=chunk_size + 2 * padding,
|
349 |
neighbor_length=fixed_neighbor_length,
|
350 |
ref_stride=fixed_ref_stride
|
351 |
)
|
|
|
352 |
|
353 |
+
# обрезаем паддинг, сохраняем только нужный фрагмент
|
354 |
+
chunk_central = chunk_result[core_start:core_end]
|
355 |
+
inpainted_all.extend(chunk_central)
|
356 |
+
|
357 |
output_path = "./result/inpaint/{}".format(video_state["video_name"])
|
358 |
video_output = generate_video_from_frames(
|
359 |
inpainted_all,
|