(importer, rng, base_poses, base_com, base_cube, num_poses, nmax, aug_modes,
                          retall=False, rot3D=False, sigma_com=None, sigma_sc=None, rot_range=None)
Sample random poses such that we can estimate the subspace more robustly
        :param importer: importer
        :param rng: RandomState
        :param base_poses: set of base 3D poses
        :param base_com: corresponding 3D crop locations
        :param base_cube: corresponding crop cubes
        :param num_poses: number of poses to sample
        :param aug_modes: augmentation modes (comb, com, rot, sc, none)
        :param retall: return all random parameters
        :param rot3D: augment rotation in 3D, which is only possible with poses not images
        :return: random poses
Sample random poses such that we can estimate the subspace more robustly
        :param importer: importer
        :param rng: RandomState
        :param base_poses: set of base 3D poses
        :param base_com: corresponding 3D crop locations
        :param base_cube: corresponding crop cubes
        :param num_poses: number of poses to sample
        :param aug_modes: augmentation modes (comb, com, rot, sc, none)
        :param retall: return all random parameters
        :param rot3D: augment rotation in 3D, which is only possible with poses not images
        :return: random poses
Sample random poses such that we can estimate the subspace more robustly : param importer : importer : param rng : RandomState : param base_poses : set of base 3D poses : param base_com : corresponding 3D crop locations : param base_cube : corresponding crop cubes : param num_poses : number of poses to sample : param aug_modes : augmentation modes ( comb com rot sc none ) : param retall : return all random parameters : param rot3D : augment rotation in 3D which is only possible with poses not images : return : random poses
def sampleRandomPoses(importer, rng, base_poses, base_com, base_cube, num_poses, nmax, aug_modes,
                          retall=False, rot3D=False, sigma_com=None, sigma_sc=None, rot_range=None):
        """
        Sample random poses such that we can estimate the subspace more robustly
        :param importer: importer
        :param rng: RandomState
        :param base_poses: set of base 3D poses
        :param base_com: corresponding 3D crop locations
        :param base_cube: corresponding crop cubes
        :param num_poses: number of poses to sample
        :param aug_modes: augmentation modes (comb, com, rot, sc, none)
        :param retall: return all random parameters
        :param rot3D: augment rotation in 3D, which is only possible with poses not images
        :return: random poses
        """

        if sigma_com is None:
            sigma_com = 10.

        if sigma_sc is None:
            sigma_sc = 0.05

        if rot_range is None:
            rot_range = 180.

        all_modes = ['none', 'rot', 'sc', 'com', 'rot+com', 'com+rot',
                     'rot+com+sc', 'rot+sc+com', 'sc+rot+com', 'sc+com+rot', 'com+sc+rot', 'com+rot+sc']
        assert all([aug_modes[i] in all_modes for i in xrange(len(aug_modes))])

	p2use = numpy.minimum(base_poses.shape[0], nmax)
	print('poses to use %d' % p2use)

        new_poses = numpy.zeros((int(num_poses), base_poses.shape[1], base_poses.shape[2]), dtype=base_poses.dtype)
        new_com = numpy.zeros((int(num_poses), 3), dtype=base_poses.dtype)
        new_cube = numpy.zeros((int(num_poses), 3), dtype=base_poses.dtype)
        modes = rng.randint(0, len(aug_modes), int(num_poses))
        ridxs = rng.randint(0, p2use, int(num_poses))
        off = rng.randn(int(num_poses), 3) * sigma_com
        sc = numpy.fabs(rng.randn(int(num_poses)) * sigma_sc + 1.)
        rot = rng.uniform(-rot_range, rot_range, size=(int(num_poses), 3))

        if aug_modes == ['none']:
            if retall is True:
                return base_poses / (base_cube[:, 2]/2.)[:, None, None], base_com, base_cube
            else:
                return base_poses / (base_cube[:, 2]/2.)[:, None, None]

        for i in xrange(int(num_poses)):
	    if i % 1000 == 0:
		print(i)
            mode = modes[i]
            ridx = ridxs[i]
            cube = base_cube[ridx]
            com3D = base_com[ridx]
            pose = base_poses[ridx]
            if aug_modes[mode] == 'com':
                # augment com
                new_com[i] = com3D + off[i]
                new_cube[i] = cube
                new_poses[i] = (pose + com3D - new_com[i]) / (new_cube[i][2]/2.)
            elif aug_modes[mode] == 'rot':
                # augment rotation
                new_com[i] = com3D
                new_cube[i] = cube
                if rot3D is False:
                    joint_2D = importer.joints3DToImg(pose + new_com[i])
                    data_2D = rotatePoints2D(joint_2D, importer.joint3DToImg(com3D)[0:2], rot[i, 0])
                    new_poses[i] = (importer.jointsImgTo3D(data_2D) - new_com[i]) / (new_cube[i][2]/2.)
                else:
                    new_poses[i] = (rotatePoints3D(pose + new_com[i], new_com[i], rot[i, 0], rot[i, 1], rot[i, 2]) - new_com[i]) / (new_cube[i][2]/2.)
            elif aug_modes[mode] == 'sc':
                # augment cube
                new_com[i] = com3D
                new_cube[i] = cube*sc[i]
                new_poses[i] = pose / (new_cube[i][2]/2.)
            elif aug_modes[mode] == 'none':
                # no augmentation
                new_com[i] = com3D
                new_cube[i] = cube
                new_poses[i] = pose / (new_cube[i][2]/2.)
            elif aug_modes[mode] == 'rot+com' or aug_modes[mode] == 'com+rot':
                # augment com+rot
                new_com[i] = com3D + off[i]
                new_cube[i] = cube
                pose = (pose + com3D - new_com[i])
                if rot3D is False:
                    joint_2D = importer.joints3DToImg(pose + com3D)
                    data_2D = rotatePoints2D(joint_2D, importer.joint3DToImg(new_com[i])[0:2], rot[i, 0])
                    new_poses[i] = (importer.jointsImgTo3D(data_2D) - com3D) / (new_cube[i][2] / 2.)
                else:
                    new_poses[i] = (rotatePoints3D(pose + new_com[i], new_com[i], rot[i, 0], rot[i, 1], rot[i, 2]) - new_com[i]) / (new_cube[i][2] / 2.)
            elif aug_modes[mode] == 'rot+com+sc' or aug_modes[mode] == 'rot+sc+com' or aug_modes == 'sc+rot+com' or aug_modes == 'sc+com+rot' or aug_modes == 'com+sc+rot' or aug_modes == 'com+rot+sc':
                # augment com+scale+rot
                new_com[i] = com3D + off[i]
                new_cube[i] = cube
                pose = (pose + com3D - new_com[i])
                pose = pose * sc[i]
                if rot3D is False:
                    joint_2D = importer.joints3DToImg(pose + com3D)
                    data_2D = rotatePoints2D(joint_2D, importer.joint3DToImg(new_com[i])[0:2], rot[i, 0])
                    new_poses[i] = (importer.jointsImgTo3D(data_2D) - com3D) / (new_cube[i][2] / 2.)
                else:
                    new_poses[i] = (rotatePoints3D(pose + new_com[i], new_com[i], rot[i, 0], rot[i, 1], rot[i, 2]) - new_com[i]) / (new_cube[i][2] / 2.)
            else:
                raise NotImplementedError()
        if retall is True:
            return new_poses, new_com, new_cube, rot
        else:
            return new_poses
