(self, seqName, Nmax=float('inf'), shuffle=False, rng=None, docom=False, cube=None, hand=None)
return NamedImgSequence(seqName, data, config)
Load an image sequence from the dataset
        :param seqName: sequence name, e.g. train
        :param Nmax: maximum number of samples to load
        :return: returns named image sequence
Load an image sequence from the dataset
        :param seqName: sequence name, e.g. train
        :param Nmax: maximum number of samples to load
        :return: returns named image sequence
Load an image sequence from the dataset : param seqName : sequence name e . g . train : param Nmax : maximum number of samples to load : return : returns named image sequence
def loadSequence(self, seqName, Nmax=float('inf'), shuffle=False, rng=None, docom=False, cube=None, hand=None):
        """
        Load an image sequence from the dataset
        :param seqName: sequence name, e.g. train
        :param Nmax: maximum number of samples to load
        :return: returns named image sequence
        """
        if cube is None:
            config = {'cube': (0,0,0)}
        else:
            assert isinstance(cube, tuple)
            assert len(cube) == 3
            config = {'cube': cube}

        pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl'.format(self.cacheDir, self.__class__.__name__, seqName, self.allJoints, HandDetector.detectionModeToString(docom, self.refineNet is not None), config['cube'][0])
        if self.useCache:
            if os.path.isfile(pickleCache):
                print("Loading cache data from {}".format(pickleCache))
                f = open(pickleCache, 'rb')
                (seqName, data, config) = cPickle.load(f)
                f.close()

                # shuffle data
                if shuffle and rng is not None:
                    print("Shuffling")
                    rng.shuffle(data)
                if not(np.isinf(Nmax)):
                    return NamedImgSequence(seqName, data[0:Nmax], config)
                else:
                    return NamedImgSequence(seqName, data, config)

        # self.loadRefineNetLazy(self.refineNet)

        # Load the dataset
        objdir = '{}/{}/'.format(self.basepath, seqName)
        trainlabels = '{}/{}/joint_data.mat'.format(self.basepath, seqName)
        print trainlabels
        comlabels='{}/{}_NYU.txt'.format(self.basepath,seqName)
        f = open(comlabels, 'r')
        coms=f.readlines()
        print type(coms[0])

        mat = scipy.io.loadmat(trainlabels)

        print '******'
        names = mat['joint_names'][0]
        joints3D = mat['joint_xyz'][0]
        joints2D = mat['joint_uvd'][0]
        if self.allJoints:
            eval_idxs = np.arange(36)
        else:
            eval_idxs = self.restrictedJointsEval

        self.numJoints = len(eval_idxs)

        txt = 'Loading {}'.format(seqName)
        print txt
        pbar = pb.ProgressBar(maxval=joints3D.shape[0], widgets=[txt, pb.Percentage(), pb.Bar()])
        pbar.start()

        data = []
        i=0
        for line in range(joints3D.shape[0]):
            scale=np.random.randint(0,6)
            print line,scale
            com_=coms[line].split()
            com_=np.asarray(com_).astype(np.float)
            print i,com_
            com2D=self.joint3DToImg(com_)

            dptFileName = '{0:s}/depth_1_{1:07d}.png'.format(objdir, line+1)


            if not os.path.isfile(dptFileName):
                print("File {} does not exist!".format(dptFileName))
                i += 1
                continue
            dpt = self.loadDepthMap(dptFileName)
            # import matplotlib.pyplot as plt
            # plt.imshow(dpt,cmap='gray')
            # plt.show()
            if hand is not None:
                raise NotImplementedError()

            # joints in image coordinates
            gtorig = np.zeros((self.numJoints, 3), np.float32)
            jt = 0
            for ii in range(joints2D.shape[1]):
                if ii not in eval_idxs:
                    continue
                gtorig[jt, 0] = joints2D[line, ii, 0]
                gtorig[jt, 1] = joints2D[line, ii, 1]
                gtorig[jt, 2] = joints2D[line, ii, 2]
                jt += 1

            # normalized joints in 3D coordinates
            gt3Dorig = np.zeros((self.numJoints, 3), np.float32)
            jt = 0
            for jj in range(joints3D.shape[1]):
                if jj not in eval_idxs:
                    continue
                gt3Dorig[jt, 0] = joints3D[line, jj, 0]
                gt3Dorig[jt, 1] = joints3D[line, jj, 1]
                gt3Dorig[jt, 2] = joints3D[line, jj, 2]
                jt += 1
            # print gt3D

            # self.showAnnotatedDepth(DepthFrame(dpt,gtorig,gtorig,0,gt3Dorig,gt3Dorig,0,dptFileName,'',''))

            # Detect hand
            hd = HandDetector(dpt, self.fx, self.fy, refineNet=self.refineNet, importer=self)
            if not hd.checkImage(1):
                print("Skipping image {}, no content".format(dptFileName))
                i += 1
                continue
            try:
                varcube=250+10*scale
                cube_0=(varcube,varcube,varcube)
                if cube is None:
                    cube_=cube_0
                else:
                    cube_=cube
                dpt, M, com = hd.cropArea3D(com=com2D, size=cube_, docom=docom,dsize=(96,96))
            except UserWarning:
                print("Skipping image {}, no hand detected".format(dptFileName))
                continue

            com3D = self.jointImgTo3D(com)
            gt3Dcrop = gt3Dorig - com3D  # normalize to com
            gtcrop = transformPoints2D(gtorig, M)

            # print("{}".format(gt3Dorig))
            # self.showAnnotatedDepth(DepthFrame(dpt,gtorig,gtcrop,M,gt3Dorig,gt3Dcrop,com3D,dptFileName,'',''))

            data.append(DepthFrame(dpt.astype(np.float32), gtorig, gtcrop, M, gt3Dorig, gt3Dcrop, com3D, dptFileName,
                                   '', self.sides[seqName], {},cube_))
            # self.showAnnotatedDepth(data[0])

            pbar.update(i)
            i += 1

            # early stop
            if len(data) >= Nmax:
                break

        pbar.finish()
        print("Loaded {} samples.".format(len(data)))

        if self.useCache:
            print("Save cache data to {}".format(pickleCache))
            f = open(pickleCache, 'wb')
            cPickle.dump((seqName, data, config), f, protocol=cPickle.HIGHEST_PROTOCOL)
            f.close()

        # shuffle data
        if shuffle and rng is not None:
            print("Shuffling")
            rng.shuffle(data)
        return NamedImgSequence(seqName, data, config)
