Repository navigation
Expand file tree
/
Copy pathPredict.py
More file actions
102 lines (93 loc) · 2.76 KB
/
Copy pathPredict.py
File metadata and controls
102 lines (93 loc) · 2.76 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from keras.layers import Conv2D, Dense, Dropout, Flatten, MaxPooling2D, ZeroPadding2D
from keras.models import Sequential, load_model
from keras.optimizers import Adam
from keras.preprocessing import image
from sklearn.utils import class_weight
from keras.applications.vgg16 import VGG16
import keras
from keras.models import Model
from keras.callbacks import Callback, EarlyStopping, ReduceLROnPlateau, ModelCheckpoint
import sklearn
import h5py
import os
import cv2
import skimage
from skimage.transform import resize
import pandas as pd
import numpy as np
from keras.utils.np_utils import to_categorical
from sklearn.model_selection import train_test_split
from skimage.color import rgb2lab
from tqdm import tqdm
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import cross_val_score
from scipy import ndimage
def olhafunc(indice):
if indice == 0:
return 'A'
elif indice == 1:
return 'B'
elif indice == 2:
return 'C'
elif indice == 3:
return 'D'
elif indice == 4:
return 'E'
elif indice == 5:
return 'F'
elif indice == 6:
return 'G'
elif indice == 7:
return 'H'
elif indice == 8:
return 'I'
elif indice == 9:
return 'J'
elif indice == 10:
return 'K'
elif indice == 11:
return 'L'
elif indice == 12:
return 'M'
elif indice == 13:
return 'N'
elif indice == 14:
return 'O'
elif indice == 15:
return 'P'
elif indice == 16:
return 'Q'
elif indice == 17:
return 'R'
elif indice == 18:
return 'S'
elif indice == 19:
return 'T'
elif indice == 20:
return 'U'
elif indice == 21:
return 'V'
elif indice == 22:
return 'W'
elif indice == 23:
return 'X'
elif indice == 24:
return 'Y'
elif indice == 25:
return 'Z'
cnn_model = load_model('/home/lavid-deep/Sign4Text/ModeloASLDuplamenteTreinadoRGB20E64SOBEL.h5')
imagens = []
for image_filename in tqdm(os.listdir("/home/lavid-deep/Sign4Text/asl_alphabet_train/T/")):
img_file = cv2.imread("/home/lavid-deep/Sign4Text/asl_alphabet_train/T/" + image_filename, 0)
if img_file is not None:
#img_file = rgb2lab(img_file / 255.0)[:,:,0]
img_file = skimage.transform.resize(img_file, (64, 64, 3), mode='reflect')
dx = ndimage.sobel(img_file, 0)
dy = ndimage.sobel(img_file, 1)
img_file = np.hypot(dx, dy)
img_arr = np.asarray(img_file.astype(np.float16))
img_arr = img_arr.reshape((1, 64, 64, 3))
print("\n" * 2)
print(cnn_model.predict(img_arr))
print("\n" * 2)
print(olhafunc(np.argmax(cnn_model.predict(img_arr))))