File tree Expand file tree Collapse file tree 3 files changed +4
-7
lines changed
attacks/evasion/adversarial_patch
estimators/classification Expand file tree Collapse file tree 3 files changed +4
-7
lines changed Original file line number Diff line number Diff line change @@ -164,9 +164,6 @@ def generate( # type: ignore
164164 """
165165 logger .info ("Creating adversarial patch." )
166166
167- if y is None : # pragma: no cover
168- raise ValueError ("Adversarial Patch attack requires target values `y`." )
169-
170167 if len (x .shape ) == 2 : # pragma: no cover
171168 raise ValueError (
172169 "Feature vectors detected. The adversarial patch can only be applied to data with spatial "
Original file line number Diff line number Diff line change @@ -682,13 +682,13 @@ def apply_patch(
682682 if mask is not None :
683683 mask = mask .copy ()
684684 mask = self ._check_mask (mask = mask , x = x )
685- x_tensor = torch .Tensor (x )
685+ x_tensor = torch .Tensor (x ). to ( self . estimator . device )
686686 if mask is not None :
687- mask_tensor = torch .Tensor (mask )
687+ mask_tensor = torch .Tensor (mask ). to ( self . estimator . device )
688688 else :
689689 mask_tensor = None
690690 if isinstance (patch_external , np .ndarray ):
691- patch_tensor = torch .Tensor (patch_external )
691+ patch_tensor = torch .Tensor (patch_external ). to ( self . estimator . device )
692692 else :
693693 patch_tensor = self ._patch
694694 return (
Original file line number Diff line number Diff line change @@ -322,7 +322,7 @@ def predict( # pylint: disable=W0221
322322 output = model_outputs [- 1 ]
323323 output = output .detach ().cpu ().numpy ().astype (np .float32 )
324324 if len (output .shape ) == 1 :
325- output = np .expand_dims (output . detach (). cpu (). numpy () , axis = 1 ).astype (np .float32 )
325+ output = np .expand_dims (output , axis = 1 ).astype (np .float32 )
326326
327327 results_list .append (output )
328328
You can’t perform that action at this time.
0 commit comments