-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_databases.py
78 lines (57 loc) · 2.89 KB
/
list_databases.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import numpy as np
import sys
import math
import operator
import csv
import glob,os
import xlrd
import pandas as pd
from utilities import Read_Input_Images, get_subfolders_num, data_loader_with_LOSO, label_matching, duplicate_channel
from utilities import record_scores, LossHistory, filter_objective_samples
from utilities import loading_samm_table, loading_smic_table, loading_casme_table, ignore_casme_samples, ignore_casmergb_samples, loading_casme_objective_table
from utilities import get_vid_per_subject
def load_db(db_path, list_db, spatial_size, objective_flag):
db_name = list_db[0]
db_home = db_path + db_name + "/"
db_images = db_path + db_name + "/" + db_name + "/"
cross_db_flag = 0
print(db_name)
if db_name == 'CASME2_Optical':
print("arrived")
table = loading_casme_table(db_home + 'CASME2_label_Ver_2.xls')
listOfIgnoredSamples, IgnoredSamples_index = ignore_casme_samples(db_path, list_db)
r = w = spatial_size
subjects=26
samples = 246
n_exp = 5
#VidPerSubject = get_subfolders_num(db_images, IgnoredSamples_index)
VidPerSubject = get_vid_per_subject(table, ['fear', 'sadness'])
timesteps_TIM = 9
data_dim = r * w
channel = 3
if os.path.isdir(db_home + "Classification/" + db_name + "_label.txt" ) == True:
os.remove(db_home + "Classification/" + db_name + "_label.txt")
return r, w, subjects, samples, n_exp, VidPerSubject, timesteps_TIM, data_dim, channel, table, listOfIgnoredSamples, db_home, db_images, cross_db_flag
def restructure_data(subject, subperdb, labelpersub, subjects, n_exp, r, w, timesteps_TIM, channel):
Train_X, Train_Y, Test_X, Test_Y, Test_Y_gt = data_loader_with_LOSO(subject, subperdb, labelpersub, subjects, n_exp)
# Rearrange Training labels into a vector of images, breaking sequence
Train_X_spatial = Train_X.reshape(Train_X.shape[0]*timesteps_TIM, r, w, channel)
Test_X_spatial = Test_X.reshape(Test_X.shape[0]* timesteps_TIM, r, w, channel)
# Extend Y labels 10 fold, so that all images have labels
Train_Y_spatial = np.repeat(Train_Y, timesteps_TIM, axis=0)
Test_Y_spatial = np.repeat(Test_Y, timesteps_TIM, axis=0)
X = Train_X_spatial.reshape(Train_X_spatial.shape[0], channel, r, w)
y = Train_Y_spatial.reshape(Train_Y_spatial.shape[0], n_exp)
normalized_X = X.astype('float32') / 255.
test_X = Test_X_spatial.reshape(Test_X_spatial.shape[0], channel, r, w)
test_y = Test_Y_spatial.reshape(Test_Y_spatial.shape[0], n_exp)
normalized_test_X = test_X.astype('float32') / 255.
print ("Train_X_shape: " + str(np.shape(Train_X)))
print ("Train_Y_shape: " + str(np.shape(Train_Y)))
print ("Test_X_shape: " + str(np.shape(Test_X)))
print ("Test_Y_shape: " + str(np.shape(Test_Y)))
print ("X_shape: " + str(np.shape(X)))
print ("y_shape: " + str(np.shape(y)))
print ("test_X_shape: " + str(np.shape(test_X)))
print ("test_y_shape: " + str(np.shape(test_y)))
return Train_X, Train_Y, Test_Y, Test_Y, Test_Y_gt, X, y, test_X, test_y