-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_save_data.py
More file actions
80 lines (66 loc) · 2.21 KB
/
random_save_data.py
File metadata and controls
80 lines (66 loc) · 2.21 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
# Randomize the data and save it into different numpy array
import os
from tqdm import tqdm
import cv2
import numpy as np
import random
folderTrain = "asl-alphabet/asl_alphabet_train"
folderTest = "asl-alphabet/asl_alphabet_test"
xTrain = []
yTrain = []
xTest = []
yTest = []
imageLabel =[]
imageName =[]
index =0
for folderName in os.listdir(folderTrain):
if not folderName.startswith("."):
for Name in tqdm(os.listdir(folderTrain + '/' + folderName)):
if not Name.startswith('.') and index <=1500:
index +=1
imageName.append(folderTrain+'/'+folderName+'/'+Name)
index = 0
random.shuffle(imageName)
print('------------------------')
print(imageName)
for image in tqdm(imageName):
img = cv2.imread(image)
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.resize(img, (100, 100))
xTrain.append(img)
try:
yTrain.append(ord(image[image.find("/",30)+1:image.find("/",32)])-65)
except:
if image[image.find("/",30)+1:image.find("/",32)] == "space":
yTrain.append(26)
elif image[image.find("/",30)+1:image.find("/",32)] == "nothing":
yTrain.append(27)
elif image[image.find("/",30)+1:image.find("/",32)] == "del":
yTrain.append(28)
xTrain = np.array(xTrain)
yTrain = np.array(yTrain)
# print(xTrain)
# print(yTrain)
np.save("data_greyScale/xtrainRandom100.npy", xTrain)
np.save("data_greyScale/ytrainRandom100.npy", yTrain)
for testName in os.listdir(folderTest):
if not testName.startswith("."):
if testName[1] =="_":
label = ord(testName[0]) - 65
else:
if testName == "space_test.jpg":
label = 26
elif testName == "nothing_test.jpg":
label = 27
elif testName == 'del595.jpg':
label = 28
img = cv2.imread(folderTest+'/'+testName)
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.resize(img, (100, 100))
xTest.append(img)
yTest.append(label)
print(folderTest+'/'+testName)
xTest = np.array(xTest)
yTest = np.array(yTest)
np.save("data_greyScale/xTestRandom100.npy",xTest)
np.save("data_greyScale/yTestRandom100.npy",yTest)