-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_converting.py
More file actions
85 lines (70 loc) · 2.97 KB
/
Copy pathdata_converting.py
File metadata and controls
85 lines (70 loc) · 2.97 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
# -*- coding: utf-8 -*-
"""data_Converting.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Nd7tjzC2bnvvHudIRlWJ5858b-yzWbet
"""
#total no. data
print(len(face_arrr))
print(len(label_arrr))
#import the data in x and y train , test , accuracy.
import numpy as np
from sklearn.model_selection import train_test_split
import numpy as np
from keras.utils import np_utils
from sklearn.preprocessing import LabelEncoder
label_encoder = LabelEncoder()
x_train,x_test,y_train,y_test = train_test_split(face_arrr,label_arrr,test_size=0.2)
x_train,x_val,y_train,y_val = train_test_split(x_train,y_train,test_size=0.2)
classes = set(label_arrr)
number_classes = list(classes)
print(len(number_classes))
number_classes=len(number_classes)
#converting list = array
x_train_arr = np.array(x_train)
print(x_train_arr.shape)
print(type(x_train_arr))
x_test_arr = np.array(x_test)
print(x_test_arr.shape)
print(type(x_test_arr))
x_val_arr = np.array(x_val)
print(x_val_arr.shape)
print(type(x_val_arr))
code_y_train = np.array(y_train)
vec_y_train = label_encoder.fit_transform(code_y_train)
code_y_test = np.array(y_test)
vec_y_test = label_encoder.fit_transform(code_y_test)
code_y_val = np.array(y_val)
vec_y_val = label_encoder.fit_transform(code_y_val)
y_train_arr = np_utils.to_categorical(vec_y_train)
print(y_train_arr.shape)
print(type(y_train_arr))
y_test_arr = np_utils.to_categorical(vec_y_test)
print(type(y_test_arr))
print(y_test_arr.shape)
y_val_arr = np_utils.to_categorical(vec_y_val)
print(y_val_arr.shape)
print(type(y_val_arr))
X_train=x_train_arr/255.0
X_val=x_val_arr/255.0
X_test=x_test_arr/255.0
print(X_train.shape)
print(X_test.shape)
print(X_val.shape)
batch_size=32
#save the load data into pickle form.
import numpy as np
np.save('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_1/X_train_all.npy', x_train_arr)
np.save('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_1/X_test_all.npy', x_test_arr)
np.save('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_1/X_val_all.npy', x_val_arr)
np.save('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_1/y_train_all.npy', y_train_arr)
np.save('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_1/y_test_all.npy',y_test_arr)
np.save('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_1/y_val_all.npy', y_val_arr)
#loading the data
import numpy as np
X_train = np.load('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_2/X_train_all.npy')
X_test = np.load('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_2/X_test_all.npy')
X_val = np.load('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_2/X_val_all.npy')
y_train_arr = np.load('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_2/y_train_all.npy')
y_test_arr = np.load('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_2/y_test_all.npy')
y_val_arr = np.load('/content/gdrive/MyDrive/face_recognition/Faces/add/dataset_2/y_val_all.npy')