Skip to content

Commit

Permalink
Remove num_channels argument
Browse files Browse the repository at this point in the history
  • Loading branch information
amyeroberts committed Aug 16, 2023
1 parent 6298095 commit e113320
Show file tree
Hide file tree
Showing 43 changed files with 42 additions and 221 deletions.
8 changes: 1 addition & 7 deletions src/transformers/models/beit/image_processing_beit.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,12 @@ def _preprocess_image(
image_std: Optional[Union[float, List[float]]] = None,
data_format: Optional[Union[str, ChannelDimension]] = None,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
) -> np.ndarray:
"""Preprocesses a single image."""
# All transformations expect numpy arrays.
image = to_numpy_array(image)
if input_data_format is None:
input_data_format = infer_channel_dimension_format(image, num_channels=num_channels)
input_data_format = infer_channel_dimension_format(image)
image = self._preprocess(
image,
do_reduce_labels=False,
Expand Down Expand Up @@ -322,7 +321,6 @@ def preprocess(
return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> PIL.Image.Image:
"""
Expand Down Expand Up @@ -375,9 +373,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
do_resize = do_resize if do_resize is not None else self.do_resize
size = size if size is not None else self.size
Expand Down Expand Up @@ -436,7 +431,6 @@ def preprocess(
image_std=image_std,
data_format=data_format,
input_data_format=input_data_format,
num_channels=num_channels,
)
for img in images
]
Expand Down
6 changes: 1 addition & 5 deletions src/transformers/models/bit/image_processing_bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def preprocess(
return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> PIL.Image.Image:
"""
Expand Down Expand Up @@ -229,9 +228,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
do_resize = do_resize if do_resize is not None else self.do_resize
size = size if size is not None else self.size
Expand Down Expand Up @@ -276,7 +272,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

if do_resize:
images = [
Expand Down
6 changes: 1 addition & 5 deletions src/transformers/models/blip/image_processing_blip.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def preprocess(
do_convert_rgb: bool = None,
data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> PIL.Image.Image:
"""
Expand Down Expand Up @@ -217,9 +216,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
do_resize = do_resize if do_resize is not None else self.do_resize
resample = resample if resample is not None else self.resample
Expand Down Expand Up @@ -259,7 +255,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

if do_resize:
images = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ def preprocess(
return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> PIL.Image.Image:
"""
Expand Down Expand Up @@ -434,9 +433,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
do_resize = do_resize if do_resize is not None else self.do_resize
size_divisor = size_divisor if size_divisor is not None else self.size_divisor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def preprocess(
return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> PIL.Image.Image:
"""
Expand Down Expand Up @@ -227,9 +226,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
do_resize = do_resize if do_resize is not None else self.do_resize
size = size if size is not None else self.size
Expand Down Expand Up @@ -274,7 +270,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

if do_resize:
images = [
Expand Down
6 changes: 1 addition & 5 deletions src/transformers/models/clip/image_processing_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def preprocess(
return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> PIL.Image.Image:
"""
Expand Down Expand Up @@ -228,9 +227,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
do_resize = do_resize if do_resize is not None else self.do_resize
size = size if size is not None else self.size
Expand Down Expand Up @@ -275,7 +271,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

if do_resize:
images = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,6 @@ def preprocess(
return_tensors: Optional[Union[TensorType, str]] = None,
data_format: Union[str, ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> BatchFeature:
"""
Expand Down Expand Up @@ -1176,9 +1175,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
if "pad_and_return_pixel_mask" in kwargs:
logger.warning_once(
Expand Down Expand Up @@ -1265,7 +1261,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
if annotations is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ def preprocess(
return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> PIL.Image.Image:
"""
Expand Down Expand Up @@ -245,9 +244,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
do_resize = do_resize if do_resize is not None else self.do_resize
crop_pct = crop_pct if crop_pct is not None else self.crop_pct
Expand Down Expand Up @@ -286,7 +282,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

if do_resize:
images = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,6 @@ def preprocess(
return_tensors: Optional[Union[TensorType, str]] = None,
data_format: Union[str, ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> BatchFeature:
"""
Expand Down Expand Up @@ -1174,9 +1173,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
if "pad_and_return_pixel_mask" in kwargs:
logger.warning_once(
Expand Down Expand Up @@ -1263,7 +1259,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
if annotations is not None:
Expand Down
6 changes: 1 addition & 5 deletions src/transformers/models/deit/image_processing_deit.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def preprocess(
return_tensors: Optional[Union[str, TensorType]] = None,
data_format: ChannelDimension = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> PIL.Image.Image:
"""
Expand Down Expand Up @@ -221,9 +220,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
do_resize = do_resize if do_resize is not None else self.do_resize
resample = resample if resample is not None else self.resample
Expand Down Expand Up @@ -264,7 +260,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

if do_resize:
images = [
Expand Down
6 changes: 1 addition & 5 deletions src/transformers/models/deta/image_processing_deta.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,6 @@ def preprocess(
return_tensors: Optional[Union[TensorType, str]] = None,
data_format: Union[str, ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> BatchFeature:
"""
Expand Down Expand Up @@ -846,9 +845,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
if "pad_and_return_pixel_mask" in kwargs:
logger.warning_once(
Expand Down Expand Up @@ -927,7 +923,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
if annotations is not None:
Expand Down
6 changes: 1 addition & 5 deletions src/transformers/models/detr/image_processing_detr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,6 @@ def preprocess(
return_tensors: Optional[Union[TensorType, str]] = None,
data_format: Union[str, ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> BatchFeature:
"""
Expand Down Expand Up @@ -1146,9 +1145,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset.
"""
if "pad_and_return_pixel_mask" in kwargs:
logger.warning_once(
Expand Down Expand Up @@ -1235,7 +1231,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

# prepare (COCO annotations as a list of Dict -> DETR target as a single Dict per image)
if annotations is not None:
Expand Down
6 changes: 1 addition & 5 deletions src/transformers/models/donut/image_processing_donut.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ def preprocess(
return_tensors: Optional[Union[str, TensorType]] = None,
data_format: Optional[ChannelDimension] = ChannelDimension.FIRST,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
num_channels: Optional[int] = None,
**kwargs,
) -> PIL.Image.Image:
"""
Expand Down Expand Up @@ -368,9 +367,6 @@ def preprocess(
- `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
- `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
- `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
num_channels (`int`, *optional*):
The number of channels in the input image, used to infer the channel dimension format if
`input_data_format` is unset. if `input_data_format` is unset.
"""
do_resize = do_resize if do_resize is not None else self.do_resize
size = size if size is not None else self.size
Expand Down Expand Up @@ -413,7 +409,7 @@ def preprocess(

if input_data_format is None:
# We assume that all images have the same channel dimension format.
input_data_format = infer_channel_dimension_format(images[0], num_channels=num_channels)
input_data_format = infer_channel_dimension_format(images[0])

if do_align_long_axis:
images = [self.align_long_axis(image, size=size, input_data_format=input_data_format) for image in images]
Expand Down
Loading

0 comments on commit e113320

Please sign in to comment.