torchref.utils.serialization module

JSON serialization helpers for torch tensors and numpy arrays.

torchref.utils.serialization.convert_to_serializable(obj)[source]

Convert tensors and numpy arrays to JSON-serializable types.

Recursively walks dicts, lists, and tuples, converting torch.Tensor, numpy.ndarray, and numpy scalar types to plain Python objects that json.dump can handle.

Parameters:

obj (object) – Arbitrary Python object (tensor, array, dict, list, scalar, …).

Returns:

A JSON-serializable equivalent.

Return type:

object