Upload processor_flamingo.py with huggingface_hub
Browse files- processor_flamingo.py +8 -7
processor_flamingo.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from transformers import ProcessorMixin, AutoProcessor
|
2 |
from transformers.models.auto.processing_auto import AutoProcessor
|
3 |
from transformers.processing_utils import ProcessorMixin
|
|
|
4 |
import json
|
5 |
import os
|
6 |
|
@@ -8,12 +9,12 @@ class FlamingoProcessor(ProcessorMixin):
|
|
8 |
"""
|
9 |
Custom processor that combines a tokenizer and feature extractor.
|
10 |
"""
|
11 |
-
attributes = ["
|
12 |
-
|
13 |
tokenizer_class = "AutoTokenizer"
|
14 |
|
15 |
-
def __init__(self,
|
16 |
-
super().__init__(
|
17 |
|
18 |
def __call__(self, text=None, images=None, **kwargs):
|
19 |
"""
|
@@ -22,7 +23,7 @@ class FlamingoProcessor(ProcessorMixin):
|
|
22 |
Args:
|
23 |
text: Text input(s) to tokenize
|
24 |
images: Image input(s) to process
|
25 |
-
**kwargs: Additional arguments passed to tokenizer/
|
26 |
|
27 |
Returns:
|
28 |
Dictionary with processed inputs
|
@@ -43,12 +44,12 @@ class FlamingoProcessor(ProcessorMixin):
|
|
43 |
|
44 |
# Process images if provided
|
45 |
if images is not None:
|
46 |
-
image_encoding = self.
|
47 |
# Add prefix to avoid key conflicts
|
48 |
for key, value in image_encoding.items():
|
49 |
encoding[f"pixel_values" if key == "pixel_values" else f"image_{key}"] = value
|
50 |
|
51 |
-
return encoding
|
52 |
|
53 |
def batch_decode(self, *args, **kwargs):
|
54 |
"""
|
|
|
1 |
from transformers import ProcessorMixin, AutoProcessor
|
2 |
from transformers.models.auto.processing_auto import AutoProcessor
|
3 |
from transformers.processing_utils import ProcessorMixin
|
4 |
+
from transformers.tokenization_utils_base import BatchEncoding
|
5 |
import json
|
6 |
import os
|
7 |
|
|
|
9 |
"""
|
10 |
Custom processor that combines a tokenizer and feature extractor.
|
11 |
"""
|
12 |
+
attributes = ["image_processor", "tokenizer"]
|
13 |
+
image_processor_class = "AutoImageProcessor"
|
14 |
tokenizer_class = "AutoTokenizer"
|
15 |
|
16 |
+
def __init__(self, image_processor, tokenizer):
|
17 |
+
super().__init__(image_processor, tokenizer)
|
18 |
|
19 |
def __call__(self, text=None, images=None, **kwargs):
|
20 |
"""
|
|
|
23 |
Args:
|
24 |
text: Text input(s) to tokenize
|
25 |
images: Image input(s) to process
|
26 |
+
**kwargs: Additional arguments passed to tokenizer/image_processor
|
27 |
|
28 |
Returns:
|
29 |
Dictionary with processed inputs
|
|
|
44 |
|
45 |
# Process images if provided
|
46 |
if images is not None:
|
47 |
+
image_encoding = self.image_processor(images, **kwargs)
|
48 |
# Add prefix to avoid key conflicts
|
49 |
for key, value in image_encoding.items():
|
50 |
encoding[f"pixel_values" if key == "pixel_values" else f"image_{key}"] = value
|
51 |
|
52 |
+
return BatchEncoding(encoding)
|
53 |
|
54 |
def batch_decode(self, *args, **kwargs):
|
55 |
"""
|