-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiconvdata.py
606 lines (573 loc) · 32.3 KB
/
iconvdata.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# Copyright (c) 2013, Li Sijin ([email protected])
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from data import *
import numpy.random as nr
import numpy as n
import random as r
from time import time
#CONV_IMG_SIZE = 128 # 128 for the whole image. Attention
#CONV_IMG_SIZE=56
CONV_IMG_SIZE=112
class POSEDataProvider(LabeledMemoryDataProvider):
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
LabeledMemoryDataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
# Subtract the mean from the data and make sure that both data and
# labels are in single-precision floating point.
for d in self.data_dic:
# This converts the data matrix to single precision and makes sure that it is C-ordered
d['data'] = n.require((d['data'] - self.data_mean), dtype=n.single, requirements='C')
d['labels'] = n.require(d['labels'].reshape((-1, d['data'].shape[1]), order='F'), dtype=n.single, requirements='C')
def get_next_batch(self):
epoch, batchnum, datadic = LabeledMemoryDataProvider.get_next_batch(self)
alldata = [ datadic['data']] + [ n.require(l.reshape((1,datadic['data'].shape[1]), order='F'), dtype=n.single, requirements='C') for l in datadic['labels']]
return epoch, batchnum, alldata
# Returns the dimensionality of the two data matrices returned by get_next_batch
# idx is the index of the matrix.
def get_data_dims(self, idx=0):
return self.img_size**2 * self.num_colors if idx == 0 else 1
# Takes as input an array returned by get_next_batch
# Returns a (numCases, imgSize, imgSize, 3) array which can be
# fed to pylab for plotting.
# This is used by shownet.py to plot test case predictions.
def get_plottable_data(self, data):
return n.require((data + self.data_mean).T.reshape(data.shape[1], 3, self.img_size, self.img_size).swapaxes(1,3) / 255.0, dtype=n.single)
class LargeMultiPOSEDataProvider(LabeledDataProvider):
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
LabeledDataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
def get_next_batch(self):
self.data_dic = self.get_batch(self.curr_batchnum)
self.data_dic['data'] = n.require((self.data_dic['data'] - self.data_mean), dtype=n.single, requirements='C')
self.data_dic['labels'] = n.c_[n.require(self.data_dic['labels'], dtype=n.single)].reshape((-1, self.data_dic['data'].shape[1]), order='F')
epoch, batchnum = self.curr_epoch, self.curr_batchnum
self.advance_batch()
alldata = [ self.data_dic['data'] ] + [n.require(l.reshape((1,self.data_dic['data'].shape[1]), order='F'), dtype=n.single, requirements='C') for l in self.data_dic['labels']]
return epoch, batchnum, alldata
# Returns the dimensionality of the two data matrices returned by get_next_batch
# idx is the index of the matrix.
def get_data_dims(self, idx=0):
return self.img_size**2 * self.num_colors if idx == 0 else 1
# Takes as input an array returned by get_next_batch
# Returns a (numCases, imgSize, imgSize, 3) array which can be
# fed to pylab for plotting.
# This is used by shownet.py to plot test case predictions.
def get_plottable_data(self, data):
return n.require((data + self.data_mean).T.reshape(data.shape[1], 3, self.img_size, self.img_size).swapaxes(1,3) / 255.0, dtype=n.single)
class MultiPOSEDataProvider(LabeledMemoryDataProvider):
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
LabeledMemoryDataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
# Subtract the mean from the data and make sure that both data and
# labels are in single-precision floating point.
for d in self.data_dic:
# This converts the data matrix to single precision and makes sure that it is C-ordered
d['data'] = n.require((d['data'] - self.data_mean), dtype=n.single, requirements='C')
d['labels'] = n.require(d['labels'].reshape((-1, d['data'].shape[1]), order='F'), dtype=n.single, requirements='C')
def get_next_batch(self):
epoch, batchnum, datadic = LabeledMemoryDataProvider.get_next_batch(self)
alldata = [ datadic['data'] ] + [n.require(l.reshape(1,datadic['data'].shape[1]), requirements='C') for l in datadic['labels']]
return epoch, batchnum, alldata
# Returns the dimensionality of the two data matrices returned by get_next_batch
# idx is the index of the matrix.
def get_data_dims(self, idx=0):
return self.img_size**2 * self.num_colors if idx == 0 else 1
# Takes as input an array returned by get_next_batch
# Returns a (numCases, imgSize, imgSize, 3) array which can be
# fed to pylab for plotting.
# This is used by shownet.py to plot test case predictions.
def get_plottable_data(self, data):
return n.require((data + self.data_mean).T.reshape(data.shape[1], 3, self.img_size, self.img_size).swapaxes(1,3) / 255.0, dtype=n.single)
class LargeJoints8DataProvider(DataProvider):
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
DataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
def get_num_parts(self):
return 8
"""
In this version,
all nan value are removed
so that all the data point is valid
"""
def get_next_batch(self):
self.data_dic = self.get_batch(self.curr_batchnum)
self.data_dic['data'] = n.require((self.data_dic['data'] - self.data_mean), dtype=n.single, requirements='C')
self.data_dic['joints8'] = n.require(self.data_dic['joints8'].reshape((16, self.data_dic['data'].shape[1]), order='C'), dtype=n.single, requirements='C')
valid_idx = n.require(1 - n.max(n.isnan(self.data_dic['joints8']), axis=0), dtype=n.bool)
self.data_dic['data'] = n.require(self.data_dic['data'][...,valid_idx], requirements='C')
self.data_dic['joints8'] = n.require(self.data_dic['joints8'][...,valid_idx],dtype=n.single, requirements='C')
self.data_dic['joints8'] = self.data_dic['joints8']/self.img_size;
epoch, batchnum = self.curr_epoch, self.curr_batchnum
self.advance_batch()
alldata = [self.data_dic['data'], self.data_dic['joints8']]
return epoch, batchnum, alldata
def get_data_dims(self, idx=0):
return self.img_size**2 * self.num_colors if idx == 0 else 16
def get_plottable_data(self, data):
return n.require(data + self.data_mean).reshape((self.img_size, self.img_size, self.num_colors, data.shape[1]), order='F')
def get_joints(self):
return self.data_dic['joints8'].reshape((8,2,-1), order='C')
def get_num_classes(self):
return 10
class LargeJoints8AndLabelDataProvider(DataProvider):
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
DataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
def get_num_parts(self):
return 8
"""
In this version,
all nan value are removed
so that all the data point is valid
"""
def get_next_batch(self):
self.data_dic = self.get_batch(self.curr_batchnum)
self.data_dic['data'] = n.require((self.data_dic['data'] - self.data_mean), dtype=n.single, requirements='C')
self.data_dic['joints8'] = n.require(self.data_dic['joints8'].reshape((16, self.data_dic['data'].shape[1]), order='C'), dtype=n.single, requirements='C')
self.data_dic['labels'] = n.require(self.data_dic['labels'].reshape((-1, self.data_dic['data'].shape[1]), order='F'), dtype=n.single, requirements='C')
#change_time = time()
valid_idx = n.require(1 - n.max(n.isnan(self.data_dic['joints8']), axis=0), dtype=n.bool)
self.data_dic['data'] = n.require(self.data_dic['data'][...,valid_idx], requirements='C')
self.data_dic['joints8'] = n.require(self.data_dic['joints8'][...,valid_idx],dtype=n.single, requirements='C')
self.data_dic['labels'] = n.require(self.data_dic['labels'][...,valid_idx], dtype=n.single, requirements='C')
#print 'change time to %.3f' % (time() - change_time)
# normalize joints to [0,1]
self.data_dic['joints8'] = self.data_dic['joints8']/self.img_size;
epoch, batchnum = self.curr_epoch, self.curr_batchnum
self.advance_batch()
alldata = [self.data_dic['data'], self.data_dic['joints8']]
# note that all label data should have offset 2
alldata = alldata + [n.require(l.reshape((1,self.data_dic['data'].shape[1]), order='F'), dtype=n.single, requirements='C') for l in self.data_dic['labels']]
return epoch, batchnum, alldata
def get_data_dims(self, idx=0):
if idx == 0:
return self.img_size**2 * self.num_colors
elif idx == 1:
return 16
else:
return 1
def get_plottable_data(self, data):
return n.require(data + self.data_mean).reshape((self.img_size, self.img_size, self.num_colors, data.shape[1]), order='F')
def get_joints(self):
return self.data_dic['joints8'].reshape((8,2,-1), order='C')
def get_num_classes(self):
return 10
class LargeJoints8AndLabelAllDataProvider(DataProvider):
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
DataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
def get_num_parts(self):
return 8
"""
In this version,
all nan value are removed
so that all the data point is valid
"""
def get_next_batch(self):
load_time = time()
self.data_dic = self.get_batch(self.curr_batchnum)
self.data_dic['data'] = n.require((self.data_dic['data'] - self.data_mean), dtype=n.single, requirements='C')
self.data_dic['joints8'] = n.require(self.data_dic['joints8'].reshape((16, self.data_dic['data'].shape[1]), order='C'), dtype=n.single, requirements='C')
self.data_dic['labels'] = n.require(self.data_dic['labels'].reshape((-1, self.data_dic['data'].shape[1]), order='F'), dtype=n.single, requirements='C')
self.data_dic['joints8'] = self.data_dic['joints8']/self.img_size;
epoch, batchnum = self.curr_epoch, self.curr_batchnum
self.advance_batch()
alldata = [self.data_dic['data'], self.data_dic['joints8']]
# note that all label data should have offset 2
alldata = alldata + [n.require(l.reshape((1,self.data_dic['data'].shape[1]), order='F'), dtype=n.single, requirements='C') for l in self.data_dic['labels']]
#print 'Loading data takes %.3f\n' % ( time() - load_time)
return epoch, batchnum, alldata
def get_data_dims(self, idx=0):
if idx == 0:
return self.img_size**2 * self.num_colors
elif idx == 1:
return 16
else:
return 1
def get_plottable_data(self, data):
return n.require(data + self.data_mean).reshape((self.img_size, self.img_size, self.num_colors, data.shape[1]), order='F')
def get_joints(self):
return self.data_dic['joints8'].reshape((8,2,-1), order='C')
def get_num_classes(self):
return 10
class LargeJoints8AndIndicatorAllDataProvider(DataProvider):
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
DataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
if 'indmap_para' not in self.batch_meta:
self.ind_dim = 7 * 8 * 8
else:
self.ind_dim = self.batch_meta['indmap_para']['dim']
# if it is set to be True, get_next_batch
# get_next_batch will not load new dic
self.keep_dic = False
def set_data_dic(self, dic):
self.data_dic = dic
def get_next_batch(self):
if not self.keep_dic:
self.data_dic = self.get_batch(self.curr_batchnum)
imgdata = n.require((self.data_dic['data'] - self.data_mean), dtype=n.single, requirements='C')
self.data_dic['joints8'] = n.require(self.data_dic['joints8'].reshape((16, self.data_dic['data'].shape[1]), order='C'), dtype=n.single, requirements='C')
self.data_dic['joints8'] = self.data_dic['joints8']/self.img_size;
epoch, batchnum = self.curr_epoch, self.curr_batchnum
self.advance_batch()
alldata = [imgdata, self.data_dic['joints8'].copy()]
ind = self.data_dic['indmap']
# Note that all image like data will use 'F' order
# although it will require 'C' continuous data
# 0th body parts will start as idx 2
ndata = ind.shape[-1]
self.data_dic['indmap'] = n.require(ind.reshape((-1, ndata), order='F'), dtype=n.single, requirements='C')
alldata += [self.data_dic['indmap'] ]
self.ind_dim = ind.shape[0] * ind.shape[1] * ind.shape[2]
return epoch, batchnum, alldata
def get_data_dims(self, idx=0):
if idx == 0:
return self.img_size**2 * self.num_colors
elif idx == 1:
return 16
else:# should be called after get_next_batch
return self.ind_dim
def get_plottable_data(self, data):
return n.require(data + self.data_mean).reshape((self.img_size, self.img_size, self.num_colors, data.shape[1]), order='F')
def get_joints(self):
return self.data_dic['joints8'].reshape((8,2,-1), order='C')
def get_num_parts(self):
return 7
class LargeJtInd2_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
"""
This DataProvider will add joint indicator at the last position in alldata
In this version, two indicator map(part,joint) are required to be the same size
"""
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
LargeJoints8AndIndicatorAllDataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
if 'savedata_info' in self.batch_meta and 'jt_inddim' in self.batch_meta['savedata_info']['indmap_para']:
self.jt_inddim = self.batch_meta['savedata_info']['indmap_para']['jt_inddim']
else:
self.jt_inddim = 8 * 8 * 8
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
ind = self.data_dic['joint_indmap']
self.data_dic['joint_indmap'] = n.require(ind.reshape((-1,ndata),order='F'), dtype=n.single, requirements='C')
alldata += [self.data_dic['joint_indmap']]
return epoch, batchnum, alldata
def get_data_dims(self, idx=0):
if idx <3:
return LargeJoints8AndIndicatorAllDataProvider.get_data_dims(self, idx)
else:
return self.jt_inddim
class LargeJtInd2Mask_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
"""
The content in alldata will be
0 : imgdata, 1: joints8, 2: part_indicator_map,
3 : joint_indicator_map, 4: joint_mask 5:is_positive
"""
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
LargeJoints8AndIndicatorAllDataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
prod = lambda x: x[0] * x[1]
#nparts = self.batch_meta['nparts']
njoints = self.batch_meta['njoints']
#self.pt_inddim = prod(self.batch_meta['ind_dim']['part_indmap'])*nparts
self.jt_inddim = prod(self.batch_meta['ind_dim']['joint_indmap'])*njoints
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
ind = self.data_dic['joint_indmap']
self.data_dic['joint_indmap'] = n.require(ind.reshape((-1,ndata),order='F'), dtype=n.single, requirements='C')
alldata += [self.data_dic['joint_indmap']]
mask = self.data_dic['jointmasks'].reshape((-1,ndata),order='C')
self.data_dic['jointmasks'] = n.require(mask,dtype=n.single,requirements='C')
# change nan to zero in joints8
alldata[1][~n.require(mask,dtype=n.bool)] = 0
alldata += [self.data_dic['jointmasks']]
is_positive = n.require(self.data_dic['is_positive'].reshape((-1,ndata),order='F'),dtype=n.single, requirements='C')
self.data_dic['is_positive'] = is_positive
alldata += [is_positive]
return epoch, batchnum, alldata
def get_data_dims(self,idx=0):
if idx < 3:
return LargeJoints8AndIndicatorAllDataProvider.get_data_dims(self,idx)
elif idx == 3:
return self.jt_inddim
elif idx == 4:
return LargeJoints8AndIndicatorAllDataProvider.get_data_dims(self,1)
else:
return 1
class LargeJtIndLack_LUA_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
num_parts = self.get_num_parts()
ind_dim = self.get_data_dims(2)
mask = n.ones((num_parts, ind_dim/num_parts, ndata),dtype=n.single, order='F')
#LUA is 5-th part
mask[5,:,:] = 0
alldata += [n.require(mask.reshape((-1,ndata), order='F'), requirements='C')]
return epoch, batchnum, alldata
class LargeJtIndLack_RUA_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
num_parts = self.get_num_parts()
ind_dim = self.get_data_dims(2)
mask = n.ones((num_parts, ind_dim/num_parts, ndata),dtype=n.single, order='F')
#RUA is 5-th part
mask[5,:,:] = 0
alldata += [n.require(mask.reshape((-1,ndata), order='F'), requirements='C')]
return epoch, batchnum, alldata
class LargeJtIndLack_RLA_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
num_parts = self.get_num_parts()
ind_dim = self.get_data_dims(2)
mask = n.ones((num_parts, ind_dim/num_parts, ndata),dtype=n.single, order='F')
#RLA is 6-th part
mask[6,:,:] = 0
alldata += [n.require(mask.reshape((-1,ndata), order='F'), requirements='C')]
return epoch, batchnum, alldata
class LargeJtIndLack_LUA_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
num_parts = self.get_num_parts()
ind_dim = self.get_data_dims(2)
mask = n.ones((num_parts, ind_dim/num_parts, ndata),dtype=n.single, order='F')
#LUA is 5-th part
mask[3,:,:] = 0
alldata += [n.require(mask.reshape((-1,ndata), order='F'), requirements='C')]
return epoch, batchnum, alldata
class LargeJtIndLack_LLA_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
num_parts = self.get_num_parts()
ind_dim = self.get_data_dims(2)
mask = n.ones((num_parts, ind_dim/num_parts, ndata),dtype=n.single, order='F')
#RLA is 6-th part
mask[4,:,:] = 0
alldata += [n.require(mask.reshape((-1,ndata), order='F'), requirements='C')]
return epoch, batchnum, alldata
class LargeJtIndLack_UA_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
num_parts = self.get_num_parts()
ind_dim = self.get_data_dims(2)
mask = n.ones((num_parts, ind_dim/num_parts, ndata),dtype=n.single, order='F')
#RUA is 5-th part, LUA is 3-th part
mask[5,:,:] = 0
mask[3,:,:] = 0
alldata += [n.require(mask.reshape((-1,ndata), order='F'), requirements='C')]
return epoch, batchnum, alldata
class LargeJtIndLack_LA_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
num_parts = self.get_num_parts()
ind_dim = self.get_data_dims(2)
mask = n.ones((num_parts, ind_dim/num_parts, ndata),dtype=n.single, order='F')
#RLA is 6-th part, LLA is 4-th part
mask[6,:,:] = 0
mask[4,:,:] = 0
alldata += [n.require(mask.reshape((-1,ndata), order='F'), requirements='C')]
return epoch, batchnum, alldata
class LargeJtIndLack_HEAD_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
num_parts = self.get_num_parts()
ind_dim = self.get_data_dims(2)
mask = n.ones((num_parts, ind_dim/num_parts, ndata),dtype=n.single, order='F')
#Head is 0-th part
mask[0,:,:] = 0
alldata += [n.require(mask.reshape((-1,ndata), order='F'), requirements='C')]
return epoch, batchnum, alldata
class LargeJtIndLack_SHOULDER_DataProvider(LargeJoints8AndIndicatorAllDataProvider):
def get_next_batch(self):
epoch, batchnum, alldata = LargeJoints8AndIndicatorAllDataProvider.get_next_batch(self)
ndata = alldata[0].shape[-1]
num_parts = self.get_num_parts()
ind_dim = self.get_data_dims(2)
mask = n.ones((num_parts, ind_dim/num_parts, ndata),dtype=n.single, order='F')
#Head is 0-th part
mask[1,:,:] = 0
mask[2,:,:] = 0
alldata += [n.require(mask.reshape((-1,ndata), order='F'), requirements='C')]
return epoch, batchnum, alldata
class LargeJoints8AndIndicatorMaskAllDataProvider(DataProvider):
"""
This data provider is used for providing various masks for network
dataidx = 0: imgdata
1: joints8
2: indmap
3: mask0
...
"""
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
DataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
if 'indmap_para' not in self.batch_meta:
self.ind_dim = 7 * 8 * 8
else:
self.ind_dim = self.batch_meta['indmap_para']['dim']
def get_next_batch(self):
load_time = time()
self.data_dic = self.get_batch(self.curr_batchnum)
self.data_dic['data'] = n.require((self.data_dic['data'] - self.data_mean), dtype=n.single, requirements='C')
self.data_dic['joints8'] = n.require(self.data_dic['joints8'].reshape((16, self.data_dic['data'].shape[1]), order='C'), dtype=n.single, requirements='C')
self.data_dic['joints8'] = self.data_dic['joints8']/self.img_size;
epoch, batchnum = self.curr_epoch, self.curr_batchnum
self.advance_batch()
alldata = [self.data_dic['data'], self.data_dic['joints8']]
ind = self.data_dic['indmap']
# Note that all image like data will use 'F' order
# although it will require 'C' continuous data
ndata = ind.shape[-1]
self.data_dic['indmap'] = n.require(ind.reshape((-1, ndata), order='F'), dtype=n.single, requirements='C')
alldata += [self.data_dic['indmap'] ]
self.ind_dim = ind.shape[0] * ind.shape[1] * ind.shape[2]
alldata += [n.ones((16, ndata),dtype=n.single, order='C')]
return epoch, batchnum, alldata
def get_data_dims(self, idx=0):
if idx == 0:
return self.img_size**2 * self.num_colors
elif idx == 1:
return 16
elif idx == 2:
# should be called after get_next_batch
return self.ind_dim
elif idx == 3:
return 16
def get_plottable_data(self, data):
return n.require(data + self.data_mean).reshape((self.img_size, self.img_size, self.num_colors, data.shape[1]), order='F')
def get_joints(self):
return self.data_dic['joints8'].reshape((8,2,-1), order='C')
def get_num_parts(self):
return 7
class LargeJoints8AndIndicatorFeatureAllDataProvider(DataProvider):
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
DataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
if 'indmap_para' not in self.batch_meta:
self.ind_dim = 7 * 8 * 8
else:
self.ind_dim = self.batch_meta['indmap_para']['dim']
def get_next_batch(self):
load_time = time()
self.data_dic = self.get_batch(self.curr_batchnum)
ndata = self.data_dic['feature'].shape[1]
self.data_dic['feature'] = n.require(self.data_dic['feature'], dtype=n.single, requirements='C')
self.data_dic['joints8'] = n.require(self.data_dic['joints8'].reshape((16, ndata), order='C'), dtype=n.single, requirements='C')
self.data_dic['joints8'] = self.data_dic['joints8']/self.img_size
epoch, batchnum = self.curr_epoch, self.curr_batchnum
self.advance_batch()
alldata = [self.data_dic['feature'], self.data_dic['joints8']]
ind = self.data_dic['indmap']
# Note that all image like data will use 'F' order
# although it will require 'C' continuous data
# 0th body parts will start as idx 2
ndata = ind.shape[-1]
self.data_dic['indmap'] = n.require(ind.reshape((-1, ndata), order='F'), dtype=n.single, requirements='C')
alldata += [self.data_dic['indmap'] ]
self.ind_dim = 448 # next time I will write it into meta
return epoch, batchnum, alldata
def get_data_dims(self, idx=0):
if idx == 0: # temp value, I will add it later in meta file
return 1600
elif idx == 1:
return 16
else:
# should be called after get_next_batch
return self.ind_dim
def get_plottable_data(self, data):
return None
#return n.require(data).reshape((self.img_size, self.img_size, self.num_colors, data.shape[1]), order='F')
def get_joints(self):
return self.data_dic['joints8'].reshape((8,2,-1), order='C')
def get_num_parts(self):
return 7
class H36MMonoDataProvider(DataProvider):
"""
This data provider can provide imgdata, mono_joints3d, joint_indicator map in order
"""
def __init__(self, data_dir, batch_range, init_epoch=1, init_batchnum=None, dp_params={}, test=False):
DataProvider.__init__(self, data_dir, batch_range, init_epoch, init_batchnum, dp_params, test)
self.data_mean = self.batch_meta['data_mean']
self.num_colors = 3
self.img_size = CONV_IMG_SIZE
self.jtind_dim = self.batch_meta['ind_dim']['joint_indmap']
self.normalize_mono_jt = 1200
# if it is set to be True, get_next_batch
# get_next_batch will not load new dic
self.keep_dic = False
self.njoints = self.batch_meta['njoints']
def set_data_dic(self, dic):
self.data_dic = dic
def get_next_batch(self):
if not self.keep_dic:
self.data_dic = self.get_batch(self.curr_batchnum)
imgdata = n.require((self.data_dic['data'] - self.data_mean), dtype=n.single, requirements='C')
self.data_dic['mono_joints3d'] = n.require(self.data_dic['mono_joints3d'].reshape((self.njoints*3, self.data_dic['data'].shape[-1]), order='F'), dtype=n.single, requirements='C')
self.data_dic['mono_joints3d'] = self.data_dic['mono_joints3d']/self.normalize_mono_jt
alldata = [imgdata, self.data_dic['mono_joints3d'].copy()]
ind = self.data_dic['joint_indmap']
ndata = ind.shape[-1]
self.data_dic['joint_indmap'] = n.require(ind.reshape((-1, ndata), order='F'), dtype=n.single, requirements='C')
alldata += [self.data_dic['joint_indmap'] ]
epoch, batchnum = self.curr_epoch, self.curr_batchnum
self.advance_batch()
return epoch, batchnum, alldata
def get_data_dims(self, idx=0):
if idx == 0:
return self.img_size**2 * self.num_colors
elif idx == 1:
return self.njoints * 3
else:
return self.jtind_dim[0] * self.jtind_dim[1] * self.njoints
def get_plottable_data(self, data):
return n.require(data + self.data_mean).reshape((self.img_size, self.img_size, self.num_colors, data.shape[1]), order='F')
def get_joints(self):
return self.data_dic['mono_joints3d'].reshape((self.njoints,3,-1), order='C')
def get_num_parts(self):
return 0