s_len = X_0.shape[0] results.loc[idx].X_adv_err = torch.zeros(len(noise_rel), s_len) results.loc[idx].X_ref_err = torch.zeros(len(noise_rel), s_len) for s in range(s_len): print("Sample: {}/{}".format(s + 1, s_len)) X_0_s = X_0[s:s + 1, ...].repeat(it_init, *((X_0.ndim - 1) * (1, ))) Y_0_s = Y_0[s:s + 1, ...].repeat(it_init, *((Y_0.ndim - 1) * (1, ))) X_adv_err_cur, X_ref_err_cur = grid_attack( method, noise_rel, X_0_s, Y_0_s, store_data=False, keep_init=keep_init, err_measure=err_measure, ) results.loc[idx].X_adv_err[:, s] = X_adv_err_cur.max(dim=1)[0] results.loc[idx].X_ref_err[:, s] = X_ref_err_cur.mean(dim=1) # save results for idx in results.index: results_save.loc[idx] = results.loc[idx] os.makedirs(save_path, exist_ok=True) results_save.to_pickle(save_results) # ----- plotting -----
*((X_0.ndim - 1) * (1, ))) Y_0_s = Y_0[s:s + 1, ...].repeat(it_init, *((Y_0.ndim - 1) * (1, ))) ( X_adv_err_cur, X_ref_err_cur, X_adv_cur, X_ref_cur, _, _, ) = grid_attack( method, noise_rel, X_0_s, Y_0_s, store_data=True, keep_init=keep_init, err_measure=err_measure, ) ( results.loc[idx].X_adv_err[:, s], idx_max_adv_err, ) = X_adv_err_cur.max(dim=1) results.loc[idx].X_ref_err[:, s] = X_ref_err_cur.mean(dim=1) for idx_noise in range(len(noise_rel)): idx_max = idx_max_adv_err[idx_noise] results.loc[idx].X_adv_psnr[idx_noise, s] = psnr( rotate_real(X_adv_cur[idx_noise, ...])[idx_max, 0:1, ...],