| 285 | model_fn = ema_model.forward |
| 286 | |
| 287 | def get_data_generator(): |
| 288 | _init = train_steps |
| 289 | while True: |
| 290 | for data in tqdm( |
| 291 | loader, |
| 292 | disable=not accelerator.is_main_process, |
| 293 | initial=_init, |
| 294 | desc="train_steps", |
| 295 | ): |
| 296 | if args.use_latent: |
| 297 | if has_text(args): |
| 298 | _cap_feats = data["caption_feature"] |
| 299 | B, N, T, C = _cap_feats.shape # each image has N captions |
| 300 | yield data["img_feature"].to(device), _cap_feats[ |
| 301 | :, random.randint(0, N - 1) |
| 302 | ].to(device) |
| 303 | elif "facehq" in str(args.data.name): |
| 304 | yield data["latent"].to(device), None |
| 305 | elif "ucf101" in str(args.data.name): |
| 306 | yield data["frame_feature256"].to(device), data["cls_id"].to( |
| 307 | device |
| 308 | ) |
| 309 | elif "celebav" in str(args.data.name): |
| 310 | _start = random.randint( |
| 311 | 0, |
| 312 | data["frame_feature256"].shape[1] |
| 313 | - args.model.params.video_frames |
| 314 | - 1, |
| 315 | ) |
| 316 | _video = data["frame_feature256"][ |
| 317 | :, _start : _start + args.model.params.video_frames |
| 318 | ].to(device) |
| 319 | yield _video, None |
| 320 | else: |
| 321 | raise NotImplementedError( |
| 322 | f"latent data not supported, args.data.name={args.data.name}" |
| 323 | ) |
| 324 | else: |
| 325 | yield data["image"].to(device), None |
| 326 | |
| 327 | def get_real_img_generator(): # [0,255] |
| 328 | while True: |