Closed ShotaArima closed 1 month ago
deepfool
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) /tmp/ipykernel_605/4182338255.py in <module> 55 # Generate adversarial examples 56 df_adv_lpf = gen_adv(config, 'LowProFool') ---> 57 df_adv_df = gen_adv(config, 'Deepfool') 58 config['AdvData'] = {'LowProFool' : df_adv_lpf, 'Deepfool' : df_adv_df} 59
/tmp/ipykernel_605/2400241947.py in gen_adv(config, method) 31 orig_pred, adv_pred, x_adv, loop_i = lowProFool(x_tensor, model, weights, encodedbounds, maxiters, alpha, lambda) 32 elif method == 'Deepfool': ---> 33 orig_pred, adv_pred, x_adv, loop_i = deepfool(x_tensor, model, maxiters, alpha, encoded_bounds, weights=[]) 34 else: 35 raise Exception("Invalid method", method)
/src/Adverse.py in deepfool(x_old, net, maxiters, alpha, bounds, weights, overshoot) 264 265 pert_x = x_old + (1 + overshoot) * torch.from_numpy(r_tot) --> 266 pert_x = clip(pert_x, min_bounds, max_bounds) 267 268 x = Variable(pert_x, requires_grad=True)
/src/Adverse.py in clip(current, low_bound, up_bound) 18 # サイズが一致していることを確認 ... ---> 20 assert current.size() == low_bound.size() == up_bound.size(), f"Sizes must match: current {current.size()}, low_bound {low_bound.size()}, up_bound {up_bound.size()}" 21 22 clipped = torch.max(torch.min(current, up_bound), low_bound)
AssertionError: Sizes must match: current torch.Size([1, 25]), low_bound torch.Size([12]), up_bound torch.Size([12]) Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
### 解釈 - 以下のテンソルサイズが不一致である - current: torch.Size([1, 25]) - low_bound: torch.Size([12]) - up_bound: torch.Size([12]) ## Why?(なぜ変更するのか) - 研究用のソースコードとして、クリティカルな問題である ## How?(どう変更するのか) - lowprofool側と最低限同じよな前処理を行う - テンソルサイズは25にする ## Checklist - [ ] a - [ ] b
What?(変更の概要・何を変更したのか)
deepfool
のアルゴリズムについて、テンソルサイズの処理でエラーを吐いていた/tmp/ipykernel_605/2400241947.py in gen_adv(config, method) 31 orig_pred, adv_pred, x_adv, loop_i = lowProFool(x_tensor, model, weights, encodedbounds, maxiters, alpha, lambda) 32 elif method == 'Deepfool': ---> 33 orig_pred, adv_pred, x_adv, loop_i = deepfool(x_tensor, model, maxiters, alpha, encoded_bounds, weights=[]) 34 else: 35 raise Exception("Invalid method", method)
/src/Adverse.py in deepfool(x_old, net, maxiters, alpha, bounds, weights, overshoot) 264 265 pert_x = x_old + (1 + overshoot) * torch.from_numpy(r_tot) --> 266 pert_x = clip(pert_x, min_bounds, max_bounds) 267 268 x = Variable(pert_x, requires_grad=True)
/src/Adverse.py in clip(current, low_bound, up_bound) 18 # サイズが一致していることを確認 ... ---> 20 assert current.size() == low_bound.size() == up_bound.size(), f"Sizes must match: current {current.size()}, low_bound {low_bound.size()}, up_bound {up_bound.size()}" 21 22 clipped = torch.max(torch.min(current, up_bound), low_bound)
AssertionError: Sizes must match: current torch.Size([1, 25]), low_bound torch.Size([12]), up_bound torch.Size([12]) Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...