def loadSequence ( self , seqName , Nmax = float ( 'inf' ) , shuffle = False , rng = None , docom = False , cube = None , hand = None ) : if cube is None : config = { 'cube' : ( 0 , 0 , 0 ) } else : assert isinstance ( cube , tuple ) assert len ( cube ) == 3 config = { 'cube' : cube } pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl' . format ( self . cacheDir , self . __class__ . __name__ , seqName , self . allJoints , HandDetector . detectionModeToString ( docom , self . refineNet is not None ) , config [ 'cube' ] [ 0 ] ) if self . useCache : if os . path . isfile ( pickleCache ) : print ( "Loading cache data from {}" . format ( pickleCache ) ) f = open ( pickleCache , 'rb' ) ( seqName , data , config ) = cPickle . load ( f ) f . close ( ) # shuffle data if shuffle and rng is not None : print ( "Shuffling" ) rng . shuffle ( data ) if not ( np . isinf ( Nmax ) ) : return NamedImgSequence ( seqName , data [ 0 : Nmax ] , config ) else : return NamedImgSequence ( seqName , data , config ) # self.loadRefineNetLazy(self.refineNet) # Load the dataset objdir = '{}/{}/' . format ( self . basepath , seqName ) trainlabels = '{}/{}/joint_data.mat' . format ( self . basepath , seqName ) print trainlabels comlabels = '{}/{}_NYU.txt' . format ( self . basepath , seqName ) f = open ( comlabels , 'r' ) coms = f . readlines ( ) print type ( coms [ 0 ] ) mat = scipy . io . loadmat ( trainlabels ) print '******' names = mat [ 'joint_names' ] [ 0 ] joints3D = mat [ 'joint_xyz' ] [ 0 ] joints2D = mat [ 'joint_uvd' ] [ 0 ] if self . allJoints : eval_idxs = np . arange ( 36 ) else : eval_idxs = self . restrictedJointsEval self . numJoints = len ( eval_idxs ) txt = 'Loading {}' . format ( seqName ) print txt pbar = pb . ProgressBar ( maxval = joints3D . shape [ 0 ] , widgets = [ txt , pb . Percentage ( ) , pb . Bar ( ) ] ) pbar . start ( ) data = [ ] i = 0 for line in range ( joints3D . shape [ 0 ] ) : scale = np . random . randint ( 0 , 6 ) print line , scale com_ = coms [ line ] . split ( ) com_ = np . asarray ( com_ ) . astype ( np . float ) print i , com_ com2D = self . joint3DToImg ( com_ ) dptFileName = '{0:s}/depth_1_{1:07d}.png' . format ( objdir , line + 1 ) if not os . path . isfile ( dptFileName ) : print ( "File {} does not exist!" . format ( dptFileName ) ) i += 1 continue dpt = self . loadDepthMap ( dptFileName ) # import matplotlib.pyplot as plt # plt.imshow(dpt,cmap='gray') # plt.show() if hand is not None : raise NotImplementedError ( ) # joints in image coordinates gtorig = np . zeros ( ( self . numJoints , 3 ) , np . float32 ) jt = 0 for ii in range ( joints2D . shape [ 1 ] ) : if ii not in eval_idxs : continue gtorig [ jt , 0 ] = joints2D [ line , ii , 0 ] gtorig [ jt , 1 ] = joints2D [ line , ii , 1 ] gtorig [ jt , 2 ] = joints2D [ line , ii , 2 ] jt += 1 # normalized joints in 3D coordinates gt3Dorig = np . zeros ( ( self . numJoints , 3 ) , np . float32 ) jt = 0 for jj in range ( joints3D . shape [ 1 ] ) : if jj not in eval_idxs : continue gt3Dorig [ jt , 0 ] = joints3D [ line , jj , 0 ] gt3Dorig [ jt , 1 ] = joints3D [ line , jj , 1 ] gt3Dorig [ jt , 2 ] = joints3D [ line , jj , 2 ] jt += 1 # print gt3D # self.showAnnotatedDepth(DepthFrame(dpt,gtorig,gtorig,0,gt3Dorig,gt3Dorig,0,dptFileName,'','')) # Detect hand hd = HandDetector ( dpt , self . fx , self . fy , refineNet = self . refineNet , importer = self ) if not hd . checkImage ( 1 ) : print ( "Skipping image {}, no content" . format ( dptFileName ) ) i += 1 continue try : varcube = 250 + 10 * scale cube_0 = ( varcube , varcube , varcube ) if cube is None : cube_ = cube_0 else : cube_ = cube dpt , M , com = hd . cropArea3D ( com = com2D , size = cube_ , docom = docom , dsize = ( 96 , 96 ) ) except UserWarning : print ( "Skipping image {}, no hand detected" . format ( dptFileName ) ) continue com3D = self . jointImgTo3D ( com ) gt3Dcrop = gt3Dorig - com3D # normalize to com gtcrop = transformPoints2D ( gtorig , M ) # print("{}".format(gt3Dorig)) # self.showAnnotatedDepth(DepthFrame(dpt,gtorig,gtcrop,M,gt3Dorig,gt3Dcrop,com3D,dptFileName,'','')) data . append ( DepthFrame ( dpt . astype ( np . float32 ) , gtorig , gtcrop , M , gt3Dorig , gt3Dcrop , com3D , dptFileName , '' , self . sides [ seqName ] , { } , cube_ ) ) # self.showAnnotatedDepth(data[0]) pbar . update ( i ) i += 1 # early stop if len ( data ) >= Nmax : break pbar . finish ( ) print ( "Loaded {} samples." . format ( len ( data ) ) ) if self . useCache : print ( "Save cache data to {}" . format ( pickleCache ) ) f = open ( pickleCache , 'wb' ) cPickle . dump ( ( seqName , data , config ) , f , protocol = cPickle . HIGHEST_PROTOCOL ) f . close ( ) # shuffle data if shuffle and rng is not None : print ( "Shuffling" ) rng . shuffle ( data ) return NamedImgSequence ( seqName , data , config )