Upload processor
Browse files- image_processing_efficientnet.py +25 -0
- preprocessor_config.json +26 -0
image_processing_efficientnet.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers.image_processing_utils import BaseImageProcessor
|
| 2 |
+
from configuration_efficientnet import MODEL_NAMES
|
| 3 |
+
from timm import create_model
|
| 4 |
+
from timm.data import resolve_data_config
|
| 5 |
+
from timm.data.transforms_factory import create_transform
|
| 6 |
+
|
| 7 |
+
class EfficientNetImageProcessor(BaseImageProcessor):
|
| 8 |
+
model_input_names = ["pixel_values"]
|
| 9 |
+
|
| 10 |
+
def __init__(self,
|
| 11 |
+
model_name: str,
|
| 12 |
+
**kwargs
|
| 13 |
+
):
|
| 14 |
+
super().__init__(**kwargs)
|
| 15 |
+
|
| 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 |
+
return transforms(image).unsqueeze(0)
|
| 22 |
+
|
| 23 |
+
__all__ = [
|
| 24 |
+
"EfficientNetImageProcessor"
|
| 25 |
+
]
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoImageProcessor": "image_processing_efficientnet.EfficientNetImageProcessor"
|
| 4 |
+
},
|
| 5 |
+
"config": {
|
| 6 |
+
"crop_mode": "center",
|
| 7 |
+
"crop_pct": 0.875,
|
| 8 |
+
"input_size": [
|
| 9 |
+
3,
|
| 10 |
+
224,
|
| 11 |
+
224
|
| 12 |
+
],
|
| 13 |
+
"interpolation": "bicubic",
|
| 14 |
+
"mean": [
|
| 15 |
+
0.485,
|
| 16 |
+
0.456,
|
| 17 |
+
0.406
|
| 18 |
+
],
|
| 19 |
+
"std": [
|
| 20 |
+
0.229,
|
| 21 |
+
0.224,
|
| 22 |
+
0.225
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
"image_processor_type": "EfficientNetImageProcessor"
|
| 26 |
+
}
|