Esempio n. 1
0
                                                         figdir=figdir,
                                                         use_cuda=True,
                                                         savelabel=modelnm)
fig1, fig2 = plot_consistentcy_mat(corr_mat_log_ctrl,
                                   corr_mat_lin_ctrl,
                                   figdir=figdir,
                                   titstr="%s" % modelnm,
                                   savelabel=modelnm)
fig11, fig22 = plot_consistency_hist(corr_mat_log_ctrl,
                                     corr_mat_lin_ctrl,
                                     figdir=figdir,
                                     titstr="%s" % modelnm,
                                     savelabel=modelnm)
fig3 = plot_consistency_example(eva_ctrl,
                                evc_ctrl,
                                figdir=figdir,
                                nsamp=5,
                                titstr="%s" % modelnm,
                                savelabel=modelnm)
#%%
with np.load(join(figdir, "spectra_col_%s.npz" % modelnm)) as data:
    eva_ctrl = data["eigval_col"]
with np.load(join(realfigdir, "spectra_col_face256_BP.npz")) as data:
    eva_real = data["eigval_col"]
fig0 = plot_spectra(eva_real,
                    savename="StyleGAN_shuffle_spectrum_cmp",
                    figdir=figdir,
                    abs=True,
                    titstr="StyleGAN cmp",
                    label="real",
                    fig=None)
fig0 = plot_spectra(eva_ctrl,
Esempio n. 2
0
         feats=feat_col)
#%%
fig = plot_spectra(
    eva_col,
    figdir=figdir,
    titstr="DCGAN",
)
#%%
corr_mat_log, corr_mat_lin = compute_hess_corr(eva_col,
                                               evc_col,
                                               figdir=figdir,
                                               use_cuda=False)
# without cuda 2:12 mins, with cuda 6:55
#%%
fig1, fig2 = plot_consistentcy_mat(corr_mat_log,
                                   corr_mat_lin,
                                   figdir=figdir,
                                   titstr="DCGAN")
fig11, fig22 = plot_consistency_hist(corr_mat_log,
                                     corr_mat_lin,
                                     figdir=figdir,
                                     titstr="DCGAN")
#%%
fig3 = plot_consistency_example(
    eva_col,
    evc_col,
    figdir=figdir,
    nsamp=5,
    titstr="DCGAN",
)
Esempio n. 3
0
                                             figdir=figdir,
                                             use_cuda=True,
                                             savelabel=modelnm + "shift1E-7")
fig1, fig2 = plot_consistentcy_mat(corr_mat_log_ctrl,
                                   corr_mat_lin_ctrl,
                                   figdir=figdir,
                                   titstr="%s" % modelnm + "shift1E-7",
                                   savelabel=modelnm)
fig11, fig22 = plot_consistency_hist(corr_mat_log_ctrl,
                                     corr_mat_lin_ctrl,
                                     figdir=figdir,
                                     titstr="%s" % modelnm + "shift1E-7",
                                     savelabel=modelnm)
fig3 = plot_consistency_example(eva_ctrl + 1E-7,
                                evc_ctrl,
                                figdir=figdir,
                                nsamp=5,
                                titstr="%s" % modelnm + "shift1E-7",
                                savelabel=modelnm)
#%%
with np.load(join(figdir, "spectra_col_%s.npz" % modelnm)) as data:
    eva_ctrl = data["eigval_col"]
with np.load(join(realfigdir, "spectra_col.npz")) as data:
    eva_real = data["eigval_col"]
fig0 = plot_spectra(eva_real,
                    savename="BigBiGAN_shuffle_spectrum_cmp",
                    figdir=figdir,
                    abs=True,
                    titstr="BigBiGAN cmp",
                    label="real",
                    fig=None)
fig0 = plot_spectra(eva_ctrl,
Esempio n. 4
0
    print("Load %d npz files of Hessian info" % len(meta))
    return eigval_col, eigvec_col, meta


#%%
SGdir = r"E:\Cluster_Backup\StyleGAN2"
modelnms = ["ffhq-256-config-e-003810", "stylegan2-cat-config-f"]
for modelnm in modelnms:
    datadir = join(SGdir, modelnm)
    eva_col, evc_col, meta = scan_hess_npz(datadir, npzpat="Hess_BP_(\d*).npz")
    fig = plot_spectra(eva_col,
                       figdir=figdir,
                       titstr="StyleGAN2-%s" % modelnm,
                       savename="Hess_spectra_%s" % modelnm)
    # corr_mat_log, corr_mat_lin = compute_hess_corr(eva_col, evc_col, figdir=figdir, use_cuda=True, savelabel=modelnm)
    # without cuda 12:11 mins, with cuda 76sec
    with np.load(join(figdir, "Hess_%s_corr_mat.npz" % modelnm)) as data:
        corr_mat_log, corr_mat_lin = data["corr_mat_log"], data["corr_mat_lin"]
    fig1, fig2 = plot_consistentcy_mat(corr_mat_log,
                                       corr_mat_lin,
                                       figdir=figdir,
                                       titstr="StyleGAN2-%s" % modelnm,
                                       savelabel=modelnm)
    fig3 = plot_consistency_example(eva_col,
                                    evc_col,
                                    figdir=figdir,
                                    nsamp=5,
                                    titstr="StyleGAN2-%s" % modelnm,
                                    savelabel=modelnm)
    fig3.show()
Esempio n. 5
0
    eigval_col=eva_ctrl,
)
# compute and plot the correlation between hessian at different points
corr_mat_log_ctrl, corr_mat_lin_ctrl = compute_hess_corr(eva_ctrl,
                                                         evc_ctrl,
                                                         figdir=figdir,
                                                         use_cuda=True,
                                                         savelabel=label)
