Neural Network - #3 fix

This commit is contained in:
Mirrowel 2023-06-01 22:55:06 +02:00
parent f416812251
commit f4ffb21a27
2 changed files with 33 additions and 0 deletions

33
TesterRandom.py Normal file
View 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()

BIN
mode2.h5

Binary file not shown.