(self, seqName, subSeq=None, 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. subject1
        :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. subject1
        :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 . subject1 : param Nmax : maximum number of samples to load : return : returns named image sequence
def loadSequence(self, seqName, subSeq=None, 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. subject1
        :param Nmax: maximum number of samples to load
        :return: returns named image sequence
        """

        if (subSeq is not None) and (not isinstance(subSeq, list)):
            raise TypeError("subSeq must be None or list")

        if cube is None:
            config = {'cube': self.default_cubes[seqName]}
        else:
            assert isinstance(cube, tuple)
            assert len(cube) == 3
            config = {'cube': cube}

        if subSeq is None:
            pickleCache = '{}/{}_{}_None_{}_{}_cache.pkl'.format(self.cacheDir, self.__class__.__name__, seqName, HandDetector.detectionModeToString(docom, self.refineNet is not None), config['cube'][0])
        else:
            pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl'.format(self.cacheDir, self.__class__.__name__, seqName, ''.join(subSeq), HandDetector.detectionModeToString(docom, self.refineNet is not None), config['cube'][0])
        if self.useCache & 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)
        subdirs = sorted([name for name in os.listdir(objdir) if os.path.isdir(os.path.join(objdir, name))])
        print subdirs

        txt = 'Loading {}'.format(seqName)
        nImgs = sum([len(files) for r, d, files in os.walk(objdir)]) // 2
        print nImgs
        pbar = pb.ProgressBar(maxval=nImgs, widgets=[txt, pb.Percentage(), pb.Bar()])
        pbar.start()

        # comlabels='{}/center/center_test_{}_refined.txt'.format(self.basepath,seqName[1])
        # print comlabels
        # comsfile = open(comlabels, 'r')

        data = []
        pi = 0

        for subdir in subdirs:
            # check for subsequences and skip them if necessary
            subSeqName = ''
            if subSeq is not None:
                if subdir not in subSeq:
                    continue

                subSeqName = subdir

            # iterate all subdirectories
            trainlabels = '{}/{}/joint.txt'.format(objdir, subdir)

            inputfile = open(trainlabels)
            # read number of samples
            nImgs = int(inputfile.readline())

            for i in range(nImgs):
                scale = np.random.randint(0, 6)
                # early stop
                if len(data) >= Nmax:
                    break

                # com=comsfile.readline()
                # com_=com.split()
                # com_=np.asarray(com_,np.float)
                # com2D = self.joint3DToImg(com_)

                line = inputfile.readline()
                part = line.split(' ')

                dptFileName = '{}/{}/{}_depth.bin'.format(objdir, subdir, str(i).zfill(6))

                if not os.path.isfile(dptFileName):
                    print("File {} does not exist!".format(dptFileName))
                    continue
                dpt = self.loadDepthMap(dptFileName)

                if hand is not None:
                    raise NotImplementedError()

                # joints in image coordinates
                gt3Dorig = np.zeros((self.numJoints, 3), np.float32)
                for joint in range(gt3Dorig.shape[0]):
                    for xyz in range(0, 3):
                        gt3Dorig[joint, xyz] = part[joint*3+xyz]

                # invert axis
                # gt3Dorig[:, 0] *= (-1.)
                # gt3Dorig[:, 1] *= (-1.)
                gt3Dorig[:, 2] *= (-1.)

                # normalized joints in 3D coordinates
                gtorig = self.joints3DToImg(gt3Dorig)
                # print gt3D
                # self.showAnnotatedDepth(DepthFrame(dpt,gtorig,gtorig,0,gt3Dorig,gt3Dcrop,com3D,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))
                    continue

                try:
                    varcube = 150 + 10 * scale
                    cube_0 = (varcube, varcube, varcube)
                    if cube is None:
                        cube_ = cube_0
                    else:
                        cube_ = cube
                    dpt, M, com = hd.cropArea3D(com=gtorig[self.crop_joint_idx], size=cube_, docom=docom,dsize=(96,96))
                    #print cube_
                    # import matplotlib.pyplot as plt
                    # plt.imshow(dpt)
                    # plt.show()
                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, subSeqName, self.sides[seqName], {},cube_))
                pbar.update(pi)
                pi += 1

            inputfile.close()

        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 , subSeq = None , Nmax = float ( 'inf' ) , shuffle = False , rng = None , docom = False , cube = None , hand = None ) : if ( subSeq is not None ) and ( not isinstance ( subSeq , list ) ) : raise TypeError ( "subSeq must be None or list" ) if cube is None : config = { 'cube' : self . default_cubes [ seqName ] } else : assert isinstance ( cube , tuple ) assert len ( cube ) == 3 config = { 'cube' : cube } if subSeq is None : pickleCache = '{}/{}_{}_None_{}_{}_cache.pkl' . format ( self . cacheDir , self . __class__ . __name__ , seqName , HandDetector . detectionModeToString ( docom , self . refineNet is not None ) , config [ 'cube' ] [ 0 ] ) else : pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl' . format ( self . cacheDir , self . __class__ . __name__ , seqName , '' . join ( subSeq ) , HandDetector . detectionModeToString ( docom , self . refineNet is not None ) , config [ 'cube' ] [ 0 ] ) if self . useCache & 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 ) subdirs = sorted ( [ name for name in os . listdir ( objdir ) if os . path . isdir ( os . path . join ( objdir , name ) ) ] ) print subdirs txt = 'Loading {}' . format ( seqName ) nImgs = sum ( [ len ( files ) for r , d , files in os . walk ( objdir ) ] ) // 2 print nImgs pbar = pb . ProgressBar ( maxval = nImgs , widgets = [ txt , pb . Percentage ( ) , pb . Bar ( ) ] ) pbar . start ( ) # comlabels='{}/center/center_test_{}_refined.txt'.format(self.basepath,seqName[1]) # print comlabels # comsfile = open(comlabels, 'r') data = [ ] pi = 0 for subdir in subdirs : # check for subsequences and skip them if necessary subSeqName = '' if subSeq is not None : if subdir not in subSeq : continue subSeqName = subdir # iterate all subdirectories trainlabels = '{}/{}/joint.txt' . format ( objdir , subdir ) inputfile = open ( trainlabels ) # read number of samples nImgs = int ( inputfile . readline ( ) ) for i in range ( nImgs ) : scale = np . random . randint ( 0 , 6 ) # early stop if len ( data ) >= Nmax : break # com=comsfile.readline() # com_=com.split() # com_=np.asarray(com_,np.float) # com2D = self.joint3DToImg(com_) line = inputfile . readline ( ) part = line . split ( ' ' ) dptFileName = '{}/{}/{}_depth.bin' . format ( objdir , subdir , str ( i ) . zfill ( 6 ) ) if not os . path . isfile ( dptFileName ) : print ( "File {} does not exist!" . format ( dptFileName ) ) continue dpt = self . loadDepthMap ( dptFileName ) if hand is not None : raise NotImplementedError ( ) # joints in image coordinates gt3Dorig = np . zeros ( ( self . numJoints , 3 ) , np . float32 ) for joint in range ( gt3Dorig . shape [ 0 ] ) : for xyz in range ( 0 , 3 ) : gt3Dorig [ joint , xyz ] = part [ joint * 3 + xyz ] # invert axis # gt3Dorig[:, 0] *= (-1.) # gt3Dorig[:, 1] *= (-1.) gt3Dorig [ : , 2 ] *= ( - 1. ) # normalized joints in 3D coordinates gtorig = self . joints3DToImg ( gt3Dorig ) # print gt3D # self.showAnnotatedDepth(DepthFrame(dpt,gtorig,gtorig,0,gt3Dorig,gt3Dcrop,com3D,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 ) ) continue try : varcube = 150 + 10 * scale cube_0 = ( varcube , varcube , varcube ) if cube is None : cube_ = cube_0 else : cube_ = cube dpt , M , com = hd . cropArea3D ( com = gtorig [ self . crop_joint_idx ] , size = cube_ , docom = docom , dsize = ( 96 , 96 ) ) #print cube_ # import matplotlib.pyplot as plt # plt.imshow(dpt) # plt.show() 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 , subSeqName , self . sides [ seqName ] , { } , cube_ ) ) pbar . update ( pi ) pi += 1 inputfile . close ( ) 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 )