Created
May 11, 2023 06:34
-
-
Save tklee1975/5e98bdfd6ece62834038b2de10011ef1 to your computer and use it in GitHub Desktop.
Simple Testing Image Classification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imagePath = "test.jpg" | |
# Replace this with the path to your image | |
image = Image.open(imagePath).convert("RGB") | |
# resizing the image to be at least 224x224 and then cropping from the center | |
size = (224, 224) | |
# image = ImageOps.fit(image, size, resample=Image.BICUBIC) | |
image = image.resize(size, resample=Image.BICUBIC) | |
# turn the image into a numpy array | |
image_array = np.asarray(image) | |
# Normalize the image | |
normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1 | |
# Load the image into the array | |
data[0] = normalized_image_array | |
# Predicts the model | |
prediction = model.predict(data) | |
index = np.argmax(prediction) | |
class_name = class_names[index] | |
confidence_score = prediction[0][index] | |
# Print prediction and confidence score | |
print("Class:", class_name[2:], end="") | |
print("Confidence Score:", confidence_score) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment