Views
No views yet
(224, 224, 3)(224, 224).tensorflow.keras.applications.mobilenet.preprocess_input).1import cv2
2import numpy as np
3import tensorflow as tf
4from tensorflow.keras.applications.mobilenet import preprocess_input
5
6# Load the model
7model = tf.keras.models.load_model("background_mobilenet_v1.h5")
8
9# Preprocessing
10def preprocess_background(img_crop: np.ndarray) -> np.ndarray:
11 img_resized = cv2.resize(img_crop, (224, 224))
12 img_batch = np.expand_dims(img_resized, axis=0)
13 return preprocess_input(img_batch.astype(np.float32))
14
15# Run inference
16input_tensor = preprocess_background(image)
17prediction = model.predict(input_tensor)