py123detection.mmcv_export.writer

Writing the infos to a pickle that the training environment can read.

Conversion needs py123d (Python >= 3.9), while mmdetection3d setups are usually on Python 3.8 and numpy 1.x. Three things break a pickle across that gap:

  1. Pickle protocol 5 is unreadable before Python 3.8, so the default is 4.

  2. Any custom class (pathlib.Path, a 123D enum, …) only unpickles where it is importable. validate_portable() rejects everything but built-ins and numpy arrays before writing.

  3. Arrays pickled under numpy 2 fail to load under numpy 1 (No module named 'numpy._core'). Either install numpy<2 for the conversion, or write array_format="portable", which stores arrays as nested lists and needs py123detection.mmcv_plugin to rebuild them.

Functions

build_metadata(taxonomy_name, class_names, ...)

The metadata block stored next to the infos.

dump_infos(infos, output_path, metadata[, ...])

Write {'infos': ..., 'metadata': ...} for mmdetection3d.

inspect_pickle(path)

(metadata, number of infos) of an exported pickle.

numpy_compatibility_warnings(array_format)

to_portable_arrays(obj)

Recursively replace numpy arrays and scalars with lists and Python numbers.

validate_portable(obj[, path])

Raise PortabilityError on the first value that needs more than built-ins and numpy to unpickle.

Classes

WriteResult(path, num_infos, size_bytes, ...)

Exceptions

PortabilityError

The payload holds something that would not unpickle in a clean environment.

exception py123detection.mmcv_export.writer.PortabilityError[source]

Bases: TypeError

The payload holds something that would not unpickle in a clean environment.

class py123detection.mmcv_export.writer.WriteResult(path, num_infos, size_bytes, protocol, array_format, numpy_version, warnings)[source]

Bases: object

path: Path
num_infos: int
size_bytes: int
protocol: int
array_format: str
numpy_version: str
warnings: List[str]
py123detection.mmcv_export.writer.validate_portable(obj, path='payload')[source]

Raise PortabilityError on the first value that needs more than built-ins and numpy to unpickle.

Return type:

None

py123detection.mmcv_export.writer.to_portable_arrays(obj)[source]

Recursively replace numpy arrays and scalars with lists and Python numbers.

Return type:

Any

py123detection.mmcv_export.writer.numpy_compatibility_warnings(array_format)[source]
Return type:

List[str]

py123detection.mmcv_export.writer.build_metadata(taxonomy_name, class_names, version, sources, extra=None)[source]

The metadata block stored next to the infos.

mmdetection3d only reads version; the rest records how the export was produced.

Return type:

Dict[str, Any]

py123detection.mmcv_export.writer.dump_infos(infos, output_path, metadata, protocol=DEFAULT_PICKLE_PROTOCOL, array_format='numpy', validate=True)[source]

Write {'infos': ..., 'metadata': ...} for mmdetection3d.

Parameters:
  • protocol (int) – 2 to 5. Anything above 4 warns, since it needs Python >= 3.8 to read.

  • array_format (str) – "numpy", or "portable" to store arrays as nested lists.

  • validate (bool) – Check the payload with validate_portable() before writing.

Return type:

WriteResult

py123detection.mmcv_export.writer.inspect_pickle(path)[source]

(metadata, number of infos) of an exported pickle. A cheap readability check for the training env.

Return type:

Tuple[Dict[str, Any], int]