About --loadInputs in trtexec


trtexec --loadInputs expect the input file to be raw binary data
In practice, you can save the binary data from the numpy array using array.tofile(file)

For example, if the input is an image, you could use a python script like this:

import PIL.Image
import numpy as np
im = PIL.Image.open("input_image.jpg").resize((512, 512))
data = np.asarray(im, dtype=np.float32)

This will convert an image to that .dat file which is basically just a raw binary buffer of datatype fp32. Or if it’s not an image, whatever other data source you use, just load it with numpy, cast it to the correct data type and shape that TensorRT expects to use as input (usually but not always float32) and write it out with numpy’s .tofile() function as above.
Then on trtexec, you can load it like this:
trtexec ... ... ... --loadInputs='input_tensor:input_tensor.dat'

Where input_tensor is the name of the input binding/tensor in the TensorRT engine, and input_tensor.dat is the path to the file generated from numpy above.

Thank you.