(
image_input: str,
pose_input: str,
width: int,
height: int,
guidance_scale: float,
num_inference_steps: int,
fps: int,
frames_overlap: int,
tile_size: int,
noise_aug_strength: float,
decode_chunk_size: int,
seed: int,
)
| 85 | |
| 86 | |
| 87 | def generate( |
| 88 | image_input: str, |
| 89 | pose_input: str, |
| 90 | width: int, |
| 91 | height: int, |
| 92 | guidance_scale: float, |
| 93 | num_inference_steps: int, |
| 94 | fps: int, |
| 95 | frames_overlap: int, |
| 96 | tile_size: int, |
| 97 | noise_aug_strength: float, |
| 98 | decode_chunk_size: int, |
| 99 | seed: int, |
| 100 | ): |
| 101 | gc.collect() |
| 102 | torch.cuda.empty_cache() |
| 103 | torch.cuda.ipc_collect() |
| 104 | timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") |
| 105 | output_dir = Path("outputs") |
| 106 | output_dir = os.path.join(output_dir, timestamp) |
| 107 | if seed == -1: |
| 108 | seed = random.randint(1, 2**20 - 1) |
| 109 | generator = torch.Generator(device=device).manual_seed(seed) |
| 110 | |
| 111 | pipeline = InferenceAnimationPipeline( |
| 112 | vae=vae, |
| 113 | image_encoder=image_encoder, |
| 114 | unet=unet, |
| 115 | scheduler=noise_scheduler, |
| 116 | feature_extractor=feature_extractor, |
| 117 | pose_net=pose_net, |
| 118 | face_encoder=face_encoder, |
| 119 | ).to(device=device, dtype=dtype) |
| 120 | |
| 121 | validation_image_path = image_input |
| 122 | validation_image = Image.open(image_input).convert('RGB') |
| 123 | validation_control_images = load_images_from_folder(pose_input, width=width, height=height) |
| 124 | |
| 125 | num_frames = len(validation_control_images) |
| 126 | face_model.face_helper.clean_all() |
| 127 | validation_face = cv2.imread(validation_image_path) |
| 128 | validation_image_bgr = cv2.cvtColor(validation_face, cv2.COLOR_RGB2BGR) |
| 129 | validation_image_face_info = face_model.app.get(validation_image_bgr) |
| 130 | if len(validation_image_face_info) > 0: |
| 131 | validation_image_face_info = sorted(validation_image_face_info, key=lambda x: (x['bbox'][2] - x['bbox'][0]) * (x['bbox'][3] - x['bbox'][1]))[-1] |
| 132 | validation_image_id_ante_embedding = validation_image_face_info['embedding'] |
| 133 | else: |
| 134 | validation_image_id_ante_embedding = None |
| 135 | |
| 136 | if validation_image_id_ante_embedding is None: |
| 137 | face_model.face_helper.read_image(validation_image_bgr) |
| 138 | face_model.face_helper.get_face_landmarks_5(only_center_face=True) |
| 139 | face_model.face_helper.align_warp_face() |
| 140 | |
| 141 | if len(face_model.face_helper.cropped_faces) == 0: |
| 142 | validation_image_id_ante_embedding = np.zeros((512,)) |
| 143 | else: |
| 144 | validation_image_align_face = face_model.face_helper.cropped_faces[0] |
nothing calls this directly
no test coverage detected