-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing trained model with sample image
- Loading branch information
1 parent
11e8d5d
commit 03c4a9b
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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)) |