Example #1
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",
)
Example #2
0
fig0 = plot_spectra(eigval_col=eva_ctrl,
                    savename="%s_spectrum" % modelnm,
                    figdir=figdir)
np.savez(
    join(figdir, "spectra_col_%s.npz" % modelnm),
    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=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:
Example #3
0
fig0 = plot_spectra(eigval_col=eva_ctrl,
                    savename="%s_spectrum" % label,
                    figdir=figdir)
np.savez(
    join(figdir, "spectra_col_%s.npz" % label),
    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,
Example #4
0
    return fig1, fig2


#%%
subpath = [f.path for f in os.scandir(SGdir) if f.is_dir()]
subfdnm = [f.name for f in os.scandir(SGdir) if f.is_dir()]
failnms2 = []
for fdnm in subfdnm:  #["FFHQ512"]:
    try:
        eigval_col, eigvec_col, meta = scan_hess_npz(join(SGdir, fdnm))
        posN = len(eigval_col)
        corr_mat_log, corr_mat_lin = compute_hess_corr(eigval_col,
                                                       eigvec_col,
                                                       fdnm=fdnm)
        plot_consistentcy_mat(corr_mat_log,
                              corr_mat_lin,
                              Hlabel=fdnm,
                              posN=posN)
        print(fdnm, "folder finished")
    except:
        print(fdnm, "folder failed, please check")
        failnms2.append(fdnm)
#%%
from hessian_analysis_tools import plot_spectra, compute_hess_corr, plot_consistentcy_mat, plot_consistency_example


def scan_hess_npz(
    Hdir,
    evakey='eva_BP',
    evckey='evc_BP',
    npzpat="Hess_BP(\d*).npz",
):
Example #5
0
datadir = r"E:\Cluster_Backup\StyleGAN"
figdir = r"E:\OneDrive - Washington University in St. Louis\Hessian_summary\StyleGAN"

os.makedirs(figdir, exist_ok=True)
eva_col, evc_col, feat_col, meta = scan_hess_npz(datadir, "Hessian_rand_(\d*).npz", featkey="feat")
feat_col = np.array(feat_col).squeeze()
H_avg, eva_avg, evc_avg = average_H(eva_col, evc_col)
np.savez(join(figdir, "H_avg_%s.npz"%"StyleGAN"), H_avg=H_avg, eva_avg=eva_avg, evc_avg=evc_avg, feats=feat_col)
#%%
fig = plot_spectra(eva_col, figdir=figdir, titstr="StyleGAN", )
#%%
corr_mat_log, corr_mat_lin = compute_hess_corr(eva_col, evc_col, figdir=figdir, use_cuda=True)
# without cuda 12:11 mins, with cuda 8:21
# corr_mat_log, corr_mat_lin = compute_hess_corr(eva_col, evc_col, figdir=figdir, use_cuda=False)
#%
fig1, fig2 = plot_consistentcy_mat(corr_mat_log, corr_mat_lin, posN=300, figdir=figdir, titstr="StyleGAN")
#%
fig3 = plot_consistency_example(eva_col, evc_col, figdir=figdir, nsamp=5, titstr="StyleGAN",)
fig3.show()
#%%
#%% Accuracy plot
figdir = r"E:\OneDrive - Washington University in St. Louis\Hessian_summary\StyleGAN"
datadir = r"E:\Cluster_Data\StyleGAN"
EPS_list = [1E-6, 1E-5, 1E-4, 3E-4, 1E-3, 3E-3, 1E-2, 5E-2, 1E-1]
raw_corr_tab = []
PSD_corr_tab = []
for triali in range(15):
    print("Computation trial %d"%triali)
    data = np.load(join(savedir, "Hess_accuracy_cmp_%d.npz" % triali), allow_pickle=True)
    H_col = data["H_col"]
    eva_BP, evc_BP, H_BP = data["eva_BP"], data["evc_BP"], data["H_BP"]