Skip to content

Commit

Permalink
refactor with setter method for codeQL
Browse files Browse the repository at this point in the history
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
  • Loading branch information
GiulioZizzo committed Dec 1, 2023
1 parent 689777e commit 5a92140
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
10 changes: 1 addition & 9 deletions art/experimental/attacks/evasion/fast_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,4 @@ def _compute(
x_adv_result.append(x_adv_batch['pixel_values'])

x_adv_result = torch.concatenate(x_adv_result)
sentinel = object()

def myfunc(adv, x_sample=sentinel):
if x_sample is sentinel:
x_sample = x_adv
x_sample['pixel_values'] = adv.type(original_type)
return x_sample

return myfunc(x_adv_result, x_sample=x_adv)
return x_adv.update_pixels(x_adv_result)
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def __len__(self) -> int:
pixel_values = UserDict.__getitem__(self, "pixel_values")
return len(pixel_values)

def update_pixels(self, pixel_values: torch.Tensor) -> None:
super().__setitem__("pixel_values", pixel_values)

def reshape(self, new_shape: Tuple) -> HuggingFaceMultiModalInput:
"""
Defines reshaping on the HuggingFaceMultiModalInput input.
Expand Down

0 comments on commit 5a92140

Please sign in to comment.