Skip to content

Commit

Permalink
fix _validate_images_text_input_order
Browse files Browse the repository at this point in the history
  • Loading branch information
yonigozlan committed Sep 17, 2024
1 parent 70d2d21 commit 9ca1e51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transformers/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,10 +1034,10 @@ def _is_valid(input, validator):
return validator(input) or input is None

images_is_valid = _is_valid(images, _is_valid_images_input_for_processor)
images_is_text = _is_valid_text_input_for_processor(images) if not images_is_valid else False
images_is_text = _is_valid_text_input_for_processor(images)

text_is_valid = _is_valid(text, _is_valid_text_input_for_processor)
text_is_images = _is_valid_images_input_for_processor(text) if not text_is_valid else False
text_is_images = _is_valid_images_input_for_processor(text)
# Handle cases where both inputs are valid
if images_is_valid and text_is_valid:
return images, text
Expand Down
12 changes: 12 additions & 0 deletions tests/utils/test_processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ def test_validate_images_text_input_order(self):
self.assertTrue(np.array_equal(valid_images[0], images[0]))
self.assertEqual(valid_text, text)

# list of strings and list of url images inputs
images = ["https://url1", "https://url2"]
text = ["text1", "text2"]
# test correct text and images order
valid_images, valid_text = _validate_images_text_input_order(images=images, text=text)
self.assertEqual(valid_images, images)
self.assertEqual(valid_text, text)
# test incorrect text and images order
valid_images, valid_text = _validate_images_text_input_order(images=text, text=images)
self.assertEqual(valid_images, images)
self.assertEqual(valid_text, text)

# list of strings and nested list of numpy images inputs
images = [[np.random.rand(224, 224, 3), np.random.rand(224, 224, 3)], [np.random.rand(224, 224, 3)]]
text = ["text1", "text2"]
Expand Down

0 comments on commit 9ca1e51

Please sign in to comment.