Render a latent vector interpolation video. Examples: \b # Render a 4x2 grid of interpolations for seeds 0 through 31. python gen_video.py --output=lerp.mp4 --trunc=1 --seeds=0-31 --grid=4x2 \\ --network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/version
(
network_pkl: str,
seeds: List[int],
output: str,
shuffle_seed: Optional[int],
truncation_psi: float,
truncation_cutoff: int,
grid: Tuple[int,int],
num_keyframes: Optional[int],
w_frames: int,
reload_modules: bool,
cfg: str,
image_mode: str,
sampling_multiplier: float,
nrr: Optional[int],
shapes: bool,
interpolate: bool,
pose_cond: int,
)
| 284 | @click.option('--pose_cond', type=int, help='pose_cond angle', default=90, show_default=True) |
| 285 | |
| 286 | def generate_images( |
| 287 | network_pkl: str, |
| 288 | seeds: List[int], |
| 289 | output: str, |
| 290 | shuffle_seed: Optional[int], |
| 291 | truncation_psi: float, |
| 292 | truncation_cutoff: int, |
| 293 | grid: Tuple[int,int], |
| 294 | num_keyframes: Optional[int], |
| 295 | w_frames: int, |
| 296 | reload_modules: bool, |
| 297 | cfg: str, |
| 298 | image_mode: str, |
| 299 | sampling_multiplier: float, |
| 300 | nrr: Optional[int], |
| 301 | shapes: bool, |
| 302 | interpolate: bool, |
| 303 | pose_cond: int, |
| 304 | ): |
| 305 | """Render a latent vector interpolation video. |
| 306 | |
| 307 | Examples: |
| 308 | |
| 309 | \b |
| 310 | # Render a 4x2 grid of interpolations for seeds 0 through 31. |
| 311 | python gen_video.py --output=lerp.mp4 --trunc=1 --seeds=0-31 --grid=4x2 \\ |
| 312 | --network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-afhqv2-512x512.pkl |
| 313 | |
| 314 | Animation length and seed keyframes: |
| 315 | |
| 316 | The animation length is either determined based on the --seeds value or explicitly |
| 317 | specified using the --num-keyframes option. |
| 318 | |
| 319 | When num keyframes is specified with --num-keyframes, the output video length |
| 320 | will be 'num_keyframes*w_frames' frames. |
| 321 | |
| 322 | If --num-keyframes is not specified, the number of seeds given with |
| 323 | --seeds must be divisible by grid size W*H (--grid). In this case the |
| 324 | output video length will be '# seeds/(w*h)*w_frames' frames. |
| 325 | """ |
| 326 | |
| 327 | print('Loading networks from "%s"...' % network_pkl) |
| 328 | device = torch.device('cuda:1') |
| 329 | with dnnlib.util.open_url(network_pkl) as f: |
| 330 | G = legacy.load_network_pkl(f)['G_ema'].to(device) # type: ignore |
| 331 | |
| 332 | G.rendering_kwargs['depth_resolution'] = int(G.rendering_kwargs['depth_resolution'] * sampling_multiplier) |
| 333 | G.rendering_kwargs['depth_resolution_importance'] = int(G.rendering_kwargs['depth_resolution_importance'] * sampling_multiplier) |
| 334 | if nrr is not None: G.neural_rendering_resolution = nrr |
| 335 | # Specify reload_modules=True if you want code modifications to take effect; otherwise uses pickled code |
| 336 | # if reload_modules: |
| 337 | # print("Reloading Modules!") |
| 338 | G_new = TriPlaneGenerator(*G.init_args, **G.init_kwargs).eval().requires_grad_(False).to(device) |
| 339 | misc.copy_params_and_buffers(G, G_new, require_all=True) |
| 340 | G_new.neural_rendering_resolution = G.neural_rendering_resolution |
| 341 | G_new.rendering_kwargs = G.rendering_kwargs |
| 342 | G = G_new |
| 343 |
no test coverage detected