Module
- class Module(module)
Represents a module instance used for model inference in runtime. This is a wrapper of the TCIM module.
Example
Example1: Single model inference.
import tcim_lite as tcim # Load the TCIM model module = tcim.runtime.Module.load("model_name.hmm") # Data preprocess input_data = cv2.imread("image.png") ... # Get the total number of model inputs input_num = module.get_num_inputs() # For each input for id in range(0, input_num): # Get the input name input_name = module.get_input_name(id) # Get the information about input data input_info = module.get_input_info(input_name) # Set input data to the input with the given input name module.set_input(input_name, input_data) # Infer model module.run() module.sync() # Get the total number of outputs output_num = module.get_num_outputs() # For each output: for id in range(0, output_num): # Get the output name output_name = module.get_output_name(id) # Get the information about output data output_info = module.get_output_info(output_name).astype(np.float32) # Get the output data output_data = module.get_output(output_name).astype(np.float32).numpy()
Example2: Multi-model inference.
# Load the first model part1 = tcim.runtime.Module.load("petr_part1.hmm") # Set the input of the first model for name in inputs: input_data = inputs[name] input_data = np.concatenate([input_data for i in range(batch)], axis=0) part1.set_input(name, input_data) # Load the second model part2 = tcim.runtime.Module.load("petr_part2.hmm") # Set the input name of the second model as the output name of the first model part2_input_name = "pts_bbox_head_transformer_reshape_0_reshape" # Infer the first model part1.run() part1.sync() # Get the output data of first model part1_output = part1.get_output(part2_input_name) # Pass the output data of first model to the second model part2.set_input(part2_input_name, part1_output) # Infer the second model part2.run() part2.sync() # Get the output of second model outputs = [] for i in range(part2.get_num_outputs()): output_name = part2.get_output_name(i) output = part2.get_output(output_name) outputs.append(output)
Constructor for the Module class.
Methods
Constructor for the Module class.
Saves all input/output tensors of the current module to the specified directory, along with a tester-compatible
model.json.Retrieves the the custom message when the model is compiled by option '--custom_msg'.
Gets the input tensor to the pre-allocated memory with the given tensor name.
Gets output data from pre-allocated memory on host or Houmo device with the given tensor name.
Deprecated: Use get_dev_input instead.
Gets the tensor information, such as tensor shape and data type with the given input tensor name.
Gets the name of the id-th input tensor on device.
Retrieves the date when the model is compiled.
Gets the total number of input tensors in the network model.
Gets the total number of output tensors in the network model.
Gets output data from pre-allocated memory on host or Houmo device with the given tensor name.
Gets the information about the output tensor of model inference, such as tensor shape and data type with the given output tensor name.
Gets the name of the id-th output tensor.
Returns the status of the initialization.
Loads a built TCIM model with the specified model file and configuration options.
Loads dumped input tensors from a DumpInOut directory and sets them into the current module.
Loads and returns the model information as a JSON string from a binary model file (.hmm or .hmms).
Infers a model.
Sets the input data to the pre-allocated memory with the given tensor name and input data.
Sets the output data to the pre-allocated memory on Houmo device with the given tensor name.
Sets the input data to the pre-allocated memory on host or device with the given tensor name and input data.
Deprecated: Use set_dev_output instead.
Sets a stream to be used for model inference.
Waits for the completion of all preceding tasks in the stream that is related to the module.