Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions armory/art_experimental/attacks/carla_mot_adversarial_patch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from typing import Optional, Tuple

from art.attacks.evasion.adversarial_patch.adversarial_patch_pytorch import (
Expand All @@ -9,6 +8,9 @@
import torch
from tqdm import trange

from armory.art_experimental.attacks.carla_obj_det_utils import (
fetch_image_from_file_or_url,
)
from armory.logs import log


Expand All @@ -19,6 +21,10 @@ def __init__(self, estimator, coco_format=False, **kwargs):
"batch_frame_size", 1
) # number of frames to attack per iteration
self.patch_base_image = kwargs.pop("patch_base_image", None)
if kwargs.pop("patch_mask", None) is not None:
raise NotImplementedError(
"patch_mask is not supported for CARLA MOT Adversarial Patch"
)
self.coco_format = bool(coco_format)

super().__init__(estimator=estimator, **kwargs)
Expand Down Expand Up @@ -66,13 +72,11 @@ def create_initial_image(self, size):
"""
Create initial patch based on a user-defined image
"""
module_path = globals()["__file__"]
# user-defined image is assumed to reside in the same location as the attack module
patch_base_image_path = os.path.abspath(
os.path.join(os.path.join(module_path, "../"), self.patch_base_image)
)

im = cv2.imread(patch_base_image_path)
if not isinstance(self.patch_base_image, str):
raise ValueError(
"patch_base_image must be a string path to an image or a url to an image"
)
im = fetch_image_from_file_or_url(self.patch_base_image)
im = cv2.resize(im, size)
im = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)

Expand Down