yobx.torch.torch_helper#

yobx.torch.torch_helper.onnx_dtype_to_torch_dtype(itype: int) dtype[source]#

Converts an onnx type into a torch dtype.

Parameters:

to – onnx dtype

Returns:

torch dtype

yobx.torch.torch_helper.to_numpy(tensor: Tensor) ndarray[source]#

Converts a torch.Tensor to numpy.ndarray.

yobx.torch.torch_helper.to_tensor(tensor: TensorProto, base_dir: str = '') Tensor[source]#

Converts a TensorProto to a torch.Tensor.

Parameters:
  • tensor – a TensorProto object.

  • base_dir – if external tensor exists, base_dir can help to find the path to it

Returns:

the converted torch tensor

yobx.torch.torch_helper.torch_deepcopy(value: Any) Any[source]#

Makes a deep copy.

Parameters:

value – any value

Returns:

a deep copy

yobx.torch.torch_helper.torch_dtype_to_onnx_dtype(to: dtype) int[source]#

Converts a torch dtype into a onnx element type.

Parameters:

to – torch dtype

Returns:

onnx type