deepsparse.utils package

Submodules

deepsparse.utils.data module

deepsparse.utils.data.arrays_to_bytes(arrays: List[numpy.array])bytearray[source]
Parameters

arrays – List of numpy arrays to serialize as bytes

Returns

bytearray representation of list of numpy arrays

deepsparse.utils.data.bytes_to_arrays(serialized_arr: bytearray)List[numpy.array][source]
Parameters

serialized_arr – bytearray representation of list of numpy arrays

Returns

List of numpy arrays decoded from input

deepsparse.utils.data.parse_input_shapes(shape_string: str)List[List[int]][source]

Reduces a string representation of a list of shapes to an actual list of shapes. .. rubric:: Examples

“[1,2,3]” -> input0=[1,2,3] “[1,2,3],[4,5,6],[7,8,9]” -> input0=[1,2,3] input1=[4,5,6] input2=[7,8,9]

deepsparse.utils.data.verify_outputs(outputs: List[numpy.array], gt_outputs: List[numpy.array], atol: float = 0.0008, rtol: float = 0.0)List[float][source]

Compares two lists of output tensors, checking that they are sufficiently similar :param outputs: List of numpy arrays, usually model outputs :param gt_outputs: List of numpy arrays, usually reference outputs :param atol: Absolute tolerance for allclose :param rtol: Relative tolerance for allclose :return: The list of max differences for each pair of outputs

deepsparse.utils.log module

deepsparse.utils.onnx module

deepsparse.utils.onnx.generate_random_inputs(onnx_filepath: str, batch_size: Optional[int] = None)List[numpy.array][source]

Generate random data that matches the type and shape of ONNX model, with a batch size override :param onnx_filepath: File path to ONNX model :param batch_size: If provided, override for the batch size dimension :return: List of random tensors

deepsparse.utils.onnx.get_external_inputs(onnx_filepath: str)List[source]

Gather external inputs of ONNX model :param onnx_filepath: File path to ONNX model :return: List of input objects

deepsparse.utils.onnx.get_external_outputs(onnx_filepath: str)List[source]

Gather external outputs of ONNX model :param onnx_filepath: File path to ONNX model :return: List of output objects

deepsparse.utils.onnx.get_input_names(onnx_filepath: str)List[str][source]

Gather names of all external inputs of ONNX model :param onnx_filepath: File path to ONNX model :return: List of string names

deepsparse.utils.onnx.get_output_names(onnx_filepath: str)List[str][source]

Gather names of all external outputs of ONNX model :param onnx_filepath: File path to ONNX model :return: List of string names

deepsparse.utils.onnx.model_to_path(model: Union[str, sparsezoo.objects.model.Model, sparsezoo.objects.file.File])str[source]

Deals with the various forms a model can take. Either an ONNX file, a SparseZoo model stub prefixed by ‘zoo:’, a SparseZoo Model object, or a SparseZoo ONNX File object that defines the neural network

deepsparse.utils.onnx.override_onnx_batch_size(onnx_filepath: str, batch_size: int)str[source]

Rewrite batch sizes of ONNX model, saving the modified model and returning its path :param onnx_filepath: File path to ONNX model :param batch_size: Override for the batch size dimension :return: File path to modified ONNX model

deepsparse.utils.onnx.override_onnx_input_shapes(onnx_filepath: str, input_shapes: Union[List[int], List[List[int]]])str[source]

Rewrite input shapes of ONNX model, saving the modified model and returning its path :param onnx_filepath: File path to ONNX model :param input_shapes: Override for model’s input shapes :return: File path to modified ONNX model

Module contents