Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
amyeroberts committed Jul 13, 2023
1 parent e65d8c9 commit 6bac3f1
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ def preprocess(
f" `pathlib.Path` or string object, but is {type(masks_path)} instead."
)

# All transformations expect numpy arrays.
# All transformations expect numpy arrays
images = [to_numpy_array(image) for image in images]

# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ def preprocess(
f" `pathlib.Path` or string object, but is {type(masks_path)} instead."
)

# All transformations expect numpy arrays.
# All transformations expect numpy arrays
images = [to_numpy_array(image) for image in images]

# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/deta/image_processing_deta.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ def preprocess(
f" `pathlib.Path` or string object, but is {type(masks_path)} instead."
)

# All transformations expect numpy arrays.
# All transformations expect numpy arrays
images = [to_numpy_array(image) for image in images]

# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/detr/image_processing_detr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ def preprocess(
f" `pathlib.Path` or string object, but is {type(masks_path)} instead."
)

# All transformations expect numpy arrays.
# All transformations expect numpy arrays
images = [to_numpy_array(image) for image in images]

# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
Expand Down
4 changes: 3 additions & 1 deletion src/transformers/models/flava/image_processing_flava.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
ImageInput,
PILImageResampling,
make_list_of_images,
to_numpy_array,
valid_images,
)
from ...utils import TensorType, is_vision_available, logging
Expand Down Expand Up @@ -454,7 +455,8 @@ def _preprocess_image(
if do_normalize and (image_mean is None or image_std is None):
raise ValueError("Image mean and std must be specified if do_normalize is True.")

image = np.array(image)
# All transformations expect numpy arrays.
image = to_numpy_array(image)

if do_resize:
image = self.resize(image=image, size=size, resample=resample)
Expand Down
4 changes: 3 additions & 1 deletion src/transformers/models/glpn/image_processing_glpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
PILImageResampling,
get_image_size,
make_list_of_images,
to_numpy_array,
valid_images,
)
from ...utils import TensorType, logging
Expand Down Expand Up @@ -174,7 +175,8 @@ def preprocess(
if not valid_images(images):
raise ValueError("Invalid image(s)")

images = [np.array(img) for img in images]
# All transformations expect numpy arrays.
images = [to_numpy_array(image) for image in images]

if do_resize:
images = [self.resize(image, size_divisor=size_divisor, resample=resample) for image in images]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def _preprocess_image(
data_format: Optional[Union[str, ChannelDimension]] = None,
) -> np.ndarray:
"""Preprocesses a single image."""

# All transformations expect numpy arrays.
image = to_numpy_array(image)
image = self._preprocess(
image=image,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ def _preprocess_image(
data_format: Optional[Union[str, ChannelDimension]] = None,
) -> np.ndarray:
"""Preprocesses a single image."""

image = np.array(image)
# All transformations expect numpy arrays.
image = to_numpy_array(image)
image = self._preprocess(
image=image,
do_resize=do_resize,
Expand All @@ -597,7 +597,7 @@ def _preprocess_mask(
size_divisor: int = 0,
) -> np.ndarray:
"""Preprocesses a single mask."""
segmentation_map = np.array(segmentation_map)
segmentation_map = to_numpy_array(segmentation_map)
# Add channel dimension if missing - needed for certain transformations
added_channel_dim = False
if segmentation_map.ndim == 2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ def _preprocess_image(
data_format: Optional[Union[str, ChannelDimension]] = None,
) -> np.ndarray:
"""Preprocesses a single image."""

image = np.array(image)
# All transformations expect numpy arrays.
image = to_numpy_array(image)
image = self._preprocess(
image=image,
do_resize=do_resize,
Expand All @@ -579,7 +579,7 @@ def _preprocess_mask(
size: Dict[str, int] = None,
) -> np.ndarray:
"""Preprocesses a single mask."""
segmentation_map = np.array(segmentation_map)
segmentation_map = to_numpy_array(segmentation_map)
# Add channel dimension if missing - needed for certain transformations
added_channel_dim = False
if segmentation_map.ndim == 2:
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/owlvit/image_processing_owlvit.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def preprocess(
"torch.Tensor, tf.Tensor or jax.ndarray."
)

# All transformations expect numpy arrays.
# All transformations expect numpy arrays
images = [to_numpy_array(image) for image in images]

if do_resize:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def extract_flattened_patches(self, image: np.ndarray, max_patches: int, patch_s
_check_torch_version()

# convert to torch
image = np.array(image)
image = to_channel_dimension_format(image, ChannelDimension.FIRST)
image = torch.from_numpy(image)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ def _preprocess_image(
data_format: Optional[Union[str, ChannelDimension]] = None,
) -> np.ndarray:
"""Preprocesses a single image."""

image = np.array(image)
# All transformations expect numpy arrays.
image = to_numpy_array(image)
image = self._preprocess(
image=image,
do_reduce_labels=False,
Expand All @@ -274,7 +274,7 @@ def _preprocess_mask(
size: Dict[str, int] = None,
) -> np.ndarray:
"""Preprocesses a single mask."""
segmentation_map = np.array(segmentation_map)
segmentation_map = to_numpy_array(segmentation_map)
# Add channel dimension if missing - needed for certain transformations
added_channel_dim = False
if segmentation_map.ndim == 2:
Expand Down
4 changes: 3 additions & 1 deletion src/transformers/models/tvlt/image_processing_tvlt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ImageInput,
PILImageResampling,
is_valid_image,
to_numpy_array,
valid_images,
)
from ...utils import TensorType, logging
Expand Down Expand Up @@ -285,7 +286,8 @@ def _preprocess_image(
if do_normalize and (image_mean is None or image_std is None):
raise ValueError("Image mean and std must be specified if do_normalize is True.")

image = np.array(image)
# All transformations expect numpy arrays.
image = to_numpy_array(image)

if do_resize:
image = self.resize(image=image, size=size, resample=resample)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ImageInput,
PILImageResampling,
is_valid_image,
to_numpy_array,
valid_images,
)
from ...utils import TensorType, is_vision_available, logging
Expand Down Expand Up @@ -257,7 +258,8 @@ def _preprocess_image(
if do_normalize and (image_mean is None or image_std is None):
raise ValueError("Image mean and std must be specified if do_normalize is True.")

image = np.array(image)
# All transformations expect numpy arrays.
image = to_numpy_array(image)

if do_resize:
image = self.resize(image=image, size=size, resample=resample)
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/vit/image_processing_vit.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def preprocess(
if do_rescale and rescale_factor is None:
raise ValueError("Rescale factor must be specified if do_rescale is True.")

# All transformations expect numpy arrays..
# All transformations expect numpy arrays.
images = [to_numpy_array(image) for image in images]

if do_resize:
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/yolos/image_processing_yolos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ def preprocess(
f" `pathlib.Path` or string object, but is {type(masks_path)} instead."
)

# All transformations expect numpy arrays.
# All transformations expect numpy arrays
images = [to_numpy_array(image) for image in images]

# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
Expand Down

0 comments on commit 6bac3f1

Please sign in to comment.