forked from Fangyh09/PoseDatasets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flic_dataset.py
executable file
·84 lines (70 loc) · 2.44 KB
/
flic_dataset.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2016 Shunta Saito
"""
@author: fangyh09
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import numpy as np
from scipy.io import loadmat
crop_sizes = {
'12-oc': (0, 0),
'along': (0, 0),
'batma': (0, 0),
'bend-': (0, 0),
'ten-c': (0, 0),
'giant': (42, 396),
'princ': (10, 464),
'schin': (6, 461),
'others': (56, 364)
}
def get_joint_list(joints):
head = np.asarray(joints['reye']) + \
np.asarray(joints['leye']) + \
np.asarray(joints['nose'])
head /= 3
del joints['reye']
del joints['leye']
del joints['nose']
joints['head'] = head.tolist()
joint_pos = [joints['lwri']]
joint_pos.append(joints['lelb'])
joint_pos.append(joints['lsho'])
joint_pos.append(joints['head'])
joint_pos.append(joints['rsho'])
joint_pos.append(joints['relb'])
joint_pos.append(joints['rwri'])
return np.array(joint_pos).flatten()
def save_crop_images_and_joints():
training_indices = loadmat('data/FLIC-full/tr_plus_indices.mat')
training_indices = training_indices['tr_plus_indices'].flatten()
examples = loadmat('data/FLIC-full/examples.mat')
examples = examples['examples'][0]
joint_ids = ['lsho', 'lelb', 'lwri', 'rsho', 'relb', 'rwri', 'lhip',
'lkne', 'lank', 'rhip', 'rkne', 'rank', 'leye', 'reye',
'lear', 'rear', 'nose', 'msho', 'mhip', 'mear', 'mtorso',
'mluarm', 'mruarm', 'mllarm', 'mrlarm', 'mluleg', 'mruleg',
'mllleg', 'mrlleg']
available = joint_ids[:8]
available.extend(joint_ids[12:14])
available.extend([joint_ids[16]])
target_joints = ['lsho', 'lelb', 'lwri',
'leye', 'reye', 'nose',
'rsho', 'relb', 'rwri']
fp_train = open('data/FLIC-full/train_joints.csv', 'w')
fp_test = open('data/FLIC-full/test_joints.csv', 'w')
for i, example in enumerate(examples):
joint = example[2].T
joint = dict(zip(joint_ids, joint))
fname = example[3][0]
joint = get_joint_list(joint)
msg = '{},{}'.format(fname, ','.join([str(j) for j in joint.tolist()]))
if i in training_indices:
print(msg, file=fp_train)
else:
print(msg, file=fp_test)
if __name__ == '__main__':
save_crop_images_and_joints()