Upload processor
Browse files- image_processing_efficientnet.py +27 -0
- preprocessor_config.json +27 -0
image_processing_efficientnet.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers.image_processing_utils import BaseImageProcessor, BatchFeature
|
| 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.model_name = model_name
|
| 17 |
+
self.config = resolve_data_config({}, model=create_model(model_name, pretrained=False))
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def preprocess(self, image):
|
| 21 |
+
transforms = create_transform(**self.config)
|
| 22 |
+
data = {'pixel_values': transforms(image).unsqueeze(0)}
|
| 23 |
+
return BatchFeature(data=data)
|
| 24 |
+
|
| 25 |
+
__all__ = [
|
| 26 |
+
"EfficientNetImageProcessor"
|
| 27 |
+
]
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoImageProcessor": "image_processing_efficientnet.EfficientNetImageProcessor"
|
| 4 |
+
},
|
| 5 |
+
"config": {
|
| 6 |
+
"crop_mode": "center",
|
| 7 |
+
"crop_pct": 0.9,
|
| 8 |
+
"input_size": [
|
| 9 |
+
3,
|
| 10 |
+
240,
|
| 11 |
+
240
|
| 12 |
+
],
|
| 13 |
+
"interpolation": "bicubic",
|
| 14 |
+
"mean": [
|
| 15 |
+
0.5,
|
| 16 |
+
0.5,
|
| 17 |
+
0.5
|
| 18 |
+
],
|
| 19 |
+
"std": [
|
| 20 |
+
0.5,
|
| 21 |
+
0.5,
|
| 22 |
+
0.5
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
"image_processor_type": "EfficientNetImageProcessor",
|
| 26 |
+
"model_name": "efficientnet_b1"
|
| 27 |
+
}
|