Go to the source code of this file.
Data Structures | |
| struct | Tensor |
| Structure to store tensor information. More... | |
| class | TensorCache |
| Class to manage multiple tensors with string-based lookup. More... | |
Functions | |
| std::string | torch_tensor_sizes_to_string (const torch::Tensor &tensor) |
| Provide a string representation of the sizes of a torch tensor. More... | |
| std::string | torch_tensor_to_string (const torch::Tensor &tensor, int max_values=10) |
| Convert torch tensor to string representation of its values. More... | |
| void | processDataType (std::ifstream &file, Tensor *result, const std::string &dtype, int64_t num_elements, const std::vector< int64_t > &shape_int64, const std::string &file_path, int gpu_id) |
| Helper function to process tensor data based on its type. More... | |
| Tensor * | read_tensor_from_file (const std::string &file_path, int gpu_id=0) |
| Read a tensor from a binary file created by dump_tensor_to_file. More... | |
| void | torch_tensor_display (const torch::Tensor &tensor, const std::string &name="Tensor", bool print_data=false, size_t max_elements=100, int precision=4) |
| Display a PyTorch tensor in a formatted table. More... | |
|
inline |
Helper function to process tensor data based on its type.
This function is used by read_tensor_from_file to handle different data types. It allocates memory, reads data from file, and transfers it to GPU memory.
| file | Open file stream to read data from |
| result | Tensor to populate |
| dtype | Data type string from file |
| num_elements | Total number of elements in tensor |
| shape_int64 | Shape of tensor as int64_t vector |
| file_path | Path to file (for logging) |
| gpu_id | GPU ID where tensor is allocated |
Definition at line 995 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References Tensor::buffer, Tensor::data_type, NvDsDataType_FP32, and Tensor::size.
Referenced by read_tensor_from_file().
|
inline |
Read a tensor from a binary file created by dump_tensor_to_file.
This function reads a tensor from a binary file that was saved using the dump_tensor_to_file function in Python. It handles the file format that includes tensor shape and data type information. The data is loaded into GPU memory.
Supported data types:
| file_path | Path to the binary file containing the tensor data |
| gpu_id | GPU ID where the tensor should be allocated (default 0) |
Definition at line 1057 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References half_float::detail::binary, Tensor::buffer, Tensor::gpu_id, Tensor::name, processDataType(), and Tensor::shape.
|
inline |
Display a PyTorch tensor in a formatted table.
This function displays a PyTorch tensor in the same formatted table style as the Tensor::display method. It shows tensor properties and optionally the tensor values.
| tensor | The PyTorch tensor to display |
| name | Optional name for the tensor (defaults to "Tensor") |
| print_data | Whether to print the tensor data values (defaults to false) |
| max_elements | Maximum number of elements to display (defaults to 100) |
| precision | Number of decimal places for floating point values (defaults to 4) |
Definition at line 1136 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References min().
|
inline |
Provide a string representation of the sizes of a torch tensor.
Converts the dimensions of a PyTorch tensor to a human-readable string format. For example, a tensor with dimensions [3, 224, 224] would return "[3x224x224]".
| tensor | PyTorch tensor whose dimensions to convert |
Definition at line 882 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References pydeepstreamdoc::tensor::TensorDoc::size.
|
inline |
Convert torch tensor to string representation of its values.
This function creates a human-readable string representation of a tensor's values. It handles different data types and allows limiting the number of values displayed.
| tensor | PyTorch tensor to convert to string |
| max_values | Maximum number of values to include in the string, or -1 for all values |
Definition at line 909 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References min().