def generate_images(
    network_pkl: str,
    outdir: str,
    truncation_psi: float,
    truncation_cutoff: int,
    fov_deg: float,
    reload_modules: bool,
    pose_cond: int,
):
    """Generate interpolation images using pretrained network pickle.

    Examples:

    \b
    python gen_interpolation.py --network models/easy-khair-180-gpc0.8-trans10-025000.pkl\
          --trunc 0.7 --outdir interpolation_out
    """

    print('Loading networks from "%s"...' % network_pkl)
    device = torch.device('cuda:1')
    with dnnlib.util.open_url(network_pkl) as f:
        G = legacy.load_network_pkl(f)['G_ema'].to(device) # type: ignore

    # Specify reload_modules=True if you want code modifications to take effect; otherwise uses pickled code
    if reload_modules:
        print("Reloading Modules!")
        G_new = TriPlaneGenerator(*G.init_args, **G.init_kwargs).eval().requires_grad_(False).to(device)
        misc.copy_params_and_buffers(G, G_new, require_all=True)
        G_new.neural_rendering_resolution = G.neural_rendering_resolution
        G_new.rendering_kwargs = G.rendering_kwargs
        G = G_new

    network_pkl = os.path.basename(network_pkl)
    outdir = os.path.join(outdir, os.path.splitext(network_pkl)[0] + '_' + str(pose_cond))
    os.makedirs(outdir, exist_ok=True)

    pose_cond_rad = pose_cond/180*np.pi
    intrinsics = FOV_to_intrinsics(fov_deg, device=device)



    # n_sample = 64
    # batch = 32

    # n_sample = n_sample // batch * batch
    # batch_li = n_sample // batch * [batch]
    pose_cond_rad = pose_cond/180*np.pi

    intrinsics = FOV_to_intrinsics(fov_deg, device=device)

    # Generate images.
    cam_pivot = torch.tensor([0, 0, 0], device=device)
    cam_radius = G.rendering_kwargs.get('avg_camera_radius', 2.7)
    conditioning_cam2world_pose = LookAtPoseSampler.sample(pose_cond_rad, np.pi/2, cam_pivot, radius=cam_radius, device=device)
    conditioning_params = torch.cat([conditioning_cam2world_pose.reshape(-1, 16), intrinsics.reshape(-1, 9)], 1)

    conditioning_cam2world_pose_back = LookAtPoseSampler.sample(-pose_cond_rad, np.pi/2, cam_pivot, radius=cam_radius, device=device)
    conditioning_params_back = torch.cat([conditioning_cam2world_pose_back.reshape(-1, 16), intrinsics.reshape(-1, 9)], 1)

   
    conditioning_cam2world_pose_side = LookAtPoseSampler.sample(45/180*np.pi, np.pi/2, cam_pivot, radius=cam_radius, device=device)
    conditioning_params_side = torch.cat([conditioning_cam2world_pose_side.reshape(-1, 16), intrinsics.reshape(-1, 9)], 1) 

    # set two random seeds for interpolation 
    seed1, seed2 = 521, 329
    z0 = torch.from_numpy(np.random.RandomState(seed1).randn(G.z_dim).reshape(1,G.z_dim)).to(device)
    z1 = torch.from_numpy(np.random.RandomState(seed2).randn(G.z_dim).reshape(1,G.z_dim)).to(device)   
    c = conditioning_params

    ws0 = G.mapping(z0, c, truncation_psi=0.7, truncation_cutoff=None)
    ws1 = G.mapping(z1, c, truncation_psi=0.7, truncation_cutoff=None)

    image_final = []
    for c in [conditioning_params, conditioning_params_side, conditioning_params_back]:
        img0 = G.synthesis(ws0, c)['image']
        img0 = norm_range(img0)
        img1 = G.synthesis(ws1, c)['image']
        img1 = norm_range(img1)





        img_list = []
        for interpolation_idx in [0,2,3,4,6,8]:
        # for interpolation_idx in range(0,14,1):
            # interpolation_idx = 8
            ws_new = ws0.clone()
            ws_new[:, interpolation_idx:, :] = ws1[:, interpolation_idx:, :]
            img_new = G.synthesis(ws_new, c)['image']
            img_new = norm_range(img_new)
            img_list.append(img_new)

        img_list.append(img0)
        
        img_new = torch.cat(img_list, dim=0)
        image_final.append(img_new)

    image_final = torch.cat(image_final, dim=2)
    
    utils.save_image(
        image_final,
        os.path.join(outdir, f'img_interpolation_seed{seed1}_{seed2}.png'),
        # nrow=8,
        normalize=True,
        range=(0, 1),
        padding=0,
    )
        # utils.save_image(
        #     diff,
        #     f'alphamse/changebg/diff.png',
        #     nrow=8,
        #     normalize=True,
        #     range=(0, 1),
        #     padding=0,
        # )
        # sys.exit()
Generate interpolation images using pretrained network pickle.

    Examples:

    
    python gen_interpolation.py --network models/easy-khair-180-gpc0.8-trans10-025000.pkl          --trunc 0.7 --outdir interpolation_out
    
gen_interpolation.py