| 39 | |
| 40 | |
| 41 | def get_batch(keys, value_dict, N: Union[List, ListConfig], T=None, device="cuda"): |
| 42 | batch = {} |
| 43 | batch_uc = {} |
| 44 | |
| 45 | for key in keys: |
| 46 | if key == "txt": |
| 47 | batch["txt"] = np.repeat([value_dict["prompt"]], repeats=math.prod(N)).reshape(N).tolist() |
| 48 | batch_uc["txt"] = np.repeat([value_dict["negative_prompt"]], repeats=math.prod(N)).reshape(N).tolist() |
| 49 | elif key in value_dict.keys(): |
| 50 | batch[key] = value_dict[key] |
| 51 | |
| 52 | if T is not None: |
| 53 | batch["num_video_frames"] = T |
| 54 | |
| 55 | for key in batch.keys(): |
| 56 | if key not in batch_uc and isinstance(batch[key], torch.Tensor): |
| 57 | batch_uc[key] = torch.clone(batch[key]) |
| 58 | return batch, batch_uc |
| 59 | |
| 60 | |
| 61 | def save_video_as_grid_and_mp4(video_batch: torch.Tensor, save_path: str, fps: int = 5, args=None, key=None, ind=None, foldername=None): |