Upload processor
Browse files- image_processing_efficientnet.py +25 -26
image_processing_efficientnet.py
CHANGED
|
@@ -1,27 +1,26 @@
|
|
| 1 |
-
from transformers.image_processing_utils import BaseImageProcessor, BatchFeature
|
| 2 |
-
from
|
| 3 |
-
from timm import
|
| 4 |
-
from timm.data import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
self.
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
data
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
"EfficientNetImageProcessor"
|
| 27 |
]
|
|
|
|
| 1 |
+
from transformers.image_processing_utils import BaseImageProcessor, BatchFeature
|
| 2 |
+
from timm import create_model
|
| 3 |
+
from timm.data import resolve_data_config
|
| 4 |
+
from timm.data.transforms_factory import create_transform
|
| 5 |
+
|
| 6 |
+
class EfficientNetImageProcessor(BaseImageProcessor):
|
| 7 |
+
model_input_names = ["pixel_values"]
|
| 8 |
+
|
| 9 |
+
def __init__(self,
|
| 10 |
+
model_name: str,
|
| 11 |
+
**kwargs
|
| 12 |
+
):
|
| 13 |
+
super().__init__(**kwargs)
|
| 14 |
+
|
| 15 |
+
self.model_name = model_name
|
| 16 |
+
self.config = resolve_data_config({}, model=create_model(model_name, pretrained=False))
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def preprocess(self, image):
|
| 20 |
+
transforms = create_transform(**self.config)
|
| 21 |
+
data = {'pixel_values': transforms(image).unsqueeze(0)}
|
| 22 |
+
return BatchFeature(data=data)
|
| 23 |
+
|
| 24 |
+
__all__ = [
|
| 25 |
+
"EfficientNetImageProcessor"
|
|
|
|
| 26 |
]
|