-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_face_re.py
56 lines (50 loc) · 1.74 KB
/
load_face_re.py
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
# -*- coding: utf-8 -*-
import os
import numpy as np
import cv2
import scipy.io as sio
#读取训练数据
images1 = []
labels1 = []
images2 = []
labels2 = []
def read_train_re(path_name):
for dir_item in os.listdir(path_name):
full_path = os.path.abspath(os.path.join(path_name, dir_item))
if "train" in full_path:
if os.path.isdir(full_path):
read_train_re(full_path)
else:
if dir_item.endswith('.jpg'):
image = cv2.imread(full_path,1)
images1.append(image)
dirname=path_name.index("train\\")+6
labels1.append(int(path_name[dirname])-1)
return images1,labels1
def read_test_re(path_name):
for dir_item in os.listdir(path_name):
full_path = os.path.abspath(os.path.join(path_name, dir_item))
if "test" in full_path:
if os.path.isdir(full_path):
read_test_re(full_path)
else:
if dir_item.endswith('.jpg'):
image = cv2.imread(full_path,1) # 0为加载灰度图像,1为加载彩色图像
images2.append(image)
dirname=path_name.index("test\\")+5
labels2.append(int(path_name[dirname])-1)
return images2,labels2
def load_train_re(path_name):
images,labels = read_train_re(path_name)
images = np.array(images)
print("train: ")
print(images.shape)
labels = np.array(labels)
return images,labels
def load_test_re(path_name):
images,labels = read_test_re(path_name)
images = np.array(images)
print("test: ")
print(images.shape)
labels = np.array(labels)
return images,labels