| import tensorflow as tf | |
| def preprocess_image(image_path, target_size=(299, 299)): | |
| """ | |
| Preprocesses a chest X-ray image for the model. | |
| Args: | |
| image_path: Path to the image file | |
| target_size: Target size for resizing | |
| Returns: | |
| Preprocessed image tensor ready for prediction | |
| """ | |
| # Read image | |
| img = tf.io.read_file(image_path) | |
| img = tf.image.decode_image(img, channels=3) | |
| # Resize | |
| img = tf.image.resize(img, target_size) | |
| # Normalize to [0,1] | |
| img = img / 255.0 | |
| # Add batch dimension | |
| img = tf.expand_dims(img, 0) | |
| return img | |