Skip to content

Commit

Permalink
enforce original size to be a list (#33564)
Browse files Browse the repository at this point in the history
* enforce original size to be a list

* formatting

* apply datatype change to unpad_image in llava_next
  • Loading branch information
dom-dziela committed Sep 18, 2024
1 parent 8efc06e commit 9db963a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/transformers/models/llava_next/modeling_llava_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def unpad_image(tensor, original_size):
Returns:
`torch.Tensor`: The unpadded image tensor.
"""
if not isinstance(original_size, (list, tuple)):
if not isinstance(original_size, (torch.Tensor, np.ndarray)):
raise TypeError(
f"image_size invalid type: {type(original_size)} not valid, should be either list, tuple, np.ndarray or tensor"
)
original_size = original_size.tolist()
original_height, original_width = original_size
current_height, current_width = tensor.shape[1:]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ def unpad_image(tensor, original_size):
Returns:
`torch.Tensor`: The unpadded image tensor.
"""
if not isinstance(original_size, (list, tuple)):
if not isinstance(original_size, (torch.Tensor, np.ndarray)):
raise TypeError(
f"image_size invalid type: {type(original_size)} not valid, should be either list, tuple, np.ndarray or tensor"
)
original_size = original_size.tolist()
original_height, original_width = original_size
current_height, current_width = tensor.shape[1:]

Expand Down

0 comments on commit 9db963a

Please sign in to comment.