예제 #1
0
                                       n_cols=instances,
                                       scale=sigma,
                                       make_plots=False,
                                       edit_type=edit_mode)
                    plt.close('all')

                    frames = [x for _, x in frames]
                    frames = frames + frames[::-1]
                    make_mp4(
                        frames, 5, outdir_comp /
                        f'{get_edit_name(edit_mode)}_sigma{sigma}_comp{c}.mp4')

    # Summary grid, random directions
    # Using the stdevs of the principal components for same norm
    random_dirs_act = torch.from_numpy(
        get_random_dirs(n_comp, np.prod(sample_shape)).reshape(
            -1, *sample_shape)).to(device)
    random_dirs_z = torch.from_numpy(
        get_random_dirs(n_comp, np.prod(inst.input_shape)).reshape(
            -1, *latent_shape)).to(device)

    for edit_mode in edit_modes:
        plt.figure(figsize=(14, 12))
        plt.suptitle(
            f"{model.name} - {layer_name}, random directions w/ PC stdevs, {get_edit_name(edit_mode)} edit",
            size=16)
        make_grid(tensors.Z_global_mean,
                  tensors.Z_global_mean,
                  random_dirs_z,
                  tensors.Z_stdev,
                  tensors.X_global_mean,
                  random_dirs_act,
예제 #2
0
        # One reasonable, one over the top
        for sigma in [args.sigma, 3*args.sigma]:
            for c in range(components):
                for edit_mode in edit_modes:
                    frames = make_grid(tensors.Z_global_mean, tensors.Z_global_mean, tensors.Z_comp[c:c+1, :, :], tensors.Z_stdev[c:c+1], tensors.X_global_mean,
                        tensors.X_comp[c:c+1, :, :], tensors.X_stdev[c:c+1], n_rows=1, n_cols=instances, scale=sigma, make_plots=False, edit_type=edit_mode)
                    plt.close('all')

                    frames = [x for _, x in frames]
                    frames = frames + frames[::-1]
                    make_mp4(frames, 5, outdir_comp / f'{get_edit_name(edit_mode)}_sigma{sigma}_comp{c}.mp4')

    
    # Summary grid, random directions
    # Using the stdevs of the principal components for same norm
    random_dirs_act = torch.from_numpy(get_random_dirs(n_comp, np.prod(sample_shape)).reshape(-1, *sample_shape)).to(device)
    random_dirs_z = torch.from_numpy(get_random_dirs(n_comp, np.prod(inst.input_shape)).reshape(-1, *latent_shape)).to(device)
    
    for edit_mode in edit_modes:
        plt.figure(figsize = (14,12))
        plt.suptitle(f"{model.name} - {layer_name}, random directions w/ PC stdevs, {get_edit_name(edit_mode)} edit", size=16)
        make_grid(tensors.Z_global_mean, tensors.Z_global_mean, random_dirs_z, tensors.Z_stdev,
            tensors.X_global_mean, random_dirs_act, tensors.X_stdev, scale=args.sigma, edit_type=edit_mode, n_rows=14)
        plt.savefig(outdir_summ / f'random_dirs_{get_edit_name(edit_mode)}.jpg', dpi=300)
        show()

    # Random instances w/ components added
    n_random_imgs = 10
    latents = model.sample_latent(n_samples=n_random_imgs)

    for img_idx in trange(n_random_imgs, desc='Random images', ascii=True):