goryhon commited on
Commit
99e3a94
·
verified ·
1 Parent(s): 33f12ac

Update web-demos/hugging_face/app.py

Browse files
Files changed (1) hide show
  1. web-demos/hugging_face/app.py +19 -20
web-demos/hugging_face/app.py CHANGED
@@ -298,14 +298,12 @@ def vos_tracking_video(video_state, interactive_state, mask_dropdown):
298
 
299
  # inpaint
300
  def inpaint_video(video_state, *_args):
301
- operation_log = [("",""), ("Inpainting started in safe high-quality mode.","Normal")]
302
 
303
- # Получаем кадры и маски
304
  frames = np.asarray(video_state["origin_images"])
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 +313,9 @@ 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
- padding = 30 # по 5 кадров с каждой стороны
321
  fixed_resize_ratio = 1.0
322
  fixed_dilate_radius = 4
323
  fixed_raft_iter = 20
@@ -327,17 +325,12 @@ def inpaint_video(video_state, *_args):
327
  total_len = len(frames)
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,
@@ -345,14 +338,20 @@ def inpaint_video(video_state, *_args):
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(
 
298
 
299
  # inpaint
300
  def inpaint_video(video_state, *_args):
301
+ operation_log = [("",""), ("Inpainting started in smooth-overlap mode.","Normal")]
302
 
 
303
  frames = np.asarray(video_state["origin_images"])
304
  fps = video_state["fps"]
305
  inpaint_masks = np.asarray(video_state["masks"])
306
 
 
307
  mask_dropdown = _args[-1]
308
  if len(mask_dropdown) == 0:
309
  mask_dropdown = ["mask_001"]
 
313
  if i not in inpaint_mask_numbers:
314
  inpaint_masks[inpaint_masks == i] = 0
315
 
316
+ chunk_size = 30 # увеличим размер чанка
317
+ save_size = 20 # сколько сохраняем из каждого чанка (уникальное)
318
+ step = save_size # шаг между чанками
319
  fixed_resize_ratio = 1.0
320
  fixed_dilate_radius = 4
321
  fixed_raft_iter = 20
 
325
  total_len = len(frames)
326
  inpainted_all = []
327
 
328
+ for start in range(0, total_len, step):
329
+ end = min(start + chunk_size, total_len)
330
+ chunk_frames = frames[start:end]
331
+ chunk_masks = inpaint_masks[start:end]
 
 
332
 
333
+ print(f"Inpainting chunk {start}:{end}")
 
 
 
334
 
335
  chunk_result = model.baseinpainter.inpaint(
336
  chunk_frames,
 
338
  ratio=fixed_resize_ratio,
339
  dilate_radius=fixed_dilate_radius,
340
  raft_iter=fixed_raft_iter,
341
+ subvideo_length=chunk_size,
342
  neighbor_length=fixed_neighbor_length,
343
  ref_stride=fixed_ref_stride
344
  )
345
 
346
+ # Сохраняем только уникальные центральные кадры
347
+ if start == 0:
348
+ chunk_to_save = chunk_result[:save_size]
349
+ elif end == total_len:
350
+ chunk_to_save = chunk_result[(chunk_size - (end - start)):]
351
+ else:
352
+ chunk_to_save = chunk_result[:save_size]
353
+
354
+ inpainted_all.extend(chunk_to_save)
355
 
356
  output_path = "./result/inpaint/{}".format(video_state["video_name"])
357
  video_output = generate_video_from_frames(