|
25 | 25 | from collections import Callable |
26 | 26 |
|
27 | 27 | import numpy as np |
28 | | -import tensorflow as tf |
29 | 28 |
|
30 | 29 | from art.attacks.attack import EvasionAttack |
31 | 30 | from art.estimators.object_detection.tensorflow_faster_rcnn import TensorFlowFasterRCNN |
@@ -344,6 +343,8 @@ def _attack_training( |
344 | 343 |
|
345 | 344 | :return: Adversarial image/texture. |
346 | 345 | """ |
| 346 | + import tensorflow as tf |
| 347 | + |
347 | 348 | # Initialize session |
348 | 349 | self.estimator.sess.run(tf.global_variables_initializer()) |
349 | 350 | self.estimator.sess.run(tf.local_variables_initializer()) |
@@ -442,6 +443,8 @@ def _build_graph( |
442 | 443 | :param rendering_function: A rendering function to use textures as input. |
443 | 444 | :return: A tuple of tensors. |
444 | 445 | """ |
| 446 | + import tensorflow as tf |
| 447 | + |
445 | 448 | # Create a placeholder to pass input image/texture |
446 | 449 | initial_input = tf.placeholder(dtype=tf.float32, shape=initial_shape, name="initial_input") |
447 | 450 |
|
@@ -628,6 +631,8 @@ def _create_optimizer(self) -> "Optimizer": |
628 | 631 |
|
629 | 632 | :return: Attack optimizer. |
630 | 633 | """ |
| 634 | + import tensorflow as tf |
| 635 | + |
631 | 636 | # Create placeholder for learning rate |
632 | 637 | learning_rate = tf.placeholder(dtype=tf.float32, shape=[], name="learning_rate") |
633 | 638 |
|
@@ -664,6 +669,8 @@ def _create_attack_loss( |
664 | 669 | :param custom_loss: Custom loss function from users. |
665 | 670 | :return: Attack loss tensor. |
666 | 671 | """ |
| 672 | + import tensorflow as tf |
| 673 | + |
667 | 674 | # Compute faster rcnn loss |
668 | 675 | partial_faster_rcnn_loss = self._create_faster_rcnn_loss() |
669 | 676 |
|
@@ -697,6 +704,8 @@ def _create_faster_rcnn_loss(self) -> "Tensor": |
697 | 704 |
|
698 | 705 | :return: Attack partial loss tensor. |
699 | 706 | """ |
| 707 | + import tensorflow as tf |
| 708 | + |
700 | 709 | # Compute RPN classifier loss |
701 | 710 | rpn_classifier_weight = tf.placeholder(dtype=tf.float32, shape=[], name="rpn_classifier_weight") |
702 | 711 |
|
@@ -748,6 +757,8 @@ def _create_box_loss(self) -> "Tensor": |
748 | 757 |
|
749 | 758 | :return: Attack partial loss tensor. |
750 | 759 | """ |
| 760 | + import tensorflow as tf |
| 761 | + |
751 | 762 | # Get default graph |
752 | 763 | default_graph = tf.get_default_graph() |
753 | 764 |
|
@@ -826,6 +837,8 @@ def _create_rpn_loss(self) -> "Tensor": |
826 | 837 |
|
827 | 838 | :return: Attack partial loss tensor. |
828 | 839 | """ |
| 840 | + import tensorflow as tf |
| 841 | + |
829 | 842 | # Get default graph |
830 | 843 | default_graph = tf.get_default_graph() |
831 | 844 |
|
@@ -888,6 +901,8 @@ def _create_similarity_loss(initial_input: "Tensor", current_value: "Tensor") -> |
888 | 901 | :param current_value: Current image/texture. |
889 | 902 | :return: Attack partial loss tensor. |
890 | 903 | """ |
| 904 | + import tensorflow as tf |
| 905 | + |
891 | 906 | # Create a placeholder for the similarity weight |
892 | 907 | similarity_weight = tf.placeholder(dtype=tf.float32, shape=[], name="similarity_weight") |
893 | 908 |
|
|
0 commit comments