Skip to content

Commit 909f861

Browse files
beat-buesserabigailgold
authored andcommitted
Fix mypy warnings caused by opencv-python
Signed-off-by: Beat Buesser <[email protected]>
1 parent ed37400 commit 909f861

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

art/attacks/evasion/adversarial_patch/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def insert_transformed_patch(x: np.ndarray, patch: np.ndarray, image_coords: np.
6262
height, _ = cv2.findHomography(patch_coords, image_coords)
6363

6464
# warp patch to destination coordinates
65-
x_out = cv2.warpPerspective(patch, height, (x.shape[1], x.shape[0]), cv2.INTER_CUBIC)
65+
x_out = cv2.warpPerspective(patch, height, (x.shape[1], x.shape[0]), cv2.INTER_CUBIC) # type: ignore
6666

6767
# mask to aid with insertion
6868
mask = np.ones(patch.shape)
69-
mask_out = cv2.warpPerspective(mask, height, (x.shape[1], x.shape[0]), cv2.INTER_CUBIC)
69+
mask_out = cv2.warpPerspective(mask, height, (x.shape[1], x.shape[0]), cv2.INTER_CUBIC) # type: ignore
7070

7171
# save image before adding shadows
7272
x_neg_patch = np.copy(x)

art/attacks/evasion/graphite/graphite_blackbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def _perturb(
346346
mask_copy = mask_array.copy()
347347
x_noise = cv2.resize(x_copy, self.noise_size)
348348
x_tar_noise = cv2.resize(x_tar_copy, self.noise_size)
349-
mask_noise = cv2.resize(mask_copy, self.noise_size)
349+
mask_noise = cv2.resize(mask_copy, self.noise_size).astype(float)
350350
mask_noise = np.where(mask_noise > 0.5, 1.0, 0.0)
351351

352352
if len(x_noise.shape) < 3:

art/attacks/evasion/graphite/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def apply_transformation(
155155
table = np.empty((256), np.uint8)
156156
for i in range(256):
157157
table[i] = np.clip(pow(i / 255.0, gamma) * 255.0, 0, 255)
158-
att_uint = cv2.LUT(att_uint, table)
158+
att_uint = cv2.LUT(att_uint, table) # type: ignore
159159
att = (att_uint / 255.0).astype(np.float32)
160160
att = np.clip(att, 0.0, 1.0)
161161

@@ -227,12 +227,12 @@ def add_noise(
227227
"""
228228
import cv2
229229

230-
theta_full = cv2.resize(theta, (x.shape[1], x.shape[0]))
230+
theta_full = cv2.resize(theta, (x.shape[1], x.shape[0])).astype(float)
231231
if len(theta_full.shape) < 3:
232232
theta_full = theta_full[:, :, np.newaxis]
233233
comb = x + lbd * theta_full
234234

235-
mask_full = cv2.resize(mask, (x.shape[1], x.shape[0]))
235+
mask_full = cv2.resize(mask, (x.shape[1], x.shape[0])).astype(float)
236236
if len(mask_full.shape) < 3:
237237
mask_full = mask_full[:, :, np.newaxis]
238238
mask_full = np.where(mask_full > 0.5, 1.0, 0.0)
@@ -334,7 +334,7 @@ def transform_wb(
334334
if blur != 0:
335335
kernel = np.zeros((blur * 2 - 1, blur * 2 - 1))
336336
kernel[blur - 1, blur - 1] = 1
337-
kernel = cv2.GaussianBlur(kernel, (blur, blur), 0)
337+
kernel = cv2.GaussianBlur(kernel, (blur, blur), 0).astype(float)
338338
kernel = kernel[blur // 2 : blur // 2 + blur, blur // 2 : blur // 2 + blur]
339339
kernel = kernel[np.newaxis, :, :]
340340
kernel = np.repeat(kernel[np.newaxis, :, :, :], x_adv.size()[1], axis=0)

0 commit comments

Comments
 (0)