Neural Network - #3 fix
This commit is contained in:
parent
f416812251
commit
f4ffb21a27
33
TesterRandom.py
Normal file
33
TesterRandom.py
Normal file
@ -0,0 +1,33 @@
|
||||
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()
|
Loading…
Reference in New Issue
Block a user