Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev_1.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Beat Buesser committed Jun 27, 2023
2 parents 4bfed67 + 7691b39 commit 28a3f8c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ jobs:
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@c4ee3adeed93b1fa6a762f209fb01608c1a22f1e
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175
with:
images: adversarialrobustnesstoolbox/releases
tags: |
type=raw,value={{branch}}-1.14.1-{{sha}}
type=semver,pattern={{version}}
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825
with:
context: .
push: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def __init__(

torch_version = list(map(int, torch.__version__.lower().split("+", maxsplit=1)[0].split(".")))
torchvision_version = list(map(int, torchvision.__version__.lower().split("+", maxsplit=1)[0].split(".")))
assert torch_version[0] >= 1 and torch_version[1] >= 7, "AdversarialPatchPyTorch requires torch>=1.7.0"
assert (
torch_version[0] >= 1 and torch_version[1] >= 7 or (torch_version[0] >= 2)
), "AdversarialPatchPyTorch requires torch>=1.7.0"
assert (
torchvision_version[0] >= 0 and torchvision_version[1] >= 8
), "AdversarialPatchPyTorch requires torchvision>=0.8.0"
Expand Down
4 changes: 4 additions & 0 deletions examples/adversarial_training_cifar10.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import logging

import tensorflow as tf

tf.compat.v1.disable_eager_execution()

from keras.models import Sequential
from keras.layers import Dense, Flatten, Conv2D, MaxPooling2D, Activation, Dropout
import numpy as np
Expand Down
19 changes: 16 additions & 3 deletions examples/application_object_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,24 @@ def plot_image_with_boxes(img, boxes, pred_cls):

for i in range(len(boxes)):
# Draw Rectangle with the coordinates
cv2.rectangle(img, boxes[i][0], boxes[i][1], color=(0, 255, 0), thickness=rect_th)

cv2.rectangle(
img,
(int(boxes[i][0][0]), int(boxes[i][0][1])),
(int(boxes[i][1][0]), int(boxes[i][1][1])),
color=(0, 255, 0),
thickness=rect_th,
)
# Write the prediction class
cv2.putText(img, pred_cls[i], boxes[i][0], cv2.FONT_HERSHEY_SIMPLEX, text_size, (0, 255, 0), thickness=text_th)

cv2.putText(
img,
pred_cls[i],
(int(boxes[i][0][0]), int(boxes[i][0][1])),
cv2.FONT_HERSHEY_SIMPLEX,
text_size,
(0, 255, 0),
thickness=text_th,
)
plt.axis("off")
plt.imshow(img.astype(np.uint8), interpolation="nearest")
plt.show()
Expand Down
32 changes: 28 additions & 4 deletions examples/get_started_fasterrcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,24 @@ def plot_image_with_boxes(img, boxes, pred_cls):

for i in range(len(boxes)):
# Draw Rectangle with the coordinates
cv2.rectangle(img, boxes[i][0], boxes[i][1], color=(0, 255, 0), thickness=rect_th)

cv2.rectangle(
img,
(int(boxes[i][0][0]), int(boxes[i][0][1])),
(int(boxes[i][1][0]), int(boxes[i][1][1])),
color=(0, 255, 0),
thickness=rect_th,
)
# Write the prediction class
cv2.putText(img, pred_cls[i], boxes[i][0], cv2.FONT_HERSHEY_SIMPLEX, text_size, (0, 255, 0), thickness=text_th)

cv2.putText(
img,
pred_cls[i],
(int(boxes[i][0][0]), int(boxes[i][0][1])),
cv2.FONT_HERSHEY_SIMPLEX,
text_size,
(0, 255, 0),
thickness=text_th,
)
plt.axis("off")
plt.imshow(img.astype(np.uint8), interpolation="nearest")
plt.show()
Expand Down Expand Up @@ -215,7 +228,7 @@ def append_loss_history(loss_history, output):
"batch_size": 1,
"image_file": "banner-diverse-group-of-people-2.jpg",
"resume": False,
"path": "xp/",
"path": "",
}

pp = pprint.PrettyPrinter(indent=4)
Expand Down Expand Up @@ -280,3 +293,14 @@ def append_loss_history(loss_history, output):
file.write(json.dumps(loss_history))

np.save(os.path.join(config["path"], "patch"), attack._patch)

predictions_adv = frcnn.predict(x=x_patch)

for i in range(image.shape[0]):
print("\nPredictions adversarial image {}:".format(i))

# Process predictions
predictions_adv_class, predictions_adv_boxes, predictions_adv_class = extract_predictions(predictions_adv[i])

# Plot predictions
plot_image_with_boxes(img=x_patch[i].copy(), boxes=predictions_adv_boxes, pred_cls=predictions_adv_class)
2 changes: 1 addition & 1 deletion examples/get_started_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten, Conv2D, MaxPooling2D
from tensorflow.keras.losses import categorical_crossentropy
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.optimizers.legacy import Adam
import numpy as np

from art.attacks.evasion import FastGradientMethod
Expand Down
6 changes: 5 additions & 1 deletion notebooks/poisoning_defense_neural_cleanse.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
"from art.utils import load_mnist, preprocess\n",
"from art.defences.detector.poison import ActivationDefence\n",
"from art.defences.transformer.poisoning import NeuralCleanse\n",
"from art.estimators.certification.neural_cleanse import KerasNeuralCleanse\n"
"from art.estimators.poison_mitigation import KerasNeuralCleanse\n",
"\n",
"import tensorflow as tf\n",
"if tf.executing_eagerly():\n",
" tf.compat.v1.disable_eager_execution()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ GPy==1.10.0
lightgbm==3.3.5
xgboost==1.7.5

kornia~=0.6.10
kornia~=0.6.12
tensorboardX==2.6
lief==0.12.3
jax[cpu]==0.4.8
Expand Down

0 comments on commit 28a3f8c

Please sign in to comment.