Skip to content

Commit

Permalink
Merge pull request #2240 from Trusted-AI/development_issue_2239
Browse files Browse the repository at this point in the history
Make PIL an optional dependency
  • Loading branch information
beat-buesser authored Aug 11, 2023
2 parents 4cd5dc0 + 38618ca commit c7f0a4a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion art/attacks/poisoning/perturbations/image_perturbations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from typing import Optional, Tuple

import numpy as np
from PIL import Image


def add_single_bd(x: np.ndarray, distance: int = 2, pixel_value: int = 1) -> np.ndarray:
Expand Down Expand Up @@ -112,6 +111,8 @@ def insert_image(
:param blend: The blending factor
:return: Backdoored image.
"""
from PIL import Image

n_dim = len(x.shape)
if n_dim == 4:
return np.array(
Expand Down
3 changes: 2 additions & 1 deletion art/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from typing import List, Optional, TYPE_CHECKING

import numpy as np
from PIL import Image

from art import config

Expand Down Expand Up @@ -97,6 +96,8 @@ def save_image(image_array: np.ndarray, f_name: str) -> None:
:param image_array: Image to be saved.
:param f_name: File name containing extension e.g., my_img.jpg, my_img.png, my_images/my_img.png.
"""
from PIL import Image

file_name = os.path.join(config.ART_DATA_PATH, f_name)
folder = os.path.split(file_name)[0]
if not os.path.exists(folder):
Expand Down

0 comments on commit c7f0a4a

Please sign in to comment.