| | """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
|
| | """
|
| |
|
| | image = image.resize(target_size, Image.LANCZOS)
|
| |
|
| |
|
| | img_array = np.array(image) / 255.0
|
| |
|
| |
|
| | 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)
|
| |
|