Skip to content
Open
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
45 changes: 44 additions & 1 deletion tests/utils/test_image_processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from huggingface_hub import HfFolder
from requests.exceptions import HTTPError

from transformers import AutoImageProcessor, ViTImageProcessor
from transformers import AutoImageProcessor, ViTImageProcessor, ViTImageProcessorFast
from transformers.image_processing_utils import get_size_dict
from transformers.testing_utils import TOKEN, TemporaryHubRepo, get_tests_dir, is_staging_test

Expand All @@ -45,9 +45,12 @@ def test_cached_files_are_used_when_internet_is_down(self):

# Download this model to make sure it's in the cache.
_ = ViTImageProcessor.from_pretrained("hf-internal-testing/tiny-random-vit")
_ = ViTImageProcessorFast.from_pretrained("hf-internal-testing/tiny-random-vit")

# Under the mock environment we get a 500 error when trying to reach the model.
with mock.patch("requests.Session.request", return_value=response_mock) as mock_head:
_ = ViTImageProcessor.from_pretrained("hf-internal-testing/tiny-random-vit")
_ = ViTImageProcessorFast.from_pretrained("hf-internal-testing/tiny-random-vit")
# This check we did call the fake head request
mock_head.assert_called()

Expand Down Expand Up @@ -79,6 +82,15 @@ def test_push_to_hub(self):
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

def test_push_to_hub_fast(self):
with TemporaryHubRepo(token=self._token) as tmp_repo:
image_processor = ViTImageProcessorFast.from_pretrained(SAMPLE_IMAGE_PROCESSING_CONFIG_DIR)
image_processor.push_to_hub(tmp_repo.repo_id, token=self._token)

new_image_processor = ViTImageProcessorFast.from_pretrained(tmp_repo.repo_id)
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

def test_push_to_hub_via_save_pretrained(self):
with TemporaryHubRepo(token=self._token) as tmp_repo:
image_processor = ViTImageProcessor.from_pretrained(SAMPLE_IMAGE_PROCESSING_CONFIG_DIR)
Expand All @@ -90,6 +102,17 @@ def test_push_to_hub_via_save_pretrained(self):
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

def test_push_to_hub_via_save_pretrained_fast(self):
with TemporaryHubRepo(token=self._token) as tmp_repo:
image_processor = ViTImageProcessorFast.from_pretrained(SAMPLE_IMAGE_PROCESSING_CONFIG_DIR)
# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
image_processor.save_pretrained(tmp_dir, repo_id=tmp_repo.repo_id, push_to_hub=True, token=self._token)

new_image_processor = ViTImageProcessorFast.from_pretrained(tmp_repo.repo_id)
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

def test_push_to_hub_in_organization(self):
with TemporaryHubRepo(namespace="valid_org", token=self._token) as tmp_repo:
image_processor = ViTImageProcessor.from_pretrained(SAMPLE_IMAGE_PROCESSING_CONFIG_DIR)
Expand All @@ -99,6 +122,15 @@ def test_push_to_hub_in_organization(self):
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

def test_push_to_hub_in_organization_fast(self):
with TemporaryHubRepo(namespace="valid_org", token=self._token) as tmp_repo:
image_processor = ViTImageProcessorFast.from_pretrained(SAMPLE_IMAGE_PROCESSING_CONFIG_DIR)
image_processor.push_to_hub(tmp_repo.repo_id, token=self._token)

new_image_processor = ViTImageProcessorFast.from_pretrained(tmp_repo.repo_id)
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

def test_push_to_hub_in_organization_via_save_pretrained(self):
with TemporaryHubRepo(namespace="valid_org", token=self._token) as tmp_repo:
image_processor = ViTImageProcessor.from_pretrained(SAMPLE_IMAGE_PROCESSING_CONFIG_DIR)
Expand All @@ -110,6 +142,17 @@ def test_push_to_hub_in_organization_via_save_pretrained(self):
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

def test_push_to_hub_in_organization_via_save_pretrained_fast(self):
with TemporaryHubRepo(namespace="valid_org", token=self._token) as tmp_repo:
image_processor = ViTImageProcessorFast.from_pretrained(SAMPLE_IMAGE_PROCESSING_CONFIG_DIR)
# Push to hub via save_pretrained
with tempfile.TemporaryDirectory() as tmp_dir:
image_processor.save_pretrained(tmp_dir, repo_id=tmp_repo.repo_id, push_to_hub=True, token=self._token)

new_image_processor = ViTImageProcessorFast.from_pretrained(tmp_repo.repo_id)
for k, v in image_processor.__dict__.items():
self.assertEqual(v, getattr(new_image_processor, k))

def test_push_to_hub_dynamic_image_processor(self):
with TemporaryHubRepo(token=self._token) as tmp_repo:
CustomImageProcessor.register_for_auto_class()
Expand Down