(self, seqName, subSeq=None, Nmax=float('inf'), shuffle=False, rng=None, docom=False, cube=None, IfComFile=True)
return NamedImgSequence(seqName, data, config)
Load an image sequence from the dataset
        :param seqName: sequence name, e.g. train
        :param subSeq: list of subsequence names, e.g. 0, 45, 122-5
        :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 subSeq: list of subsequence names, e.g. 0, 45, 122-5
        :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 subSeq : list of subsequence names e . g . 0 45 122 - 5 : 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, IfComFile=True):
        """
        Load an image sequence from the dataset
        :param seqName: sequence name, e.g. train
        :param subSeq: list of subsequence names, e.g. 0, 45, 122-5
        :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['train']}
        else:
            assert isinstance(cube, tuple)
            assert len(cube) == 3
            config = {'cube': cube}

        if subSeq is None:
            pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl'.format(self.cacheDir, self.__class__.__name__, seqName, self.hand,
                                                               HandDetector.detectionModeToString(docom, self.refineNet is not None), config['cube'][0])
        else:
            pickleCache = '{}/{}_{}_{}_{}_{}_{}_cache.pkl'.format(self.cacheDir, self.__class__.__name__, seqName,
                                                                  ''.join(subSeq), self.hand,
                                                                  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)

            # check for multiple subsequences
            if subSeq is not None:
                if len(subSeq) > 1:
                    missing = False
                    for i in range(len(subSeq)):
                        if not os.path.isfile('{}/{}_{}_{}_{}_{}_cache.pkl'.format(self.cacheDir, self.__class__.__name__,
                                                                                   seqName, self.hand, subSeq[i],
                                                                                   HandDetector.detectionModeToString(docom, self.refineNet is not None))):
                            missing = True
                            print("missing: {}".format(subSeq[i]))
                            break

                    if not missing:
                        # load first data
                        pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl'.format(self.cacheDir, self.__class__.__name__,
                                                                           seqName, self.hand, subSeq[0],
                                                                           HandDetector.detectionModeToString(docom, self.refineNet is not None))
                        print("Loading cache data from {}".format(pickleCache))
                        f = open(pickleCache, 'rb')
                        (seqName, fullData, config) = cPickle.load(f)
                        f.close()
                        # load rest of data
                        for i in range(1, len(subSeq)):
                            pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl'.format(self.cacheDir, self.__class__.__name__,
                                                                               seqName, self.hand, subSeq[i],
                                                                               HandDetector.detectionModeToString(docom, self.refineNet is not None))
                            print("Loading cache data from {}".format(pickleCache))
                            f = open(pickleCache, 'rb')
                            (seqName, data, config) = cPickle.load(f)
                            fullData.extend(data)
                            f.close()

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

        self.loadRefineNetLazy(self.refineNet)
        if IfComFile ==True:
            print('Import comfile')
            comfile = open('{}'.format(self.basepath)+'/33ICVL/'+seqName+'_com.txt','r')
            comline = comfile.readlines()
            comfile.close()
        # Load the dataset
        objdir = '{}/Depth/'.format(self.basepath)
        trainlabels = '{}/33ICVL/{}.txt'.format(self.basepath, seqName)

        inputfile = open(trainlabels)
        
        txt = 'Loading {}'.format(seqName)
        pbar = pb.ProgressBar(maxval=len(inputfile.readlines()), widgets=[txt, pb.Percentage(), pb.Bar()])
        pbar.start()
        inputfile.seek(0)
        
        data = []
        i = 0
        print('Import data')
        for line in inputfile:
            # early stop
            if len(data) >= Nmax:
                break

            part = line.split(' ')
            # check for subsequences and skip them if necessary
            subSeqName = ''
            if subSeq is not None:
                p = part[0].split('/')
                # handle original data (unrotated '0') separately
                if ('0' in subSeq) and len(p[0]) > 6:
                    pass
                elif not('0' in subSeq) and len(p[0]) > 6:
                    i += 1
                    continue
                elif (p[0] in subSeq) and len(p[0]) <= 6:
                    pass
                elif not(p[0] in subSeq) and len(p[0]) <= 6:
                    i += 1
                    continue

                if len(p[0]) <= 6:
                    subSeqName = p[0]
                else:
                    subSeqName = '0'

            dptFileName = '{}/{}'.format(objdir, part[0])

            if not os.path.isfile(dptFileName):
                print("File {} does not exist!".format(dptFileName))
                i += 1
                continue
            dpt = self.loadDepthMap(dptFileName)
            if self.hand is not None:
                if self.hand != self.sides[seqName]:
                    raise NotImplementedError()
                    dpt = dpt[:, ::-1]

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

            # normalized joints in 3D coordinates
            gt3Dorig = self.jointsImgTo3D(gtorig)
            # print gt3D
            # self.showAnnotatedDepth(DepthFrame(dpt,gtorig,gtorig,0,gt3Dorig,gt3Dcrop,0,dptFileName,subSeqName,''))

            # 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:
                if IfComFile == True:
                    com3D = list(map(float, comline[i].replace('\n', '').split(' ')))
                    com2D = self.joint3DToImg(com3D)
                    dpt, M, com = hd.cropArea3D(com=com2D,size=config['cube'], docom=docom,dsize=(96,96))
                else:
                    dpt, M, com = hd.cropArea3D(com=gtorig[self.crop_joint_idx], size=config['cube'], docom=docom,dsize=(96,96))
            except UserWarning:
                print("Skipping image {}, no hand detected".format(dptFileName))
                i += 1
                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,subSeqName,''))

            data.append(DepthFrame(dpt.astype(np.float32), gtorig, gtcrop, M, gt3Dorig, gt3Dcrop, com3D, dptFileName,
                                   subSeqName, 'left', {},cube))
            pbar.update(i)
            i += 1
        # print(i)
        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 , IfComFile = True ) : 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 [ 'train' ] } else : assert isinstance ( cube , tuple ) assert len ( cube ) == 3 config = { 'cube' : cube } if subSeq is None : pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl' . format ( self . cacheDir , self . __class__ . __name__ , seqName , self . hand , HandDetector . detectionModeToString ( docom , self . refineNet is not None ) , config [ 'cube' ] [ 0 ] ) else : pickleCache = '{}/{}_{}_{}_{}_{}_{}_cache.pkl' . format ( self . cacheDir , self . __class__ . __name__ , seqName , '' . join ( subSeq ) , self . hand , 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 ) # check for multiple subsequences if subSeq is not None : if len ( subSeq ) > 1 : missing = False for i in range ( len ( subSeq ) ) : if not os . path . isfile ( '{}/{}_{}_{}_{}_{}_cache.pkl' . format ( self . cacheDir , self . __class__ . __name__ , seqName , self . hand , subSeq [ i ] , HandDetector . detectionModeToString ( docom , self . refineNet is not None ) ) ) : missing = True print ( "missing: {}" . format ( subSeq [ i ] ) ) break if not missing : # load first data pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl' . format ( self . cacheDir , self . __class__ . __name__ , seqName , self . hand , subSeq [ 0 ] , HandDetector . detectionModeToString ( docom , self . refineNet is not None ) ) print ( "Loading cache data from {}" . format ( pickleCache ) ) f = open ( pickleCache , 'rb' ) ( seqName , fullData , config ) = cPickle . load ( f ) f . close ( ) # load rest of data for i in range ( 1 , len ( subSeq ) ) : pickleCache = '{}/{}_{}_{}_{}_{}_cache.pkl' . format ( self . cacheDir , self . __class__ . __name__ , seqName , self . hand , subSeq [ i ] , HandDetector . detectionModeToString ( docom , self . refineNet is not None ) ) print ( "Loading cache data from {}" . format ( pickleCache ) ) f = open ( pickleCache , 'rb' ) ( seqName , data , config ) = cPickle . load ( f ) fullData . extend ( data ) f . close ( ) # shuffle data if shuffle and rng is not None : print ( "Shuffling" ) rng . shuffle ( fullData ) if not ( np . isinf ( Nmax ) ) : return NamedImgSequence ( seqName , fullData [ 0 : Nmax ] , config ) else : return NamedImgSequence ( seqName , fullData , config ) self . loadRefineNetLazy ( self . refineNet ) if IfComFile == True : print ( 'Import comfile' ) comfile = open ( '{}' . format ( self . basepath ) + '/33ICVL/' + seqName + '_com.txt' , 'r' ) comline = comfile . readlines ( ) comfile . close ( ) # Load the dataset objdir = '{}/Depth/' . format ( self . basepath ) trainlabels = '{}/33ICVL/{}.txt' . format ( self . basepath , seqName ) inputfile = open ( trainlabels ) txt = 'Loading {}' . format ( seqName ) pbar = pb . ProgressBar ( maxval = len ( inputfile . readlines ( ) ) , widgets = [ txt , pb . Percentage ( ) , pb . Bar ( ) ] ) pbar . start ( ) inputfile . seek ( 0 ) data = [ ] i = 0 print ( 'Import data' ) for line in inputfile : # early stop if len ( data ) >= Nmax : break part = line . split ( ' ' ) # check for subsequences and skip them if necessary subSeqName = '' if subSeq is not None : p = part [ 0 ] . split ( '/' ) # handle original data (unrotated '0') separately if ( '0' in subSeq ) and len ( p [ 0 ] ) > 6 : pass elif not ( '0' in subSeq ) and len ( p [ 0 ] ) > 6 : i += 1 continue elif ( p [ 0 ] in subSeq ) and len ( p [ 0 ] ) <= 6 : pass elif not ( p [ 0 ] in subSeq ) and len ( p [ 0 ] ) <= 6 : i += 1 continue if len ( p [ 0 ] ) <= 6 : subSeqName = p [ 0 ] else : subSeqName = '0' dptFileName = '{}/{}' . format ( objdir , part [ 0 ] ) if not os . path . isfile ( dptFileName ) : print ( "File {} does not exist!" . format ( dptFileName ) ) i += 1 continue dpt = self . loadDepthMap ( dptFileName ) if self . hand is not None : if self . hand != self . sides [ seqName ] : raise NotImplementedError ( ) dpt = dpt [ : , : : - 1 ] # joints in image coordinates gtorig = np . zeros ( ( self . numJoints , 3 ) , np . float32 ) for joint in range ( self . numJoints ) : for xyz in range ( 0 , 3 ) : gtorig [ joint , xyz ] = part [ joint * 3 + xyz + 1 ] # normalized joints in 3D coordinates gt3Dorig = self . jointsImgTo3D ( gtorig ) # print gt3D # self.showAnnotatedDepth(DepthFrame(dpt,gtorig,gtorig,0,gt3Dorig,gt3Dcrop,0,dptFileName,subSeqName,'')) # 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 : if IfComFile == True : com3D = list ( map ( float , comline [ i ] . replace ( '\n' , '' ) . split ( ' ' ) ) ) com2D = self . joint3DToImg ( com3D ) dpt , M , com = hd . cropArea3D ( com = com2D , size = config [ 'cube' ] , docom = docom , dsize = ( 96 , 96 ) ) else : dpt , M , com = hd . cropArea3D ( com = gtorig [ self . crop_joint_idx ] , size = config [ 'cube' ] , docom = docom , dsize = ( 96 , 96 ) ) except UserWarning : print ( "Skipping image {}, no hand detected" . format ( dptFileName ) ) i += 1 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,subSeqName,'')) data . append ( DepthFrame ( dpt . astype ( np . float32 ) , gtorig , gtcrop , M , gt3Dorig , gt3Dcrop , com3D , dptFileName , subSeqName , 'left' , { } , cube ) ) pbar . update ( i ) i += 1 # print(i) 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 )