Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump pillow from 10.2.0 to 10.3.0 #846

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions dataquality/utils/cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from io import BytesIO
from typing import Any, Optional

from PIL import Image
from PIL.Image import Image
from PIL.Image import open as Image_open
from pydantic import UUID4

from dataquality import config
Expand All @@ -18,7 +19,7 @@


def _bytes_to_img(b: bytes) -> Image:
return Image.open(BytesIO(b))
return Image_open(BytesIO(b))


def _write_img_bytes_to_file(
Expand Down
14 changes: 8 additions & 6 deletions dataquality/utils/cv_smart_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import vaex
from imagededup.methods import PHash
from multiprocess import Pool, cpu_count
from PIL import Image, ImageFilter, ImageStat
from PIL import ImageFilter, ImageStat
from PIL.Image import Image
from PIL.Image import open as Image_open
from vaex.dataframe import DataFrame

from dataquality.exceptions import GalileoWarning
Expand All @@ -19,7 +21,7 @@
METHODS: the methods for detecting smart feature all follow the same architecture with
a first method to quantify the anomaly (as a real number) followed by a method to
threshold it and return a boolean (qualitive).
For example to detect if a method is blurry we call
For example to detect if a method is blurry we call
blurriness = _blurry_laplace(image_gray)
is_blurry = _is_blurry_laplace(blurriness)
These methods are kept separate to allow easy generalization to the use-case where we
Expand Down Expand Up @@ -256,7 +258,7 @@ def _is_under_exposed(
return q_max_over <= under_exposed_max_thresh


def _blurry_laplace(image_gray: Image.Image) -> float:
def _blurry_laplace(image_gray: Image) -> float:
"""
Bluriness detector method where we compute the Variance of the Laplacian.
We use PIL to estimate the Laplacian via the 3x3 convolution filter
Expand Down Expand Up @@ -284,7 +286,7 @@ def _is_blurry_laplace(
return blurriness < blurry_thresh


def _image_content_entropy(image: Image.Image) -> float:
def _image_content_entropy(image: Image) -> float:
"""
Returns the entropy of the pixels on the image. A high entropy means a more complex
image with lots of variation in the pixel values (histogram closer to being uniform)
Expand Down Expand Up @@ -396,7 +398,7 @@ def _is_near_duplicate(in_frame: DataFrame) -> np.ndarray:
return np_is_near_duplicate


def _open_and_resize(image_path: str) -> Tuple[Image.Image, Image.Image, np.ndarray]:
def _open_and_resize(image_path: str) -> Tuple[Image, Image, np.ndarray]:
"""
Open the image at the given path and return a triple with
- the original image opened with PIL
Expand All @@ -406,7 +408,7 @@ def _open_and_resize(image_path: str) -> Tuple[Image.Image, Image.Image, np.ndar
If any of the sides of the image is larger than 2**11, resize the image so that the
largest side is now 2**11.
"""
image = Image.open(image_path)
image = Image_open(image_path)
image_gray = image.convert(
"L"
) # TODO: check if image already grey, faster to skip that ?
Expand Down
9 changes: 5 additions & 4 deletions dataquality/utils/semantic_segmentation/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import numpy as np
import torch
from PIL import Image, ImageColor
from PIL import ImageColor
from PIL.Image import Image, fromarray

from dataquality import config
from dataquality.clients.objectstore import ObjectStore
Expand Down Expand Up @@ -36,7 +37,7 @@ def calculate_and_upload_dep(
return dep_heatmaps


def colorize_dep_heatmap(image: Image.Image, dep_mean: int) -> Image.Image:
def colorize_dep_heatmap(image: Image, dep_mean: int) -> Image:
"""Recolors a grayscale image to a color image based on our dep mapping"""
color_1 = ImageColor.getrgb("#9bc33f") # Red
color_2 = ImageColor.getrgb("#ece113") # Yellow
Expand All @@ -62,7 +63,7 @@ def colorize_dep_heatmap(image: Image.Image, dep_mean: int) -> Image.Image:
colorized_image[~threshold_mask, 1] = (1 - ratio) * color_2[1] + ratio * color_3[1]
colorized_image[~threshold_mask, 2] = (1 - ratio) * color_2[2] + ratio * color_3[2]

return Image.fromarray(colorized_image.astype(np.uint8))
return fromarray(colorized_image.astype(np.uint8))


def calculate_dep_heatmaps(
Expand Down Expand Up @@ -166,7 +167,7 @@ def dep_heatmap_to_img(dep_heatmap: np.ndarray) -> Image:
# Scale the array values to the range [0, 255]
dep_heatmap = (dep_heatmap * 255).astype(np.uint8)
# Create a PIL Image object from the numpy array as grey-scale
img = Image.fromarray(dep_heatmap, mode="L")
img = fromarray(dep_heatmap, mode="L")
if img.size[0] > MAX_DEP_HEATMAP_SIZE or img.size[1] > MAX_DEP_HEATMAP_SIZE:
img = img.resize((MAX_DEP_HEATMAP_SIZE, MAX_DEP_HEATMAP_SIZE))
return img
Expand Down
6 changes: 3 additions & 3 deletions docs/cv/coco_hf_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import torch
from google.cloud import storage
from PIL import Image
from PIL.Image import Image, Resampling
from torchvision import transforms
from tqdm import tqdm

Expand Down Expand Up @@ -57,7 +57,7 @@ def __init__(
if mask_transform is None:
mask_transform = transforms.Compose(
[
transforms.Resize((size, size), resample=Image.NEAREST),
transforms.Resize((size, size), resample=Resampling.NEAREST),
transforms.ToTensor(),
]
)
Expand Down Expand Up @@ -117,7 +117,7 @@ def __getitem__(self, idx: int) -> Dict[str, Union[torch.Tensor, int, np.ndarray

# resize image and mask to given size
unnormalized_image = image.copy().resize(
(self.size, self.size), resample=Image.NEAREST
(self.size, self.size), resample=Resampling.NEAREST
)
unnormalized_image = transforms.ToTensor()(unnormalized_image)
unnormalized_image = expand_gray_channel()(unnormalized_image)
Expand Down
2 changes: 1 addition & 1 deletion docs/cv/cv-demo-hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from io import BytesIO

from datasets import load_dataset
from PIL import Image
from PIL.Image import Image
from torchvision.transforms import Compose, Normalize, RandomResizedCrop, ToTensor
from transformers import (
AutoFeatureExtractor,
Expand Down
2 changes: 1 addition & 1 deletion docs/cv/cv-testing-benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from io import BytesIO

from datasets import load_dataset
from PIL import Image
from PIL.Image import Image

food = load_dataset("sasha/dog-food")

Expand Down
Loading
Loading