-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ResizeCenterCropNormalize transform for image preprocessing
- Loading branch information
1 parent
483db88
commit fe9bd47
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from torchvision import transforms | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
IMG_SIZE = 224 # Default image size | ||
|
||
|
||
class ResizeCenterCropNormalize(transforms.Compose): | ||
""" | ||
Resizes, center crops, and normalizes an image. | ||
Args: | ||
size (int, optional): The target size of the image after resizing and cropping. Defaults to 224. | ||
""" | ||
|
||
def __init__(self, size: int = IMG_SIZE): | ||
super().__init__([ | ||
# Resize with a buffer for better quality | ||
transforms.Resize(int(size * 1.14)), | ||
transforms.CenterCrop(size), | ||
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[ | ||
0.229, 0.224, 0.225]), # ImageNet normalization | ||
]) |