Skip to content

Commit

Permalink
testing trained model with sample image
Browse files Browse the repository at this point in the history
  • Loading branch information
namannarula committed May 20, 2021
1 parent 11e8d5d commit 03c4a9b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Binary file added testimg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions testing_trained_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from keras.models import load_model
import cv2
import numpy as np

# Path where the sample image is stored
FILE_PATH = "testimg.png"

# Path where the trained model is stored
MODEL_PATH = "rock-paper-scissors-trained.h5"

# Defining class map for each label
CLASS_MAP = {
0: "rock",
1: "paper",
2: "scissors",
}
def mapper(val):
return CLASS_MAP[val]

# Loading the trained model
model = load_model(MODEL_PATH)

# Preparing the image
img = cv2.imread(FILE_PATH)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (148, 148))

# Predicting the name
pred = model.predict(np.array([img]))
pred_label = np.argmax(pred[0])
label_value = mapper(pred_label)

# Predicting the final result
print("Predicted: {}".format(label_value))

0 comments on commit 03c4a9b

Please sign in to comment.