Example #1
0
 def create_augumentation_mesh(self, dim, newdim, generate_type):
     """
     return a list of offset
     [(dr1,dc1),(dr2,dc2), ...,(drn,dcn)]
     (dri,dci) is the lower points for i-th window( in row, col format)
     """
     if generate_type in set(['rt', 'neg_sample']):
         mesh = iu.cartesian_product2(np.asarray( [range(dim[0] - newdim[0] + 1), range(dim[1] - newdim[1] + 1)]))
     elif generate_type == 'ct':
         dx = (dim[0] - newdim[0])/2
         dy = (dim[1] - newdim[1])/2
         mesh =[(dx,dy)]
     return mesh
Example #2
0
 def create_augumentation_mesh(self, dim, newdim, generate_type):
     """
     return a list of offset
     [(dr1,dc1),(dr2,dc2), ...,(drn,dcn)]
     (dri,dci) is the lower points for i-th window( in row, col format)
     """
     if generate_type in set(['rt', 'neg_sample']):
         mesh = iu.cartesian_product2(
             np.asarray([
                 range(dim[0] - newdim[0] + 1),
                 range(dim[1] - newdim[1] + 1)
             ]))
     elif generate_type == 'ct':
         dx = (dim[0] - newdim[0]) / 2
         dy = (dim[1] - newdim[1]) / 2
         mesh = [(dx, dy)]
     return mesh
Example #3
0
    def generate_rt_data(self, matpath):
        """
        in each mat
                        mat['X'] is image data
                        mat['Y'] is npart x ndata array
        """
        mat = sio.loadmat(matpath)
        dim = mat['dim'][0]
        ndata = (mat['X'].shape)[1]
        sample_num = self.savedata_info['sample_num']
        totaldata = sample_num * ndata * 2
        newdim = self.savedata_info['newdim']
        nparts = self.meta['nparts']
        filter_size = self.savedata_info['indmap_para']['filter_size']
        stride =  self.savedata_info['indmap_para']['stride']
        rate = self.savedata_info['indmap_para']['rate']
        mdim = self.get_indmapdim(newdim, filter_size, stride)
        
        if newdim[0] > dim[0] or newdim[1] > dim[1]:
            raise HMLPEError('Invalid new size ')
        if (dim[0] - newdim[0] + 1) * (dim[1] - newdim[1] + 1) < sample_num:
            raise HMLPEError(' Invalid sample_num')
        res = {}
        per_size = min(totaldata, self.savedata_info['max_batch_size'])

        mesh = iu.cartesian_product2(np.asarray( [range(dim[0] - newdim[0] + 1), \
                                                 range(dim[1] - newdim[1] + 1)]))
        allX = mat['X'].reshape( (dim[0], dim[1],dim[2], ndata), order='F')
        allY = mat['Y'].reshape( (2,-1, ndata), order='F') 
        newlen = iu.prod( newdim )
        res['data'] = np.ndarray([newdim[0], newdim[1], newdim[2], per_size], \
                                 dtype = np.uint8)
        res['labels'] = np.ndarray( [allY.shape[1], per_size], dtype=np.int)
        res['joints8'] = np.ndarray( [8, 2, per_size], dtype=np.float)
        res['oribbox'] = np.ndarray( [4, per_size], dtype = np.float)
        res['indmap'] = np.zeros((nparts, mdim[0], mdim[1], per_size), np.bool)
        res['filenames'] =[str() for x in range(per_size)]
        tmpres = dict()
        cur_id = self.batch_id
        pre_nc = 0
        nc = 0
        for it in range(ndata):
            curX = allX[...,it]
            curY = allY[...,it].transpose()
            curfilename = str(mat['imagepathlist'][0,it][0])
            l = (np.random.permutation(range(len(mesh))))[:sample_num]
            for p in l:
                r,c = mesh[p]
                tmpX = curX
                tmpX = np.roll(tmpX, shift=-int(r), axis = 0)
                tmpX = np.roll(tmpX, shift=-int(c), axis = 1)
                tmpX = tmpX[:newdim[0], :newdim[1],:]
                res['data'][...,nc - pre_nc] = tmpX
                tmpY = curY - 1 + np.asarray([-c,-r])
                res['joints8'][..., nc - pre_nc] = tmpY;
                res['filenames'][nc - pre_nc] = curfilename
                res['oribbox'][...,nc-pre_nc] = res['oribbox'][...,it]
                res['indmap'][...,nc-pre_nc] = self.create_indicatormap(tmpY, part_idx, mdim, rate, filter_size, stride)
				res['jointmasks'] = self.makejointmask(newdim, tmpY)
                nc = nc + 1
                #flip image
                tmpX = tmpX[:,::-1,:]
                res['data'][...,nc - pre_nc] = tmpX
                res['filenames'][nc - pre_nc] = curfilename
				tmmY = flip_pose8_joint(newdim, tmpY)
	            res['joints8'][...,nc -pre_nc] = tmpY
                res['oribbox'][...,nc-pre_nc] = res['oribbox'][...,it]
				res['indmap'][...,nc-pre_nc] = self.create_indicatormap(tmpY, part_idx, mdim, rate, filter_size, stride)
				res['jointmasks'] = self.makejointmask(newdim, tmpY)