"vscode:/vscode.git/clone" did not exist on "c612628045822f909020f7eb6784c79700813eda"
Unverified Commit 78fdd64d authored by Yih-Dar's avatar Yih-Dar Committed by GitHub
Browse files

Remove `use_square_size` after loading (#30567)



* fix

* add test

---------
Co-authored-by: default avatarydshieh <ydshieh@users.noreply.github.com>
parent 87927b24
......@@ -143,6 +143,10 @@ class CLIPImageProcessor(BaseImageProcessor):
# for backwards compatibility of KOSMOS-2
if "use_square_size" in kwargs:
self.size = {"height": size["shortest_edge"], "width": size["shortest_edge"]}
# Let's remove `use_square_size` (as it is removed from #27690), so the future Kosmos-2 image processors
# won't have this attr. being saved. (otherwise, it will enter this if branch while there is no more
# `shortest_edge` key.
delattr(self, "use_square_size")
def resize(
self,
......
......@@ -17,6 +17,7 @@ import os
import shutil
import tempfile
import unittest
from tempfile import TemporaryDirectory
import numpy as np
import pytest
......@@ -84,6 +85,15 @@ class Kosmos2ProcessorTest(unittest.TestCase):
return image_inputs
def test_image_procesor_load_save_reload(self):
# make sure load from Hub repo. -> save -> reload locally work
image_processor = CLIPImageProcessor.from_pretrained("microsoft/kosmos-2-patch14-224")
with TemporaryDirectory() as tmp_dir:
image_processor.save_pretrained(tmp_dir)
reloaded_image_processor = CLIPImageProcessor.from_pretrained(tmp_dir)
assert image_processor.to_dict() == reloaded_image_processor.to_dict()
assert image_processor.to_json_string() == reloaded_image_processor.to_json_string()
def test_save_load_pretrained_additional_features(self):
processor = Kosmos2Processor(tokenizer=self.get_tokenizer(), image_processor=self.get_image_processor())
processor.save_pretrained(self.tmpdirname)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment