misinformation-detector / src /utils /preprocessing.py
ShreyasGosavi's picture
Upload 37 files
53bec59 verified
raw
history blame contribute delete
743 Bytes
"""Preprocessing utilities."""
import numpy as np
from PIL import Image
from typing import Tuple
def preprocess_image(image: Image.Image, target_size: Tuple[int, int] = (299, 299)) -> np.ndarray:
"""
Preprocess image for model input.
Args:
image: PIL Image
target_size: Target dimensions
Returns:
Preprocessed image array
"""
# Resize
image = image.resize(target_size, Image.LANCZOS)
# Convert to array
img_array = np.array(image) / 255.0
# Normalize
mean = np.array([0.485, 0.456, 0.406])
std = np.array([0.229, 0.224, 0.225])
img_array = (img_array - mean) / std
return img_array.astype(np.float32)