コード例 #1
0
    def prepare(self):
        self.meta = self.prepare_meta(self.lmdb_paths)
        if self.unpack is None:
            self.unpack = self.default_unpack

            # The fetcher is supposed to be initialized in the
            # sub-processes, or it will cause CRC Error.
            self.fetcher = None

        self.data_ids = self.meta.get('data_ids', self.meta.get('data_id', []))
        if self.debug:
            self.data_ids = self.data_ids[:32]
        self.num_samples = len(self.data_ids)

        # prepare lmdb environments
        for path in self.lmdb_paths:
            path = os.path.join(path, '')
            env = lmdb.open(path, max_dbs=1, lock=False)
            db_image = env.open_db('image'.encode())
            self.envs.append(env)
            self.txns[path] = env.begin(db=db_image)

        if is_main():
            print(self.num_samples, 'images found')
        return self
コード例 #2
0
ファイル: meta_cache.py プロジェクト: zhangliang-04/MegReader
 def read(self, nori_path):
     path = self.hash(nori_path)
     while not self.connection.exists(os.path.join(path, '__keys__')):
         warnings.warn('Cache not found in redis:' + str(path))
         if is_main():
             warnings.warn('Now may try to load and save meta from file')
             return None
         else:
             time.sleep(2)
     return RedisMeta(self.connection, path)
コード例 #3
0
ファイル: meta_cache.py プロジェクト: zjzcn1/MegReader
    def save(self, nori_path, meta):
        if not is_main():
            return False

        path = self.hash(nori_path)
        for key, value_list in meta.items():
            pipe = self.connection.pipeline()
            pipe.sadd(os.path.join(path, '__keys__'), key)
            for value in value_list:
                pipe.lpush(os.path.join(path, key), value)
            pipe.execute()
        return True
コード例 #4
0
    def prepare(self):
        self.meta = self.prepare_meta(self.file_paths)

        if self.unpack is None:
            self.unpack = self.default_unpack

        self.data_ids = self.meta.get('data_ids', self.meta.get('data_id', []))
        if self.debug:
            self.data_ids = self.data_ids[:32]
        self.num_samples = len(self.data_ids)
        if is_main():
            print(self.num_samples, 'images found')
        return self
コード例 #5
0
    def prepare(self):
        self.meta = self.prepare_meta(self.nori_paths)
        if self.unpack is None:
            self.unpack = self.defulat_unpack

            # The fetcher is supposed to be initialized in the
            # sub-processes, or it will cause CRC Error.
            self.fetcher = None

        self.data_ids = self.meta.get('data_ids', self.meta.get('data_id', []))
        if self.debug:
            self.data_ids = self.data_ids[:32]
        self.num_samples = len(self.data_ids)
        if is_main():
            print(self.num_samples, 'images found')
        return self