Skip to content

Commit d8a4805

Browse files
author
Beat Buesser
committed
Fix documentation
Signed-off-by: Beat Buesser <[email protected]>
1 parent 7b6be92 commit d8a4805

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

art/attacks/evasion/pe_malware_attack.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
from tqdm.auto import trange
3131

3232
import numpy as np
33-
import tensorflow as tf
3433

3534
from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
3635
from art.estimators.classification.classifier import ClassifierMixin
3736
from art.attacks.attack import EvasionAttack
3837

3938
if TYPE_CHECKING:
39+
# pylint: disable=C0412
40+
import tensorflow as tf
4041
from art.utils import CLASSIFIER_NEURALNETWORK_TYPE
4142

4243
logger = logging.getLogger(__name__)
@@ -212,6 +213,8 @@ def generate_mask(
212213
of perturbation region.
213214
:return mask: Array with 1s on the features we will modify on this batch and 0s elsewhere.
214215
"""
216+
import tensorflow as tf # lgtm [py/repeated-import]
217+
215218
mask = np.zeros_like(x)
216219
for i in range(len(x)):
217220
if y[i] == 1:
@@ -252,6 +255,8 @@ def update_embeddings(self, embeddings: "tf.Tensor", gradients: "tf.Tensor", mas
252255
:param mask: Tensor with 1s on the embeddings we modify, 0s elsewhere.
253256
:return embeddings: Updated embeddings wrt the adversarial objective.
254257
"""
258+
import tensorflow as tf # lgtm [py/repeated-import]
259+
255260
if self.use_sign:
256261
gradients = tf.sign(gradients)
257262
embeddings = embeddings + self.l_r * gradients * mask
@@ -282,6 +287,8 @@ def get_adv_malware(
282287
283288
:return data: Numpy array with valid data samples.
284289
"""
290+
import tensorflow as tf # lgtm [py/repeated-import]
291+
285292
for i, label in enumerate(labels):
286293
if label == 1:
287294
total_diff = 0
@@ -490,6 +497,8 @@ def generate( # pylint: disable=W0221
490497
the start of perturbation region.
491498
:return x: our adversarial examples.
492499
"""
500+
import tensorflow as tf # lgtm [py/repeated-import]
501+
493502
# make copy so original data is not modified.
494503
adv_x = x.copy()
495504
if sample_sizes is None:

0 commit comments

Comments
 (0)