-
Notifications
You must be signed in to change notification settings - Fork 0
/
predictor
65 lines (53 loc) · 2.01 KB
/
predictor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import cv2
import pickle
import numpy as np
from time import time
from keras import utils
from keras.optimizers import Adam
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from keras.models import load_model
classes = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', 'nothing', 'space', 'del']
# Load the model
with open ('CNNtranslator/data.pickle', 'rb') as f:
test = pickle.load(f)
x_train = test[0]
x_test = test[1]
y_train = test[2]
y_test = test[3]
model = load_model('CNNtranslator/model.h5')
#c:\Users\Luo\Downloads\D10.jpgclasses = 29
batch = 128
epochs = 2
learning_rate = 0.001
#history = model.fit(x_train, y_train, batch_size=batch, epochs=epochs, validation_split=0.1, shuffle = True, verbose=1)
from keras.preprocessing import image
# Load the image
img = image.load_img("CNNtranslator/C10.png", target_size=(32, 32))
img1 = image.load_img("CNNtranslator/W11.png", target_size=(32, 32))
# Convert the image to a numpy array
img_array = image.img_to_array(img)
#img_array = img_array.reshape(32, 32) # Assumes the input shape is (width, height, 3)
img_array1 = image.img_to_array(img1)
# Add an extra dimension because the model expects batches of images
img_batch = np.expand_dims(img_array, axis=0)
img_batch2 = np.expand_dims(img_array1, axis=0)
# Normalize image
#img_batch /= 255.
#img_batch2 /= 255.
# Predict
prediction = (model.predict(img_batch))
prediction1 = (model.predict(img_batch2))
print(prediction)
print(prediction1)
predicted_class = np.argmax(prediction)
# Map the predicted class with its corresponding label
predicted_label = classes[predicted_class]
max_index1 = np.argmax(prediction1)
print("Predicted class: ", predicted_label)
print("Predicted class: ", classes[max_index1])