Multitask Image Classification with TAO Deploy

Multitask classification etlt file generated from tao export is taken as an input to tao-deploy to generate optimized TensorRT engine. For more information about training the Multitask Image Classification, please refer to Multitask Image Classification training documentation.

Converting .etlt File into TensorRT Engine

Same spec file can be used as the tao multitask_classification export command.

Use the following command to run Multitask Image Classification engine generation:

Copy
Copied!

tao-deploy multitask_classification gen_trt_engine [-h] [-v]
-m MODEL_PATH
-k KEY
[--data_type {fp32,fp16,int8}]
[--engine_file ENGINE_FILE]
[--cal_image_dir CAL_IMAGE_DIR]
[--cal_data_file CAL_DATA_FILE]
[--cal_cache_file CAL_CACHE_FILE]
[--max_batch_size MAX_BATCH_SIZE]
[--min_batch_size MIN_BATCH_SIZE]
[--opt_batch_size OPT_BATCH_SIZE]
[--batch_size BATCH_SIZE]
[--batches BATCHES]
[--max_workspace_size MAX_WORKSPACE_SIZE]
[-s STRICT_TYPE_CONSTRAINTS]
[--gpu_index GPU_INDEX]
[--log_file LOG_FILE]


Required Arguments

• -m, --model_path: The .etlt model to be converted.

• -k, --key: A user-specific encoding key to load a .etlt model.

Optional Arguments

• -h, --help: Show this help message and exit.

• --data_type: The desired engine data type. The options are fp32, fp16, int8. The default value is fp32. A calibration cache will be generated in INT8 mode. If using INT8, the following INT8 arguments are required.

• --engine_file: Path to the serialized TensorRT engine file. Note that this file is hardware specific, and cannot be generalized across GPUs. As TensorRT engine file is hardware specific, you cannot use this engine file for deployment unless the deployment GPU is identical to training GPU.

• -s, --strict_type_constraints: A Boolean flag indicating whether to apply the TensorRT strict type constraints when building the TensorRT engine.

• --gpu_index: The index of (discrete) GPUs used for exporting the model. You can specify the index of the GPU to run export if the machine has multiple GPUs installed. Note that gen_trt_engine can only run on a single GPU.

• --log_file: The path to the log file. The default path is “stdout”.

INT8 Engine Generation Required Arguments

• --cal_data_file: Tensorfile generated for calibrating the engine. This can also be an output file if used with --cal_image_dir.

• --cal_image_dir: Directory of images to use for calibration.

Note

--cal_image_dir parameter for images and applies the necessary preprocessing to generate a tensorfile at the path mentioned in the --cal_data_file parameter, which is in turn used for calibration. The number of batches in the tensorfile generated is obtained from the value set to the --batches parameter, and the batch_size is obtained from the value set to the --batch_size parameter. Be sure that the directory mentioned in --cal_image_dir has at least batch_size * batches number of images in it. The valid image extensions are .jpg, .jpeg, and .png. In this case, the input_dimensions of the calibration tensors are derived from the input layer of the .etlt model.

INT8 Engine Generation Optional Arguments

• --cal_cache_file: The path to save the calibration cache file to. The default value is ./cal.bin.

• --batches: Number of batches to use for calibration. The default value is 10.

• --batch_size: Batch size to use for calibration. The default value is 1.

• --max_batch_size: Maximum batch size of TensorRT engine. The default value is 1.

• --min_batch_size: Minimum batch size of TensorRT engine. The default value is 1.

• --opt_batch_size: Optimal batch size of TensorRT engine. The default value is 1.

• --max_workspace_size: Maximum workspace size in Gb of TensorRT engine. The default value is: (2 Gb).

Sample Usage

Here’s an example of using the gen_trt_engine command to generate INT8 TensorRT engine:

Copy
Copied!

tao-deploy multitask_classification gen_trt_engine -m /workspace/mcls.etlt \