ShotaArima / demo-lowprofool

0 stars 0 forks source link

lowprofoolのエラー解決 #18

Closed ShotaArima closed 1 month ago

ShotaArima commented 2 months ago

9 の前に、lowprofoolの処理の修正を行う

ShotaArima commented 2 months ago

問題

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/tmp/ipykernel_535/4182338255.py in <module>
     54 
     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}

/tmp/ipykernel_535/2400241947.py in gen_adv(config, method)
     29 
     30         if method == 'LowProFool':
---> 31             orig_pred, adv_pred, x_adv, loop_i = lowProFool(x_tensor, model, weights, encoded_bounds, 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=[])

/src/Adverse.py in lowProFool(x, model, weights, bounds, maxiters, alpha, lambda_)
    107         print("xprime", xprime)
    108         print("xprime.shape", xprime.shape)
--> 109         xprime = clip(xprime, min_bounds, max_bounds)
    110 
    111         # Classify adversarial example

/src/Adverse.py in clip(current, low_bound, up_bound)
     12     low_bound = torch.FloatTensor(low_bound)
...
---> 14     clipped = torch.max(torch.min(current, up_bound), low_bound)
     15     return clipped
     16 

RuntimeError: The size of tensor a (25) must match the size of tensor b (12) at non-singleton dimension 0
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?12f54be0-863d-4dd2-bf61-6d1049bed61f) or open in a [text editor](command:workbench.action.openLargeOutput?12f54be0-863d-4dd2-bf61-6d1049bed61f). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...

原因

ShotaArima commented 1 month ago

デバッグの出力

x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
r shape: torch.Size([25])
r: tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], requires_grad=True)
min_bound tensor([-1.1392, -1.4340, -1.0725, -0.6062, -1.9427, -1.8097, -1.7314, -1.4245,
        -0.6768, -0.4391, -0.8222, -0.1759])
min_bound.shape torch.Size([12])
max_bound tensor([1.2846, 3.9544, 5.0352, 2.1390, 1.3829, 0.9139, 1.0340, 3.4155, 4.5070,
        2.2772, 1.2163, 5.6862])
max_bound.shape torch.Size([12])
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])

問題

解決方法

  1. min_boundmax_boundの拡張:カテゴリカル変数(one-hot エンコーディングされた部分)に対応するために、境界値を拡張する必要があります。
  2. clip 関数の修正:
  3. r の初期化の修正:rnan になっている原因を特定し、適切に初期化します。
  4. メインループ内でのデバッグ:各イテレーションで rxprime の値をチェックし、nan が発生した時点を特定します。
  5. 損失計算の確認:損失計算が適切に行われているか確認します。特に、bcel2 の計算結果を出力して確認してください。
ShotaArima commented 1 month ago

先ほどのテンソルのサイズに関する問題は解決した

今の結果は以下のとおりである

Original min_bounds [-1.1392103043341657, -1.43399911187459, -1.072541321556781, -0.6062390952738802, -1.9427378147403065, -1.8096634670027836, -1.731448375007055, -1.4244743489732166, -0.6767670828496157, -0.43913886453595097, -0.8221786020271294, -0.17586311452816475]
Original max_bounds [1.284641407015123, 3.954393203881836, 5.035151581806096, 2.138994543702181, 1.3829189294656394, 0.9139103127672922, 1.033952756326307, 3.4154829900398354, 4.50698078578574, 2.2771840088823034, 1.2162807418417865, 5.686240703077327]
min_bounds [-1.1392103043341657, -1.43399911187459, -1.072541321556781, -0.6062390952738802, -1.9427378147403065, -1.8096634670027836, -1.731448375007055, -1.4244743489732166, -0.6767670828496157, -0.43913886453595097, -0.8221786020271294, -0.17586311452816475, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
max_bounds [1.284641407015123, 3.954393203881836, 5.035151581806096, 2.138994543702181, 1.3829189294656394, 0.9139103127672922, 1.033952756326307, 3.4154829900398354, 4.50698078578574, 2.2771840088823034, 1.2162807418417865, 5.686240703077327, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
r after initialization: tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
        0.], requires_grad=True)
min_bounds dtype: torch.float32
max_bounds dtype: torch.float32
x dtype: torch.float32
r dtype: torch.float32
x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
r shape: torch.Size([25])
r: tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], requires_grad=True)
min_bound tensor([-1.1392, -1.4340, -1.0725, -0.6062, -1.9427, -1.8097, -1.7314, -1.4245,
        -0.6768, -0.4391, -0.8222, -0.1759,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000])
min_bound.shape torch.Size([25])
max_bound tensor([1.2846, 3.9544, 5.0352, 2.1390, 1.3829, 0.9139, 1.0340, 3.4155, 4.5070,
        2.2772, 1.2163, 5.6862, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
...
max_bound.shape torch.Size([25])
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?9c1909e4-76c1-459c-9e0b-d62383b18f5d) or open in a [text editor](command:workbench.action.openLargeOutput?9c1909e4-76c1-459c-9e0b-d62383b18f5d). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
r shape: torch.Size([25])
r: tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], requires_grad=True)
min_bound tensor([-1.1392, -1.4340, -1.0725, -0.6062, -1.9427, -1.8097, -1.7314, -1.4245,
        -0.6768, -0.4391, -0.8222, -0.1759,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000])
