import cv2 import numpy as np import tensorflow as tf def preprocess_image(img): """Preprocess a single image for prediction.""" img = tf.image.decode_jpeg(img, channels=1) img= tf.image.resize(img, (224, 224)) img_flattened = tf.reshape(img, (-1,)) # Convert to 2D array (expected input format for the model) img_flattened = np.expand_dims(img_flattened, axis=0) # Shape: (1, features) return img_flattened def predict_single_image(model, image): """Predict the label of a single image.""" # Preprocess the image processed_image = preprocess_image(image) # Make prediction prediction = model.predict(processed_image) return prediction[0] # Return the predicted label # Test the single image