fig1, fig2 = plot_consistentcy_mat(corr_mat_log_ctrl,
                                   corr_mat_lin_ctrl,
                                   figdir=figdir,
                                   titstr="%s" % label,
                                   savelabel=label)
fig11, fig22 = plot_consistency_hist(corr_mat_log_ctrl,
                                     corr_mat_lin_ctrl,
                                     figdir=figdir,
                                     titstr="%s" % label,
                                     savelabel=label)
fig3 = plot_consistency_example(eva_ctrl,
                                evc_ctrl,
                                figdir=figdir,
                                nsamp=5,
                                titstr="%s" % label,
                                savelabel=label)
fig3 = plot_consistency_example(eva_ctrl,
                                evc_ctrl,
                                figdir=figdir,
                                nsamp=3,
                                titstr="%s" % label,
                                savelabel=label)
Esempio n. 6
0

#%%
GANsnm = "StyleGAN2-Face512"
modeldir = join(summarydir, "StyleGAN2")
eigval_col, eigvec_col, feat_col, meta = scan_hess_npz(
    r"E:\Cluster_Backup\StyleGAN2\ffhq-512-avg-tpurun1", featkey="feat")
corr_mat_log, corr_mat_lin = compute_hess_corr(
    eigval_col,
    eigvec_col,
    savelabel="ffhq-512-avg-tpurun1",
    figdir=modeldir,
)
plot_consistency_example(eigval_col,
                         eigvec_col,
                         nsamp=5,
                         titstr=GANsnm,
                         figdir=modeldir,
                         savelabel="ffhq-512-avg-tpurun1")

#%%
corrmat_npz_dict = {
    "fc6GAN": "fc6GAN\\evol_hess_corr_mat.npz",
    "DCGAN": "DCGAN\\Hess__corr_mat.npz",
    "BigGAN": "BigGAN\\Hess_all_consistency_corr_mat.npz",
    "BigBiGAN": "BigBiGAN\\evol_hess_corr_mat.npz",
    "PGGAN": "PGGAN\\Hess__corr_mat.npz",
    "StyleGAN-Face": "StyleGAN\\Hess__corr_mat.npz",
    "StyleGAN2-Face512": "StyleGAN2\\Hess_ffhq-512-avg-tpurun1_corr_mat.npz",
    "StyleGAN2-Face256":
    "StyleGAN2\\Hess_ffhq-256-config-e-003810_corr_mat.npz",
    "StyleGAN2-Cat256": "StyleGAN2\\Hess_stylegan2-cat-config-f_corr_mat.npz",
Esempio n. 7
0
fig0 = plot_spectra(eigval_col=eigval_col, savename="%s_spectrum" % modelnm)
corr_mat_log, corr_mat_lin = compute_hess_corr(
    eigval_col,
    eigvec_col,
    figdir=figdir,
    use_cuda=False,
    savelabel=modelnm,
)
fig1, fig2 = plot_consistentcy_mat(corr_mat_log,
                                   corr_mat_lin,
                                   figdir=figdir,
                                   titstr="StyleGAN2 %s" % modelnm,
                                   savelabel=modelnm)
fig3 = plot_consistency_example(eigval_col,
                                eigvec_col,
                                figdir=figdir,
                                nsamp=5,
                                titstr="StyleGAN2 %s" % modelnm,
                                savelabel=modelnm)
#%% "ImageNet512"
Hessdir = join(rootdir, 'StyleGAN2')
modelnm = "model.ckpt-533504"
modelsnm = "ImageNet512"
# SGAN = loadStyleGAN2(modelnm+".pt", size=512,)
# SG = StyleGAN2_wrapper(SGAN, )
eigval_col, eigvec_col, feat_col, meta = scan_hess_npz(join(dataroot, modelnm),
                                                       "Hess_BP_(\d*).npz",
                                                       featkey="feat")
feat_col = np.array(feat_col).squeeze()
H_avg, eva_avg, evc_avg = average_H(eigval_col, eigvec_col)
np.savez(join(Hessdir, "H_avg_%s.npz" % modelnm),
         H_avg=H_avg,