18
18
import tempfile
19
19
import unittest
20
20
21
- import numpy as np
22
21
import pytest
23
22
24
23
from transformers import BertTokenizer , BertTokenizerFast
25
24
from transformers .models .bert .tokenization_bert import VOCAB_FILES_NAMES
26
25
from transformers .testing_utils import require_vision
27
26
from transformers .utils import FEATURE_EXTRACTOR_NAME , is_vision_available
28
27
28
+ from ...test_processing_common import ProcessorTesterMixin
29
29
30
- if is_vision_available ():
31
- from PIL import Image
32
30
31
+ if is_vision_available ():
33
32
from transformers import ChineseCLIPImageProcessor , ChineseCLIPProcessor
34
33
35
34
36
35
@require_vision
37
- class ChineseCLIPProcessorTest (unittest .TestCase ):
36
+ class ChineseCLIPProcessorTest (ProcessorTesterMixin , unittest .TestCase ):
37
+ processor_class = ChineseCLIPProcessor
38
+
38
39
def setUp (self ):
39
40
self .tmpdirname = tempfile .mkdtemp ()
40
41
@@ -76,6 +77,11 @@ def setUp(self):
76
77
with open (self .image_processor_file , "w" , encoding = "utf-8" ) as fp :
77
78
json .dump (image_processor_map , fp )
78
79
80
+ tokenizer = self .get_tokenizer ()
81
+ image_processor = self .get_image_processor ()
82
+ processor = ChineseCLIPProcessor (tokenizer = tokenizer , image_processor = image_processor )
83
+ processor .save_pretrained (self .tmpdirname )
84
+
79
85
def get_tokenizer (self , ** kwargs ):
80
86
return BertTokenizer .from_pretrained (self .tmpdirname , ** kwargs )
81
87
@@ -88,17 +94,6 @@ def get_image_processor(self, **kwargs):
88
94
def tearDown (self ):
89
95
shutil .rmtree (self .tmpdirname )
90
96
91
- def prepare_image_inputs (self ):
92
- """This function prepares a list of PIL images, or a list of numpy arrays if one specifies numpify=True,
93
- or a list of PyTorch tensors if one specifies torchify=True.
94
- """
95
-
96
- image_inputs = [np .random .randint (255 , size = (3 , 30 , 400 ), dtype = np .uint8 )]
97
-
98
- image_inputs = [Image .fromarray (np .moveaxis (x , 0 , - 1 )) for x in image_inputs ]
99
-
100
- return image_inputs
101
-
102
97
def test_save_load_pretrained_default (self ):
103
98
tokenizer_slow = self .get_tokenizer ()
104
99
tokenizer_fast = self .get_rust_tokenizer ()
0 commit comments