Remove use_square_size after loading (#30567)
* fix * add test --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
@@ -143,6 +143,10 @@ class CLIPImageProcessor(BaseImageProcessor):
|
|||||||
# for backwards compatibility of KOSMOS-2
|
# for backwards compatibility of KOSMOS-2
|
||||||
if "use_square_size" in kwargs:
|
if "use_square_size" in kwargs:
|
||||||
self.size = {"height": size["shortest_edge"], "width": size["shortest_edge"]}
|
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(
|
def resize(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
@@ -84,6 +85,15 @@ class Kosmos2ProcessorTest(unittest.TestCase):
|
|||||||
|
|
||||||
return image_inputs
|
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):
|
def test_save_load_pretrained_additional_features(self):
|
||||||
processor = Kosmos2Processor(tokenizer=self.get_tokenizer(), image_processor=self.get_image_processor())
|
processor = Kosmos2Processor(tokenizer=self.get_tokenizer(), image_processor=self.get_image_processor())
|
||||||
processor.save_pretrained(self.tmpdirname)
|
processor.save_pretrained(self.tmpdirname)
|
||||||
|
|||||||
Reference in New Issue
Block a user