Spaces:
Running
on
Zero
Running
on
Zero
myniu
commited on
Commit
•
69f142b
1
Parent(s):
c488ebf
init
Browse files
app.py
CHANGED
@@ -216,7 +216,7 @@ def visualize_drag_v2(background_image_path, splited_tracks, width, height):
|
|
216 |
|
217 |
class Drag:
|
218 |
@spaces.GPU(duration=200)
|
219 |
-
def __init__(self, device, height, width
|
220 |
self.device = device
|
221 |
|
222 |
svd_ckpt = "ckpts/stable-video-diffusion-img2vid-xt-1-1"
|
@@ -234,7 +234,6 @@ class Drag:
|
|
234 |
|
235 |
self.height = height
|
236 |
self.width = width
|
237 |
-
self.model_length = model_length
|
238 |
|
239 |
def get_cmp_flow(self, frames, sparse_optical_flow, mask, brush_mask=None):
|
240 |
|
@@ -289,7 +288,7 @@ class Drag:
|
|
289 |
'''
|
290 |
|
291 |
seed = 42
|
292 |
-
num_frames =
|
293 |
|
294 |
set_seed(seed)
|
295 |
|
@@ -389,8 +388,8 @@ class Drag:
|
|
389 |
new_resized_all_points = []
|
390 |
new_resized_all_points_384 = []
|
391 |
for tnum in range(len(resized_all_points)):
|
392 |
-
new_resized_all_points.append(interpolate_trajectory(input_all_points[tnum],
|
393 |
-
new_resized_all_points_384.append(interpolate_trajectory(resized_all_points_384[tnum],
|
394 |
|
395 |
resized_all_points = np.array(new_resized_all_points)
|
396 |
resized_all_points_384 = np.array(new_resized_all_points_384)
|
@@ -408,24 +407,24 @@ class Drag:
|
|
408 |
input_drag_384_inmask, input_mask_384_inmask = \
|
409 |
get_sparseflow_and_mask_forward(
|
410 |
resized_all_points_384_inmask,
|
411 |
-
|
412 |
)
|
413 |
else:
|
414 |
input_drag_384_inmask, input_mask_384_inmask = \
|
415 |
-
np.zeros((
|
416 |
-
np.zeros((
|
417 |
|
418 |
if resized_all_points_384_outmask.shape[0] != 0:
|
419 |
out_mask_flag = True
|
420 |
input_drag_384_outmask, input_mask_384_outmask = \
|
421 |
get_sparseflow_and_mask_forward(
|
422 |
resized_all_points_384_outmask,
|
423 |
-
|
424 |
)
|
425 |
else:
|
426 |
input_drag_384_outmask, input_mask_384_outmask = \
|
427 |
-
np.zeros((
|
428 |
-
np.zeros((
|
429 |
|
430 |
input_drag_384_inmask = torch.from_numpy(input_drag_384_inmask).unsqueeze(0).to(self.device) # [1, 13, h, w, 2]
|
431 |
input_mask_384_inmask = torch.from_numpy(input_mask_384_inmask).unsqueeze(0).to(self.device) # [1, 13, h, w]
|
@@ -441,7 +440,7 @@ class Drag:
|
|
441 |
input_first_frame = repeat(first_frames_transform(input_first_frame), 'c h w -> b c h w', b=1).to(self.device)
|
442 |
|
443 |
seed = 42
|
444 |
-
num_frames =
|
445 |
|
446 |
set_seed(seed)
|
447 |
|
@@ -500,8 +499,8 @@ class Drag:
|
|
500 |
new_resized_all_points = []
|
501 |
new_resized_all_points_384 = []
|
502 |
for tnum in range(len(resized_all_points)):
|
503 |
-
new_resized_all_points.append(interpolate_trajectory(input_all_points[tnum],
|
504 |
-
new_resized_all_points_384.append(interpolate_trajectory(resized_all_points_384[tnum],
|
505 |
|
506 |
resized_all_points = np.array(new_resized_all_points)
|
507 |
resized_all_points_384 = np.array(new_resized_all_points_384)
|
@@ -519,24 +518,24 @@ class Drag:
|
|
519 |
input_drag_384_inmask, input_mask_384_inmask = \
|
520 |
get_sparseflow_and_mask_forward(
|
521 |
resized_all_points_384_inmask,
|
522 |
-
|
523 |
)
|
524 |
else:
|
525 |
input_drag_384_inmask, input_mask_384_inmask = \
|
526 |
-
np.zeros((
|
527 |
-
np.zeros((
|
528 |
|
529 |
if resized_all_points_384_outmask.shape[0] != 0:
|
530 |
out_mask_flag = True
|
531 |
input_drag_384_outmask, input_mask_384_outmask = \
|
532 |
get_sparseflow_and_mask_forward(
|
533 |
resized_all_points_384_outmask,
|
534 |
-
|
535 |
)
|
536 |
else:
|
537 |
input_drag_384_outmask, input_mask_384_outmask = \
|
538 |
-
np.zeros((
|
539 |
-
np.zeros((
|
540 |
|
541 |
input_drag_384_inmask = torch.from_numpy(input_drag_384_inmask).unsqueeze(0) # [1, 13, h, w, 2]
|
542 |
input_mask_384_inmask = torch.from_numpy(input_mask_384_inmask).unsqueeze(0) # [1, 13, h, w]
|
@@ -657,7 +656,7 @@ with gr.Blocks() as demo:
|
|
657 |
)
|
658 |
|
659 |
target_size = 512
|
660 |
-
DragNUWA_net = Drag("cuda:0", target_size, target_size
|
661 |
first_frame_path = gr.State()
|
662 |
tracking_points = gr.State([])
|
663 |
motion_brush_points = gr.State([])
|
|
|
216 |
|
217 |
class Drag:
|
218 |
@spaces.GPU(duration=200)
|
219 |
+
def __init__(self, device, height, width):
|
220 |
self.device = device
|
221 |
|
222 |
svd_ckpt = "ckpts/stable-video-diffusion-img2vid-xt-1-1"
|
|
|
234 |
|
235 |
self.height = height
|
236 |
self.width = width
|
|
|
237 |
|
238 |
def get_cmp_flow(self, frames, sparse_optical_flow, mask, brush_mask=None):
|
239 |
|
|
|
288 |
'''
|
289 |
|
290 |
seed = 42
|
291 |
+
num_frames = 25
|
292 |
|
293 |
set_seed(seed)
|
294 |
|
|
|
388 |
new_resized_all_points = []
|
389 |
new_resized_all_points_384 = []
|
390 |
for tnum in range(len(resized_all_points)):
|
391 |
+
new_resized_all_points.append(interpolate_trajectory(input_all_points[tnum], 25))
|
392 |
+
new_resized_all_points_384.append(interpolate_trajectory(resized_all_points_384[tnum], 25))
|
393 |
|
394 |
resized_all_points = np.array(new_resized_all_points)
|
395 |
resized_all_points_384 = np.array(new_resized_all_points_384)
|
|
|
407 |
input_drag_384_inmask, input_mask_384_inmask = \
|
408 |
get_sparseflow_and_mask_forward(
|
409 |
resized_all_points_384_inmask,
|
410 |
+
25 - 1, 384, 384
|
411 |
)
|
412 |
else:
|
413 |
input_drag_384_inmask, input_mask_384_inmask = \
|
414 |
+
np.zeros((25 - 1, 384, 384, 2)), \
|
415 |
+
np.zeros((25 - 1, 384, 384))
|
416 |
|
417 |
if resized_all_points_384_outmask.shape[0] != 0:
|
418 |
out_mask_flag = True
|
419 |
input_drag_384_outmask, input_mask_384_outmask = \
|
420 |
get_sparseflow_and_mask_forward(
|
421 |
resized_all_points_384_outmask,
|
422 |
+
25 - 1, 384, 384
|
423 |
)
|
424 |
else:
|
425 |
input_drag_384_outmask, input_mask_384_outmask = \
|
426 |
+
np.zeros((25 - 1, 384, 384, 2)), \
|
427 |
+
np.zeros((25 - 1, 384, 384))
|
428 |
|
429 |
input_drag_384_inmask = torch.from_numpy(input_drag_384_inmask).unsqueeze(0).to(self.device) # [1, 13, h, w, 2]
|
430 |
input_mask_384_inmask = torch.from_numpy(input_mask_384_inmask).unsqueeze(0).to(self.device) # [1, 13, h, w]
|
|
|
440 |
input_first_frame = repeat(first_frames_transform(input_first_frame), 'c h w -> b c h w', b=1).to(self.device)
|
441 |
|
442 |
seed = 42
|
443 |
+
num_frames = 25
|
444 |
|
445 |
set_seed(seed)
|
446 |
|
|
|
499 |
new_resized_all_points = []
|
500 |
new_resized_all_points_384 = []
|
501 |
for tnum in range(len(resized_all_points)):
|
502 |
+
new_resized_all_points.append(interpolate_trajectory(input_all_points[tnum], 25))
|
503 |
+
new_resized_all_points_384.append(interpolate_trajectory(resized_all_points_384[tnum], 25))
|
504 |
|
505 |
resized_all_points = np.array(new_resized_all_points)
|
506 |
resized_all_points_384 = np.array(new_resized_all_points_384)
|
|
|
518 |
input_drag_384_inmask, input_mask_384_inmask = \
|
519 |
get_sparseflow_and_mask_forward(
|
520 |
resized_all_points_384_inmask,
|
521 |
+
25 - 1, 384, 384
|
522 |
)
|
523 |
else:
|
524 |
input_drag_384_inmask, input_mask_384_inmask = \
|
525 |
+
np.zeros((25 - 1, 384, 384, 2)), \
|
526 |
+
np.zeros((25 - 1, 384, 384))
|
527 |
|
528 |
if resized_all_points_384_outmask.shape[0] != 0:
|
529 |
out_mask_flag = True
|
530 |
input_drag_384_outmask, input_mask_384_outmask = \
|
531 |
get_sparseflow_and_mask_forward(
|
532 |
resized_all_points_384_outmask,
|
533 |
+
25 - 1, 384, 384
|
534 |
)
|
535 |
else:
|
536 |
input_drag_384_outmask, input_mask_384_outmask = \
|
537 |
+
np.zeros((25 - 1, 384, 384, 2)), \
|
538 |
+
np.zeros((25 - 1, 384, 384))
|
539 |
|
540 |
input_drag_384_inmask = torch.from_numpy(input_drag_384_inmask).unsqueeze(0) # [1, 13, h, w, 2]
|
541 |
input_mask_384_inmask = torch.from_numpy(input_mask_384_inmask).unsqueeze(0) # [1, 13, h, w]
|
|
|
656 |
)
|
657 |
|
658 |
target_size = 512
|
659 |
+
DragNUWA_net = Drag("cuda:0", target_size, target_size)
|
660 |
first_frame_path = gr.State()
|
661 |
tracking_points = gr.State([])
|
662 |
motion_brush_points = gr.State([])
|