33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import tensorflow as tf
|
|
from tensorflow import keras
|
|
from tensorflow.keras.preprocessing import image
|
|
import numpy as np
|
|
import os
|
|
|
|
# Load the trained model
|
|
model = keras.models.load_model('trained_model.h5')
|
|
|
|
# Load the class names
|
|
class_names = ['Empty', 'Food','People']
|
|
|
|
# Path to the folder containing test images
|
|
test_images_folder = 'Testing/
|
|
|
|
# Iterate over the test images
|
|
for filename in os.listdir(test_images_folder):
|
|
if filename.endswith('.jpg') or filename.endswith('.jpeg') or filename.endswith('.png'):
|
|
# Load and preprocess the test image
|
|
image_path = os.path.join(test_images_folder, filename)
|
|
test_image = image.load_img(image_path, target_size=(224, 224))
|
|
test_image = image.img_to_array(test_image)
|
|
test_image = np.expand_dims(test_image, axis=0)
|
|
test_image = test_image / 255.0 # Normalize the image
|
|
|
|
# Make predictions
|
|
predictions = model.predict(test_image)
|
|
predicted_class_index = np.argmax(predictions[0])
|
|
predicted_class = class_names[predicted_class_index]
|
|
|
|
print('Image:', filename)
|
|
print('Predicted class:', predicted_class)
|
|
print() |