forked from stevenwudi/chalearn2014_wudi_lio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Step_5_1_save_video_files.py
86 lines (70 loc) · 3.05 KB
/
Step_5_1_save_video_files.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
79
80
81
82
83
84
85
"""
Di Wu [email protected]
2015-06-12
"""
from numpy import log
from glob import glob
import os
import sys
import cPickle
from classes import GestureSample
# customized imports
# modular imports
# the hyperparameter set the data dir, use etc classes, it's important to modify it according to your need
from classes.hyperparameters import use, lr, batch, reg, mom, tr, drop,\
net, DataLoader_with_skeleton_normalisation
from functions.test_functions import *
from functions.train_functions import _shared, _avg, write, ndtensor, print_params, lin,\
training_report, epoch_report, _batch,\
save_results, move_results, save_params, test_lio_skel
from classes.hyperparameters import batch
from dbn.utils import normalize
from convnet3d_grbm_early_fusion import convnet3d_grbm_early_fusion
import scipy.io as sio
## Load Prior and transitional Matrix
dic=sio.loadmat('Prior_Transition_matrix_5states.mat')
Transition_matrix = dic['Transition_matrix']
Prior = dic['Prior']
# number of hidden states for each gesture class
STATE_NO = 5
#data path and store path definition
pc = "wudi"
if pc=="wudi":
data = r"E:\CHALEARN2014\Train" # dir of original data -- note that wudi has decompressed it!!!
data = '/idiap/user/dwu/chalearn/Test'
save_dst = "/idiap/user/dwu/chalearn/Test_CNN_precompute"
res_dir_ = "/idiap/user/dwu/chalearn/result/"
elif pc=="lio":
data = "/media/lio/Elements/chalearn/trainingset"
save_dst = " "
load_flag = False
os.chdir(data)
if pc=="wudi":
samples=glob("*.zip") # because wudi unzipped all the files already!
elif pc=="lio":
samples=glob("*.zip")
print len(samples), "samples found"
used_joints = ['ElbowLeft', 'WristLeft', 'ShoulderLeft', 'HandLeft',
'ElbowRight', 'WristRight', 'ShoulderRight', 'HandRight',
'Head', 'Spine', 'HipCenter']
for file_count, file in enumerate(samples):
condition = (file_count > -1)
if condition: #wudi only used first 650 for validation !!! Lio be careful!
save_path= os.path.join(save_dst, file)
if os.path.isfile(save_path):
print "loading exiting file"
data_dic = cPickle.load(open(save_path,'rb'))
video = data_dic["video"]
Feature_gesture = data_dic["Feature_gesture"]
assert video.shape[0] == Feature_gesture.shape[0]
else:
print("\t Processing file " + file)
# Create the object to access the sample
sample = GestureSample(os.path.join(data,file))
print "finish loading samples"
video, Feature_gesture = sample.get_test_data_wudi_lio(used_joints)
assert video.shape[0] == Feature_gesture.shape[0]# -*- coding: utf-8 -*-
print "finish preprocessing"
out_file = open(save_path, 'wb')
cPickle.dump({"video":video, "Feature_gesture":Feature_gesture}, out_file, protocol=cPickle.HIGHEST_PROTOCOL)
out_file.close()