Upload src/preprocess.py with huggingface_hub
Browse files- src/preprocess.py +30 -0
src/preprocess.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Image preprocessing pipeline for Imager-1-Tiny."""
|
| 2 |
+
from torchvision import transforms
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
IMAGENET_MEAN = [0.485, 0.456, 0.406]
|
| 6 |
+
IMAGENET_STD = [0.229, 0.224, 0.225]
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_transform(train: bool = False):
|
| 10 |
+
"""
|
| 11 |
+
Return the torchvision transform pipeline.
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
train: If True, returns the training pipeline with augmentation.
|
| 15 |
+
If False, returns the deterministic inference pipeline.
|
| 16 |
+
"""
|
| 17 |
+
if train:
|
| 18 |
+
return transforms.Compose([
|
| 19 |
+
transforms.Resize(256),
|
| 20 |
+
transforms.RandomResizedCrop(224, scale=(0.8, 1.0)),
|
| 21 |
+
transforms.RandomHorizontalFlip(),
|
| 22 |
+
transforms.ToTensor(),
|
| 23 |
+
transforms.Normalize(mean=IMAGENET_MEAN, std=IMAGENET_STD),
|
| 24 |
+
])
|
| 25 |
+
return transforms.Compose([
|
| 26 |
+
transforms.Resize(256),
|
| 27 |
+
transforms.CenterCrop(224),
|
| 28 |
+
transforms.ToTensor(),
|
| 29 |
+
transforms.Normalize(mean=IMAGENET_MEAN, std=IMAGENET_STD),
|
| 30 |
+
])
|