def _reconstructL1_adv(y, lam, rho, x0, z0): x, _ = admm_l1_rec_diag(y, OpA, OpTV, x0, z0, lam, rho, iter=200, silent=True) return x
def _reconstruct(y, lam, rho): x, _ = admm_l1_rec_diag( y, OpA, OpTV, OpA.adj(y), OpTV(OpA.adj(y)), lam, rho, iter=400, silent=True, ) return x
def _reconstructL1(y, noise_rel): lam, rho = _get_gs_param(noise_rel.numpy()) x, _ = admm_l1_rec_diag( y, OpA, OpTV, OpA.adj(y), OpTV(OpA.adj(y)), lam, rho, iter=5000, silent=True, ) return x
def _attackerL1(x0, noise_rel, yadv_init=None, batch_size=6): # compute noiseless measurements y0 = OpA(x0) if noise_rel == 0.0: return y0, y0, y0 # compute absolute noise levels noise_level = noise_rel * y0.norm(p=2, dim=(-2, -1), keepdim=True) # compute noisy measurements for reference yref = noise_ref(OpA(x0), noise_level) # attack parameters adv_init_fac = 3.0 * noise_level adv_param = { "codomain_dist": _complexloss, "domain_dist": None, "mixed_dist": None, "weights": (1.0, 1.0, 1.0), "optimizer": PAdam, "projs": None, "iter": 250, "stepsize": 5e0, } # get ADMM tuning parameters for noise_rel lam, rho = _get_gs_param(noise_rel.numpy()) # compute good start values for _reconstructL1_adv x0_adv, z0_adv = admm_l1_rec_diag( y0, OpA, OpTV, OpA.adj(y0), OpTV(OpA.adj(y0)), lam, rho, iter=5000, silent=True, ) # compute initialization yadv = y0.clone().detach() + ( adv_init_fac / np.sqrt(np.prod(y0.shape[-2:]))) * torch.randn_like(y0) if yadv_init is not None: yadv[0:yadv_init.shape[0], ...] = yadv_init.clone().detach() for idx_batch in range(0, yadv.shape[0], batch_size): print("Attack for samples " + str(list(range(idx_batch, idx_batch + batch_size)))) adv_param["projs"] = [ lambda y: proj_l2_ball( y, y0[idx_batch:idx_batch + batch_size, ...], noise_level[idx_batch:idx_batch + batch_size, ...], ) ] # perform attack yadv[idx_batch:idx_batch + batch_size, ...] = untargeted_attack( lambda y: _reconstructL1_adv( y, lam, rho, x0_adv[idx_batch:idx_batch + batch_size, ...], z0_adv[idx_batch:idx_batch + batch_size, ...], ), yadv[idx_batch:idx_batch + batch_size, ...].clone().requires_grad_(True), y0[idx_batch:idx_batch + batch_size, ...], t_out_ref=x0[idx_batch:idx_batch + batch_size, ...], **adv_param).detach() return yadv, yref, y0