MCPcopy Create free account
hub / github.com/TencentARC/AnimeGamer / generate_Decoder

Function generate_Decoder

app.py:337–388  ·  view source on GitHub ↗
(ml, vid_output, video_path)

Source from the content-addressed store, hash-verified

335 return vid_output, pred_character_states, mix_emb, character_states, instructions
336
337def generate_Decoder(ml, vid_output, video_path):
338
339 c = {"crossattn": torch.zeros((1, 30, 4096)).type(torch.float16).to(animegamer.device_vdm)}
340 uc = {"crossattn": torch.zeros((1, 30, 4096)).type(torch.float16).to(animegamer.device_vdm)}
341 c['ip_cond'] = torch.zeros((1, 196, 768)).type(torch.float16).to(animegamer.device_vdm)
342 uc['ip_cond'] = torch.zeros_like(c['ip_cond'])
343 c['face_id_cond'] = torch.zeros_like(c['ip_cond'])
344 uc['face_id_cond'] = torch.zeros_like(c['ip_cond'])
345 flow_number = cuculate_level(int(ml))
346
347 for index in [flow_number]:
348 samples_z = animegamer.sample_func(
349 c,
350 uc=uc,
351 batch_size=1,
352 shape=(animegamer.T, animegamer.C, animegamer.H // animegamer.F, animegamer.W // animegamer.F),
353 flow=torch.tensor(flow_number),
354 aroutput=vid_output, #[1, 226, 1920]
355 )
356 samples_z = samples_z.permute(0, 2, 1, 3, 4).contiguous()
357
358 torch.cuda.empty_cache()
359 first_stage_model = animegamer.Decoder_model.first_stage_model
360 first_stage_model = first_stage_model.to(animegamer.device_vdm)
361
362 latent = 1.0 / animegamer.Decoder_model.scale_factor * samples_z
363
364 # Decode latent serial to save GPU memory
365 recons = []
366 loop_num = (animegamer.T - 1) // 2
367 for i in range(loop_num):
368 if i == 0:
369 start_frame, end_frame = 0, 3
370 else:
371 start_frame, end_frame = i * 2 + 1, i * 2 + 3
372 if i == loop_num - 1:
373 clear_fake_cp_cache = True
374 else:
375 clear_fake_cp_cache = False
376 with torch.no_grad():
377 recon = first_stage_model.decode(
378 latent[:, :, start_frame:end_frame].contiguous(), clear_fake_cp_cache=clear_fake_cp_cache
379 )
380
381 recons.append(recon)
382
383 recon = torch.cat(recons, dim=2).to(torch.float32)
384 samples_x = recon.permute(0, 2, 1, 3, 4).contiguous()
385 samples = torch.clamp((samples_x + 1.0) / 2.0, min=0.0, max=1.0).cpu()
386
387 if mpu.get_model_parallel_rank() == 0:
388 save_video_as_grid_and_mp4(samples, video_path, fps=animegamer.sampling_fps)
389
390
391def generate_animation(history, characters, motion_adverb, motion, time, background, video_dir):

Callers 1

generate_animationFunction · 0.85

Calls 3

cuculate_levelFunction · 0.70
decodeMethod · 0.45

Tested by

no test coverage detected