Skip to content

Commit

Permalink
feat: Add ResizeCenterCropNormalize transform for image preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
healthonrails committed Oct 23, 2024
1 parent 483db88 commit fe9bd47
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions annolid/behavior/data_loading/transforms.py
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
])

0 comments on commit fe9bd47

Please sign in to comment.