This code loads an image using OpenCV, makes a prediction on it using a model, and prints the predicted label. The image is then displayed using Matplotlib, reshaped to a 48x48 matrix and mapped to grayscale colors.
image = 'images/train/sad/42.jpg'
print("original image is of sad")
img = ef(image)
pred = model.predict(img)
pred_label = label[pred.argmax()]
print("model prediction is ",pred_label)
plt.imshow(img.reshape(48,48),cmap='gray')
# Import necessary libraries for image processing and visualization
import cv2 as ef # Assuming 'ef' is an alias for OpenCV
import matplotlib.pyplot as plt
# Load image from file
image = 'images/train/sad/42.jpg'
# Print original image label
print("original image is of sad")
# Load image using OpenCV
img = ef.imread(image)
# Make prediction using a model
pred = model.predict(img)
# Get predicted label
pred_label = label[pred.argmax()]
# Print predicted label
print("model prediction is ", pred_label)
# Display image using Matplotlib
plt.imshow(img.reshape(48,48), cmap='gray')
imread
function.argmax
method on the prediction output.imshow
function, reshaped to a 48x48 matrix and with grayscale color mapping.