lib/datasets/imagenetVID.py
def _load_image_set_index(self):
        '''
        Load all the image index.
        '''
        if self._image_set == 'train':
            image_set_file = os.path.join(self._data_path, 'ImageSets', 'trainr_VID_TRA.pkl')
            image_index = []
            if os.path.exists(image_set_file):
                with open(image_set_file, 'r') as f:
                    '''
                    data = f.readlines()
                    for line in data:
                        if line != '':
                            image_index.append(line)
                    '''
                    image_index, structured_indexes = pickle.load(f)
                    return image_index, structured_indexes

            # We use vid_indexes to contain all video folders for each category.
            vid_indexes = []
            for i in range(1, 31):
                vid_set_file = os.path.join(self._data_path, 'ImageSets', 'VID', 'train_' + str(i) + '.txt')
                with open(vid_set_file) as f:
                    tmp_index = [x.strip() for x in f.readlines()]
                    vtmp_index = []
                    for line in tmp_index:
                        line = line.split(' ')
                        if line[1] == '1':
                            vtmp_index.append(self._data_path + '/Data/VID/train/' + line[0])
                        else:
                            print(line)
                            raise 'Please check your file list.'

                    vid_indexes.append(vtmp_index)

            # list hold all video image indexes.
            image_indexes = []
            # [cat,...[vid,...[index...]]]
            structured_indexes = []
            idx_counter = 0
            for vid_idx in vid_indexes:
                cat_holder = []
                for vid_id in vid_idx:
                    vid_holder = []
                    flist = os.listdir(vid_id)
                    nfiles = len(flist)
                    for iid in range(self._gap // 2, nfiles, self._gap):
                        image_indexes.append(os.path.join(vid_id, '%06d' % (iid)))
                        vid_holder.append(idx_counter)
                        idx_counter += 1
                    cat_holder.append(vid_holder)
                structured_indexes.append(cat_holder)

            with open(image_set_file, 'w') as f:
                '''
                for line in image_indexes:
                        f.write(line + '\n')
                '''
                pickle.dump((image_indexes, structured_indexes), f, pickle.HIGHEST_PROTOCOL)
            return image_indexes, structured_indexes
        else:
            vid_set_file = os.path.join(self._data_path, 'ImageSets', 'VID', 'val.txt')
            assert os.path.exists(vid_set_file), vid_set_file + ' does not exist.'
            image_indexes = []
            # [vid,...[index...]]
            structured_indexes = []
            last_dir = None
            tmp_holder = None
            i = 0
            with open(vid_set_file, 'r') as f:
                for x in f.readlines():
                    line = x.strip().split(' ')
                    dir_name = os.path.dirname(line[0])
                    if dir_name != last_dir:
                        if tmp_holder is not None:
                            structured_indexes.append(tmp_holder)
                        tmp_holder = []
                        last_dir = dir_name
                    image_indexes.append(self._data_path + '/Data/VID/val/' + line[0])
                    tmp_holder.append(i)
                    i += 1
                # Add the last vid.
                structured_indexes.append(tmp_holder)

            print('Total number of videos are: %d.' % (len(structured_indexes)))
            print('Total number of video images are: %d.' % (len(image_indexes)))
            return image_indexes, structured_indexes

        Load all the image index.
        
Load all the image index.
Load all the image index .
def _load_image_set_index(self):
        if self._image_set == 'train':
            image_set_file = os.path.join(self._data_path, 'ImageSets', 'trainr_VID_TRA.pkl')
            image_index = []
            if os.path.exists(image_set_file):
                with open(image_set_file, 'r') as f:
                    image_index, structured_indexes = pickle.load(f)
                    return image_index, structured_indexes
            vid_indexes = []
            for i in range(1, 31):
                vid_set_file = os.path.join(self._data_path, 'ImageSets', 'VID', 'train_' + str(i) + '.txt')
                with open(vid_set_file) as f:
                    tmp_index = [x.strip() for x in f.readlines()]
                    vtmp_index = []
                    for line in tmp_index:
                        line = line.split(' ')
                        if line[1] == '1':
                            vtmp_index.append(self._data_path + '/Data/VID/train/' + line[0])
                        else:
                            print(line)
                            raise 'Please check your file list.'
                    vid_indexes.append(vtmp_index)
            image_indexes = []
            structured_indexes = []
            idx_counter = 0
            for vid_idx in vid_indexes:
                cat_holder = []
                for vid_id in vid_idx:
                    vid_holder = []
                    flist = os.listdir(vid_id)
                    nfiles = len(flist)
                    for iid in range(self._gap // 2, nfiles, self._gap):
                        image_indexes.append(os.path.join(vid_id, '%06d' % (iid)))
                        vid_holder.append(idx_counter)
                        idx_counter += 1
                    cat_holder.append(vid_holder)
                structured_indexes.append(cat_holder)
            with open(image_set_file, 'w') as f:
                pickle.dump((image_indexes, structured_indexes), f, pickle.HIGHEST_PROTOCOL)
            return image_indexes, structured_indexes
        else:
            vid_set_file = os.path.join(self._data_path, 'ImageSets', 'VID', 'val.txt')
            assert os.path.exists(vid_set_file), vid_set_file + ' does not exist.'
            image_indexes = []
            structured_indexes = []
            last_dir = None
            tmp_holder = None
            i = 0
            with open(vid_set_file, 'r') as f:
                for x in f.readlines():
                    line = x.strip().split(' ')
                    dir_name = os.path.dirname(line[0])
                    if dir_name != last_dir:
                        if tmp_holder is not None:
                            structured_indexes.append(tmp_holder)
                        tmp_holder = []
                        last_dir = dir_name
                    image_indexes.append(self._data_path + '/Data/VID/val/' + line[0])
                    tmp_holder.append(i)
                    i += 1
                structured_indexes.append(tmp_holder)
            print('Total number of videos are: %d.' % (len(structured_indexes)))
            print('Total number of video images are: %d.' % (len(image_indexes)))
            return image_indexes, structured_indexes
def _load_image_set_index ( self ) : if self . _image_set == 'train' : image_set_file = os . path . join ( self . _data_path , 'ImageSets' , 'trainr_VID_TRA.pkl' ) image_index = [ ] if os . path . exists ( image_set_file ) : with open ( image_set_file , 'r' ) as f : '''
                    data = f.readlines()
                    for line in data:
                        if line != '':
                            image_index.append(line)
                    ''' image_index , structured_indexes = pickle . load ( f ) return image_index , structured_indexes vid_indexes = [ ] for i in range ( 1 , 31 ) : vid_set_file = os . path . join ( self . _data_path , 'ImageSets' , 'VID' , 'train_' + str ( i ) + '.txt' ) with open ( vid_set_file ) as f : tmp_index = [ x . strip ( ) for x in f . readlines ( ) ] vtmp_index = [ ] for line in tmp_index : line = line . split ( ' ' ) if line [ 1 ] == '1' : vtmp_index . append ( self . _data_path + '/Data/VID/train/' + line [ 0 ] ) else : print ( line ) raise 'Please check your file list.' vid_indexes . append ( vtmp_index ) image_indexes = [ ] structured_indexes = [ ] idx_counter = 0 for vid_idx in vid_indexes : cat_holder = [ ] for vid_id in vid_idx : vid_holder = [ ] flist = os . listdir ( vid_id ) nfiles = len ( flist ) for iid in range ( self . _gap // 2 , nfiles , self . _gap ) : image_indexes . append ( os . path . join ( vid_id , '%06d' % ( iid ) ) ) vid_holder . append ( idx_counter ) idx_counter += 1 cat_holder . append ( vid_holder ) structured_indexes . append ( cat_holder ) with open ( image_set_file , 'w' ) as f : '''
                for line in image_indexes:
                        f.write(line + '\n')
                ''' pickle . dump ( ( image_indexes , structured_indexes ) , f , pickle . HIGHEST_PROTOCOL ) return image_indexes , structured_indexes else : vid_set_file = os . path . join ( self . _data_path , 'ImageSets' , 'VID' , 'val.txt' ) assert os . path . exists ( vid_set_file ) , vid_set_file + ' does not exist.' image_indexes = [ ] structured_indexes = [ ] last_dir = None tmp_holder = None i = 0 with open ( vid_set_file , 'r' ) as f : for x in f . readlines ( ) : line = x . strip ( ) . split ( ' ' ) dir_name = os . path . dirname ( line [ 0 ] ) if dir_name != last_dir : if tmp_holder is not None : structured_indexes . append ( tmp_holder ) tmp_holder = [ ] last_dir = dir_name image_indexes . append ( self . _data_path + '/Data/VID/val/' + line [ 0 ] ) tmp_holder . append ( i ) i += 1 structured_indexes . append ( tmp_holder ) print ( 'Total number of videos are: %d.' % ( len ( structured_indexes ) ) ) print ( 'Total number of video images are: %d.' % ( len ( image_indexes ) ) ) return image_indexes , structured_indexes
Load all the image index.
Load all the image index .
'''
        Load all the image index.
        ''' '''
                    data = f.readlines()
                    for line in data:
                        if line != '':
                            image_index.append(line)
                    ''' # We use vid_indexes to contain all video folders for each category. # list hold all video image indexes. # [cat,...[vid,...[index...]]] '''
                for line in image_indexes:
                        f.write(line + '\n')
                ''' # [vid,...[index...]] # Add the last vid.
self