Skip to content

Commit 7aa1f1b

Browse files
authored
Merge branch 'dev_1.15.1' into development_issue_2165
2 parents e76c04c + c6da8c4 commit 7aa1f1b

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

art/attacks/poisoning/perturbations/image_perturbations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from typing import Optional, Tuple
2222

2323
import numpy as np
24-
from PIL import Image
2524

2625

2726
def add_single_bd(x: np.ndarray, distance: int = 2, pixel_value: int = 1) -> np.ndarray:
@@ -112,6 +111,8 @@ def insert_image(
112111
:param blend: The blending factor
113112
:return: Backdoored image.
114113
"""
114+
from PIL import Image
115+
115116
n_dim = len(x.shape)
116117
if n_dim == 4:
117118
return np.array(

art/estimators/object_detection/pytorch_object_detector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ def _preprocess_and_convert_inputs(
219219

220220
# Set gradients
221221
if not no_grad:
222-
x_tensor.requires_grad = True
222+
if x_tensor.is_leaf:
223+
x_tensor.requires_grad = True
224+
else:
225+
x_tensor.retain_grad()
223226

224227
# Apply framework-specific preprocessing
225228
x_preprocessed, y_preprocessed = self._apply_preprocessing(x=x_tensor, y=y_tensor, fit=fit, no_grad=no_grad)

art/visualization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from typing import List, Optional, TYPE_CHECKING
2626

2727
import numpy as np
28-
from PIL import Image
2928

3029
from art import config
3130

@@ -97,6 +96,8 @@ def save_image(image_array: np.ndarray, f_name: str) -> None:
9796
:param image_array: Image to be saved.
9897
:param f_name: File name containing extension e.g., my_img.jpg, my_img.png, my_images/my_img.png.
9998
"""
99+
from PIL import Image
100+
100101
file_name = os.path.join(config.ART_DATA_PATH, f_name)
101102
folder = os.path.split(file_name)[0]
102103
if not os.path.exists(folder):

0 commit comments

Comments
 (0)