Skip to content

Instantly share code, notes, and snippets.

@EnkrateiaLucca
Created March 27, 2023 18:06
Show Gist options
  • Save EnkrateiaLucca/e9f00a7230a69eadecae69f5bd4bf247 to your computer and use it in GitHub Desktop.
Save EnkrateiaLucca/e9f00a7230a69eadecae69f5bd4bf247 to your computer and use it in GitHub Desktop.
from tensorflow.keras.models import load_model
import numpy as np
import cv2
import random
import glob
import pickle
def show_image(img,title=""):
cv2.imshow(title, img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Load the trained model
model = load_model('/home/lucassoares/Desktop/projects/biometrid/dev_document_rotation/rotation_model')
# Load and preprocess the image
for image_path in glob.glob("/home/lucassoares/Desktop/projects/biometrid/dev_document_rotation/data/eval_images/*"):
print("Image Path: ")
print(image_path)
img = cv2.imread(image_path)
img = cv2.resize(img, (600, 600)) # Resize the image to match input size used in training
img = img.astype('float32') / 255.0 # Normalize pixel values
# Generate prediction on the image
prediction = model.predict(np.expand_dims(img, axis=0))[0]
print("Prediction: ", prediction)
# Convert prediction from probabilities to class label
class_label = np.argmax(prediction)
# Load the labels from the pickle file
with open('./lastClassesCore.pickle', 'rb') as f:
labels = pickle.load(f)
predicted_label = labels.classes_[class_label]
print("Predicted Label: ", predicted_label)
show_image(img, title=predicted_label)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment