Views
No views yet
| Metric | Value |
|---|---|
| Accuracy | 0.8418 |
| Precision | 0.8509 |
| Recall | 0.8981 |
| Loss | 0.3919 |
1import tensorflow as tf
2import numpy as np
3from PIL import Image
4
5# Load model
6model = tf.keras.models.load_model('fine_tuned_phone_detection_model.h5')
7
8def predict_phone_usage(image_path):
9 # Preprocess image
10 img = Image.open(image_path).convert("RGB")
11 img = img.resize((224, 224))
12 img_array = np.array(img) / 255.0
13 img_array = np.expand_dims(img_array, axis=0)
14
15 # Predict
16 prediction = model.predict(img_array)[0][0]
17 class_names = ['no_phone', 'using_phone']
18 result = class_names[1] if prediction > 0.5 else class_names[0]
19 confidence = prediction if prediction > 0.5 else 1 - prediction
20
21 return result, confidence