Spaces:
Runtime error
Runtime error
modify
Browse files
app.py
CHANGED
|
@@ -218,6 +218,12 @@ def save_video_from_frames(image_pred, save_pth, fps=8):
|
|
| 218 |
print(f"视频已保存至 {save_pth}")
|
| 219 |
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
# 伪函数占位(生成空白视频)
|
| 222 |
@spaces.GPU
|
| 223 |
def dummy_process(input_fg, input_bg):
|
|
@@ -230,19 +236,21 @@ def dummy_process(input_fg, input_bg):
|
|
| 230 |
cond_tensor = torch.cat((cond_fg_tensor, cond_bg_tensor), dim=2)
|
| 231 |
|
| 232 |
# 初始化潜变量
|
| 233 |
-
init_latent = torch.randn_like(cond_fg_tensor)
|
| 234 |
-
|
| 235 |
-
inf_pipe = InferenceIP2PVideo(
|
| 236 |
-
diffusion_model.unet,
|
| 237 |
-
scheduler='ddpm',
|
| 238 |
-
num_ddim_steps=20
|
| 239 |
-
)
|
| 240 |
|
| 241 |
EDIT_PROMPT = 'change the background'
|
| 242 |
VIDEO_CFG = 1.2
|
| 243 |
TEXT_CFG = 7.5
|
| 244 |
text_cond = diffusion_model.encode_text([EDIT_PROMPT]) # (1, 77, 768)
|
| 245 |
text_uncond = diffusion_model.encode_text([''])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
latent_pred = inf_pipe(
|
| 247 |
latent=init_latent,
|
| 248 |
text_cond=text_cond,
|
|
@@ -275,6 +283,7 @@ def dummy_process(input_fg, input_bg):
|
|
| 275 |
# frame = np.zeros((512, 512, 3), dtype=np.uint8)
|
| 276 |
# out.write(frame)
|
| 277 |
# out.release()
|
|
|
|
| 278 |
|
| 279 |
return output_path
|
| 280 |
|
|
|
|
| 218 |
print(f"视频已保存至 {save_pth}")
|
| 219 |
|
| 220 |
|
| 221 |
+
inf_pipe = InferenceIP2PVideo(
|
| 222 |
+
diffusion_model.unet,
|
| 223 |
+
scheduler='ddpm',
|
| 224 |
+
num_ddim_steps=20
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
# 伪函数占位(生成空白视频)
|
| 228 |
@spaces.GPU
|
| 229 |
def dummy_process(input_fg, input_bg):
|
|
|
|
| 236 |
cond_tensor = torch.cat((cond_fg_tensor, cond_bg_tensor), dim=2)
|
| 237 |
|
| 238 |
# 初始化潜变量
|
| 239 |
+
init_latent = torch.randn_like(cond_fg_tensor)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
EDIT_PROMPT = 'change the background'
|
| 242 |
VIDEO_CFG = 1.2
|
| 243 |
TEXT_CFG = 7.5
|
| 244 |
text_cond = diffusion_model.encode_text([EDIT_PROMPT]) # (1, 77, 768)
|
| 245 |
text_uncond = diffusion_model.encode_text([''])
|
| 246 |
+
# to float16 todo
|
| 247 |
+
init_latent, text_cond, text_uncond, cond_tensor = (
|
| 248 |
+
init_latent.to(dtype=torch.float16),
|
| 249 |
+
text_cond.to(dtype=torch.float16),
|
| 250 |
+
text_uncond.to(dtype=torch.float16),
|
| 251 |
+
cond_tensor.to(dtype=torch.float16)
|
| 252 |
+
)
|
| 253 |
+
inf_pipe.to(torch.float16)
|
| 254 |
latent_pred = inf_pipe(
|
| 255 |
latent=init_latent,
|
| 256 |
text_cond=text_cond,
|
|
|
|
| 283 |
# frame = np.zeros((512, 512, 3), dtype=np.uint8)
|
| 284 |
# out.write(frame)
|
| 285 |
# out.release()
|
| 286 |
+
torch.cuda.empty_cache()
|
| 287 |
|
| 288 |
return output_path
|
| 289 |
|