8.2 Testing Alexnet Model

 Program:


import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import load_img, img_to_array
#from tensorflow.keras.applications.resnet50 import preprocess_input
import matplotlib.pyplot as plt

# Load the saved model
model = load_model('/content/drive/MyDrive/8/alexnet_cifar10.h5')
d={0:"Airplane",1:"Automobile",2:"Bird",3:"Cat",4:"Deer",5:"Dog",6:"Frog",
   7:"Horse",8:"Ship",9:"Truck"}
# Load and preprocess an image from a local path for prediction
local_image_path = '/content/drive/MyDrive/8/a.jpg'  # Replace with the path to your local image
local_image = load_img(local_image_path, target_size=(32, 32))
local_image1 = load_img(local_image_path)
local_image_array = img_to_array(local_image)
local_image_array = np.expand_dims(local_image_array, axis=0)
local_image_array /= 255.0  # Apply simple normalization, not preprocess_input

# Make a prediction for the local image
local_predictions = model.predict(local_image_array)
local_predicted_class = np.argmax(local_predictions[0])

# Display the image and prediction
plt.imshow(local_image)
plt.title(f"Predicted Class: {d[local_predicted_class]}")
plt.axis('off')
plt.show()

plt.imshow(local_image1, interpolation='nearest')
plt.title(f"Predicted Class: {d[local_predicted_class]}")
plt.axis('off')
plt.show()


link to images to predict:

https://drive.google.com/drive/folders/1S34ART1LbDlOJsEwxogRxsLCtq_BVAhc?usp=sharing


The CIFAR-10 dataset consists of 10 classes of images. Here is the list of classes in the CIFAR-10 dataset:

  1. Airplane
  2. Automobile
  3. Bird
  4. Cat
  5. Deer
  6. Dog
  7. Frog
  8. Horse
  9. Ship
  10. Truck
So one should test only these Images

Comments

Popular posts from this blog

11. List of Capstone Projects for SOC - Deep Learning

8. Advanced CNN (Build AlexNet using Advanced CNN)