import_pickles

menpo.io.import_pickles(pattern, max_pickles=None, shuffle=False, as_generator=False, verbose=False, **kwargs)[source]

Multiple pickle importer.

Menpo unambiguously uses .pkl as it’s choice of extension for Pickle files. Menpo also supports automatic importing and exporting of gzip compressed pickle files - just choose a filepath ending pkl.gz and gzip compression will automatically be applied. Compression can massively reduce the filesize of a pickle file at the cost of longer import and export times.

Note that this is a function returns a LazyList. Therefore, the function will return immediately and indexing into the returned list will load a pickle at run time. If all pickles should be loaded, then simply wrap the returned LazyList in a Python list.

Parameters
  • pattern (str) – A glob path pattern to search for pickles. Every pickle found to match the glob will be imported one by one. See pickle_paths for more details of what pickles will be found.

  • max_pickles (positive int, optional) – If not None, only import the first max_pickles found. Else, import all.

  • shuffle (bool, optional) – If True, the order of the returned pickles will be randomised. If False, the order of the returned pickles will be alphanumerically ordered.

  • as_generator (bool, optional) – If True, the function returns a generator and assets will be yielded one after another when the generator is iterated over.

  • verbose (bool, optional) – If True progress of the importing will be dynamically reported with a progress bar.

Returns

lazy_list (LazyList or generator of Python objects) – A LazyList or generator yielding whatever Python objects are present in the Pickle file instances that match the glob pattern provided.

Raises

ValueError – If no pickles are found at the provided glob.