Skip to content

Commit e2eccf8

Browse files
committed
Format changed files with black==21.12b0
Signed-off-by: Foxglove144 <[email protected]>
1 parent 5f039c0 commit e2eccf8

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

art/attacks/evasion/adversarial_patch/adversarial_patch_pytorch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def __init__(
123123

124124
torch_version = list(map(int, torch.__version__.lower().split("+", maxsplit=1)[0].split(".")))
125125
torchvision_version = list(map(int, torchvision.__version__.lower().split("+", maxsplit=1)[0].split(".")))
126-
assert torch_version[0] >= 1 and torch_version[1] >= 7 or (torch_version[0]>=2), "AdversarialPatchPyTorch requires torch>=1.7.0"
126+
assert (
127+
torch_version[0] >= 1 and torch_version[1] >= 7 or (torch_version[0] >= 2)
128+
), "AdversarialPatchPyTorch requires torch>=1.7.0"
127129
assert (
128130
torchvision_version[0] >= 0 and torchvision_version[1] >= 8
129131
), "AdversarialPatchPyTorch requires torchvision>=0.8.0"

examples/application_object_detection.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,23 @@ def plot_image_with_boxes(img, boxes, pred_cls):
130130
for i in range(len(boxes)):
131131
# Draw Rectangle with the coordinates
132132

133-
cv2.rectangle(img, (int(boxes[i][0][0]), int(boxes[i][0][1])), (int(boxes[i][1][0]), int(boxes[i][1][1])),
134-
color=(0, 255, 0), thickness=rect_th)
133+
cv2.rectangle(
134+
img,
135+
(int(boxes[i][0][0]), int(boxes[i][0][1])),
136+
(int(boxes[i][1][0]), int(boxes[i][1][1])),
137+
color=(0, 255, 0),
138+
thickness=rect_th,
139+
)
135140
# Write the prediction class
136-
cv2.putText(img, pred_cls[i], (int(boxes[i][0][0]), int(boxes[i][0][1])), cv2.FONT_HERSHEY_SIMPLEX, text_size,
137-
(0, 255, 0), thickness=text_th)
141+
cv2.putText(
142+
img,
143+
pred_cls[i],
144+
(int(boxes[i][0][0]), int(boxes[i][0][1])),
145+
cv2.FONT_HERSHEY_SIMPLEX,
146+
text_size,
147+
(0, 255, 0),
148+
thickness=text_th,
149+
)
138150
plt.axis("off")
139151
plt.imshow(img.astype(np.uint8), interpolation="nearest")
140152
plt.show()
@@ -206,4 +218,4 @@ def main():
206218

207219

208220
if __name__ == "__main__":
209-
main()
221+
main()

examples/get_started_fasterrcnn.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,23 @@ def plot_image_with_boxes(img, boxes, pred_cls):
159159
for i in range(len(boxes)):
160160
# Draw Rectangle with the coordinates
161161

162-
cv2.rectangle(img, (int(boxes[i][0][0]), int(boxes[i][0][1])), (int(boxes[i][1][0]), int(boxes[i][1][1])),
163-
color=(0, 255, 0), thickness=rect_th)
162+
cv2.rectangle(
163+
img,
164+
(int(boxes[i][0][0]), int(boxes[i][0][1])),
165+
(int(boxes[i][1][0]), int(boxes[i][1][1])),
166+
color=(0, 255, 0),
167+
thickness=rect_th,
168+
)
164169
# Write the prediction class
165-
cv2.putText(img, pred_cls[i], (int(boxes[i][0][0]), int(boxes[i][0][1])), cv2.FONT_HERSHEY_SIMPLEX, text_size,
166-
(0, 255, 0), thickness=text_th)
170+
cv2.putText(
171+
img,
172+
pred_cls[i],
173+
(int(boxes[i][0][0]), int(boxes[i][0][1])),
174+
cv2.FONT_HERSHEY_SIMPLEX,
175+
text_size,
176+
(0, 255, 0),
177+
thickness=text_th,
178+
)
167179
plt.axis("off")
168180
plt.imshow(img.astype(np.uint8), interpolation="nearest")
169181
plt.show()
@@ -281,7 +293,7 @@ def append_loss_history(loss_history, output):
281293
file.write(json.dumps(loss_history))
282294

283295
np.save(os.path.join(config["path"], "patch"), attack._patch)
284-
296+
285297
predictions_adv = frcnn.predict(x=x_patch)
286298

287299
for i in range(image.shape[0]):
@@ -291,4 +303,4 @@ def append_loss_history(loss_history, output):
291303
predictions_adv_class, predictions_adv_boxes, predictions_adv_class = extract_predictions(predictions_adv[i])
292304

293305
# Plot predictions
294-
plot_image_with_boxes(img=x_patch[i].copy(), boxes=predictions_adv_boxes, pred_cls=predictions_adv_class)
306+
plot_image_with_boxes(img=x_patch[i].copy(), boxes=predictions_adv_boxes, pred_cls=predictions_adv_class)

0 commit comments

Comments
 (0)