import numpy as np
import tensorflow as tf
from tensorflow.keras.preprocessing.image import load_img, img_to_array
Load your TFLite model
interpreter = tf.lite.Interpreter(model_path='/path/to/your/mobilenet_mask2.tflite') # Update with your TFLite model path
interpreter.allocate_tensors()
import numpy as np import tensorflow as tf from tensorflow.keras.preprocessing.image import load_img, img_to_array
Load your TFLite model
interpreter = tf.lite.Interpreter(model_path='/path/to/your/mobilenet_mask2.tflite') # Update with your TFLite model path interpreter.allocate_tensors()
Get input and output details
input_details = interpreter.get_input_details() output_details = interpreter.get_output_details()
Function to predict if an image has glasses or not using TFLite
def predict_image(image_path):
Load and preprocess the image
Provide the path to the image from your internal storage
image_path = '/path/to/your/image.jpg' # Update this with the path to your image file predicted_class = predict_image(image_path)
Display the prediction result
result = 'No MASK' if predicted_class[0][0] == 1 else 'MASK' print(f'Prediction: {result}')