def sampleRandomPoses ( importer , rng , base_poses , base_com , base_cube , num_poses , nmax , aug_modes , retall = False , rot3D = False , sigma_com = None , sigma_sc = None , rot_range = None ) : if sigma_com is None : sigma_com = 10. if sigma_sc is None : sigma_sc = 0.05 if rot_range is None : rot_range = 180. all_modes = [ 'none' , 'rot' , 'sc' , 'com' , 'rot+com' , 'com+rot' , 'rot+com+sc' , 'rot+sc+com' , 'sc+rot+com' , 'sc+com+rot' , 'com+sc+rot' , 'com+rot+sc' ] assert all ( [ aug_modes [ i ] in all_modes for i in xrange ( len ( aug_modes ) ) ] ) p2use = numpy . minimum ( base_poses . shape [ 0 ] , nmax ) print ( 'poses to use %d' % p2use ) new_poses = numpy . zeros ( ( int ( num_poses ) , base_poses . shape [ 1 ] , base_poses . shape [ 2 ] ) , dtype = base_poses . dtype ) new_com = numpy . zeros ( ( int ( num_poses ) , 3 ) , dtype = base_poses . dtype ) new_cube = numpy . zeros ( ( int ( num_poses ) , 3 ) , dtype = base_poses . dtype ) modes = rng . randint ( 0 , len ( aug_modes ) , int ( num_poses ) ) ridxs = rng . randint ( 0 , p2use , int ( num_poses ) ) off = rng . randn ( int ( num_poses ) , 3 ) * sigma_com sc = numpy . fabs ( rng . randn ( int ( num_poses ) ) * sigma_sc + 1. ) rot = rng . uniform ( - rot_range , rot_range , size = ( int ( num_poses ) , 3 ) ) if aug_modes == [ 'none' ] : if retall is True : return base_poses / ( base_cube [ : , 2 ] / 2. ) [ : , None , None ] , base_com , base_cube else : return base_poses / ( base_cube [ : , 2 ] / 2. ) [ : , None , None ] for i in xrange ( int ( num_poses ) ) : if i % 1000 == 0 : print ( i ) mode = modes [ i ] ridx = ridxs [ i ] cube = base_cube [ ridx ] com3D = base_com [ ridx ] pose = base_poses [ ridx ] if aug_modes [ mode ] == 'com' : # augment com new_com [ i ] = com3D + off [ i ] new_cube [ i ] = cube new_poses [ i ] = ( pose + com3D - new_com [ i ] ) / ( new_cube [ i ] [ 2 ] / 2. ) elif aug_modes [ mode ] == 'rot' : # augment rotation new_com [ i ] = com3D new_cube [ i ] = cube if rot3D is False : joint_2D = importer . joints3DToImg ( pose + new_com [ i ] ) data_2D = rotatePoints2D ( joint_2D , importer . joint3DToImg ( com3D ) [ 0 : 2 ] , rot [ i , 0 ] ) new_poses [ i ] = ( importer . jointsImgTo3D ( data_2D ) - new_com [ i ] ) / ( new_cube [ i ] [ 2 ] / 2. ) else : new_poses [ i ] = ( rotatePoints3D ( pose + new_com [ i ] , new_com [ i ] , rot [ i , 0 ] , rot [ i , 1 ] , rot [ i , 2 ] ) - new_com [ i ] ) / ( new_cube [ i ] [ 2 ] / 2. ) elif aug_modes [ mode ] == 'sc' : # augment cube new_com [ i ] = com3D new_cube [ i ] = cube * sc [ i ] new_poses [ i ] = pose / ( new_cube [ i ] [ 2 ] / 2. ) elif aug_modes [ mode ] == 'none' : # no augmentation new_com [ i ] = com3D new_cube [ i ] = cube new_poses [ i ] = pose / ( new_cube [ i ] [ 2 ] / 2. ) elif aug_modes [ mode ] == 'rot+com' or aug_modes [ mode ] == 'com+rot' : # augment com+rot new_com [ i ] = com3D + off [ i ] new_cube [ i ] = cube pose = ( pose + com3D - new_com [ i ] ) if rot3D is False : joint_2D = importer . joints3DToImg ( pose + com3D ) data_2D = rotatePoints2D ( joint_2D , importer . joint3DToImg ( new_com [ i ] ) [ 0 : 2 ] , rot [ i , 0 ] ) new_poses [ i ] = ( importer . jointsImgTo3D ( data_2D ) - com3D ) / ( new_cube [ i ] [ 2 ] / 2. ) else : new_poses [ i ] = ( rotatePoints3D ( pose + new_com [ i ] , new_com [ i ] , rot [ i , 0 ] , rot [ i , 1 ] , rot [ i , 2 ] ) - new_com [ i ] ) / ( new_cube [ i ] [ 2 ] / 2. ) elif aug_modes [ mode ] == 'rot+com+sc' or aug_modes [ mode ] == 'rot+sc+com' or aug_modes == 'sc+rot+com' or aug_modes == 'sc+com+rot' or aug_modes == 'com+sc+rot' or aug_modes == 'com+rot+sc' : # augment com+scale+rot new_com [ i ] = com3D + off [ i ] new_cube [ i ] = cube pose = ( pose + com3D - new_com [ i ] ) pose = pose * sc [ i ] if rot3D is False : joint_2D = importer . joints3DToImg ( pose + com3D ) data_2D = rotatePoints2D ( joint_2D , importer . joint3DToImg ( new_com [ i ] ) [ 0 : 2 ] , rot [ i , 0 ] ) new_poses [ i ] = ( importer . jointsImgTo3D ( data_2D ) - com3D ) / ( new_cube [ i ] [ 2 ] / 2. ) else : new_poses [ i ] = ( rotatePoints3D ( pose + new_com [ i ] , new_com [ i ] , rot [ i , 0 ] , rot [ i , 1 ] , rot [ i , 2 ] ) - new_com [ i ] ) / ( new_cube [ i ] [ 2 ] / 2. ) else : raise NotImplementedError ( ) if retall is True : return new_poses , new_com , new_cube , rot else : return new_poses