min_bound.shape torch.Size([25])
max_bound tensor([1.2846, 3.9544, 5.0352, 2.1390, 1.3829, 0.9139, 1.0340, 3.4155, 4.5070,
        2.2772, 1.2163, 5.6862, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
        1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000])
max_bound.shape torch.Size([25])
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
...
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
x shape: torch.Size([25])
x: 
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?beff9fb3-4bfd-4622-a514-273889be2ef6) or open in a [text editor](command:workbench.action.openLargeOutput?beff9fb3-4bfd-4622-a514-273889be2ef6). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
r shape: torch.Size([25])
r: tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], requires_grad=True)
min_bound tensor([-1.1392, -1.4340, -1.0725, -0.6062, -1.9427, -1.8097, -1.7314, -1.4245,
        -0.6768, -0.4391, -0.8222, -0.1759,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000])
min_bound.shape torch.Size([25])
max_bound tensor([1.2846, 3.9544, 5.0352, 2.1390, 1.3829, 0.9139, 1.0340, 3.4155, 4.5070,
        2.2772, 1.2163, 5.6862, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
        1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000])
max_bound.shape torch.Size([25])
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
...
         0.0000])
r shape: torch.Size([25])
r: tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], requires_grad=True)
min_bound 
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?f0dbae1b-0764-4e45-816a-2bdbd63bf472) or open in a [text editor](command:workbench.action.openLargeOutput?f0dbae1b-0764-4e45-816a-2bdbd63bf472). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], requires_grad=True)
min_bound tensor([-1.1392, -1.4340, -1.0725, -0.6062, -1.9427, -1.8097, -1.7314, -1.4245,
        -0.6768, -0.4391, -0.8222, -0.1759,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000])
min_bound.shape torch.Size([25])
max_bound tensor([1.2846, 3.9544, 5.0352, 2.1390, 1.3829, 0.9139, 1.0340, 3.4155, 4.5070,
        2.2772, 1.2163, 5.6862, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
        1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000])
max_bound.shape torch.Size([25])
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
r shape: torch.Size([25])
r: tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], requires_grad=True)
min_bound tensor([-1.1392, -1.4340, -1.0725, -0.6062, -1.9427, -1.8097, -1.7314, -1.4245,
        -0.6768, -0.4391, -0.8222, -0.1759,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,
...
max_bound.shape torch.Size([25])
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?1bd0798d-3a8b-4192-908c-cb2154c6ada5) or open in a [text editor](command:workbench.action.openLargeOutput?1bd0798d-3a8b-4192-908c-cb2154c6ada5). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
r shape: torch.Size([25])
r: tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], requires_grad=True)
min_bound tensor([-1.1392, -1.4340, -1.0725, -0.6062, -1.9427, -1.8097, -1.7314, -1.4245,
        -0.6768, -0.4391, -0.8222, -0.1759,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000])
min_bound.shape torch.Size([25])
max_bound tensor([1.2846, 3.9544, 5.0352, 2.1390, 1.3829, 0.9139, 1.0340, 3.4155, 4.5070,
        2.2772, 1.2163, 5.6862, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
        1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000])
max_bound.shape torch.Size([25])
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
...
max_bound.shape torch.Size([25])
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?92befa22-bc2a-4164-82b9-f6484f7efd44) or open in a [text editor](command:workbench.action.openLargeOutput?92befa22-bc2a-4164-82b9-f6484f7efd44). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

Current values:
NotebookApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
NotebookApp.rate_limit_window=3.0 (secs)

tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
         0.0000,  0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  1.0000,  0.0000,  0.0000,  1.0000,  0.0000,  1.0000,
         0.0000])
r shape: torch.Size([25])
r: tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], requires_grad=True)
min_bound tensor([-1.1392, -1.4340, -1.0725, -0.6062, -1.9427, -1.8097, -1.7314, -1.4245,
        -0.6768, -0.4391, -0.8222, -0.1759,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,  0.0000,
         0.0000])
min_bound.shape torch.Size([25])
max_bound tensor([1.2846, 3.9544, 5.0352, 2.1390, 1.3829, 0.9139, 1.0340, 3.4155, 4.5070,
        2.2772, 1.2163, 5.6862, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
        1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000])
max_bound.shape torch.Size([25])
xprime tensor([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,
        nan], grad_fn=<AddBackward0>)
xprime.shape torch.Size([25])
x shape: torch.Size([25])
x: tensor([ 2.0526, -0.1312,  0.0061,  1.0340,  1.6005, -0.6768, -0.4391,  1.0000,
...
 -0.43913886  1.          0.          0.          0.          1.
  0.          0.          0.          0.          0.          0.
  1.          0.          0.          1.          0.          1.
  0.          1.          0.          0.        ]
Output is truncated. View as a [scrollable element](command:cellOutput.enableScrolling?a4c38a97-705d-4f51-ac88-84e1f0320b9d) or open in a [text editor](command:workbench.action.openLargeOutput?a4c38a97-705d-4f51-ac88-84e1f0320b9d). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...

新しいバグ

---------------------------------------------------------------------------
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, encoded_bounds, 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](command:cellOutput.enableScrolling?76d0865e-d081-499f-b1eb-3854ace73846) or open in a [text editor](command:workbench.action.openLargeOutput?76d0865e-d081-499f-b1eb-3854ace73846). Adjust cell output [settings](command:workbench.action.openSettings?%5B%22%40tag%3AnotebookOutputLayout%22%5D)...

これにより、LowProFoolについてはエラーを吐かない状態になった

次の課題