YOLOv4#
YOLOv4 is an object detection model that is included in TAO. YOLOv4 supports the following tasks:
dataset_convert
kmeans
train
evaluate
inference
prune
export
Preparing the Input Data Structure#
The dataset structure of YOLOv4 is identical to that of DetectNet_v2. The only difference is the command line used to generate the TFRecords from KITTI text labels. To generate TFRecords for YOLOv4 training, use this command:
Required Arguments#
-d, --dataset_spec: path to the dataset specification file.-o, --output_filename: path to the output TFRecords file.
Optional Arguments#
--gpu_index: The GPU index to run this command on. We can specify the GPU index used to run this command if the machine has multiple GPUs installed. Note that this command can only run on a single GPU.
Creating a Configuration File#
Below is a sample for the YOLOv4 specification file. It has 6 major components: yolov4_config,
training_config, eval_config, nms_config, augmentation_config, and
dataset_config. The format of the specification file is a protobuf text (prototxt) message, and each
of its fields can be either a basic data type or a nested message. The top-level structure of the
specification file is summarized in the table below.
random_seed: 42
yolov4_config {
big_anchor_shape: "[(114.94, 60.67), (159.06, 114.59), (297.59, 176.38)]"
mid_anchor_shape: "[(42.99, 31.91), (79.57, 31.75), (56.80, 56.93)]"
small_anchor_shape: "[(15.60, 13.88), (30.25, 20.25), (20.67, 49.63)]"
box_matching_iou: 0.25
matching_neutral_box_iou: 0.5
arch: "resnet"
nlayers: 18
loss_loc_weight: 1.0
loss_neg_obj_weights: 1.0
loss_class_weights: 1.0
label_smoothing: 0.0
big_grid_xy_extend: 0.05
mid_grid_xy_extend: 0.1
small_grid_xy_extend: 0.2
freeze_bn: false
freeze_blocks: 0
force_relu: false
}
training_config {
batch_size_per_gpu: 8
num_epochs: 80
enable_qat: false
checkpoint_interval: 10
learning_rate {
soft_start_cosine_annealing_schedule {
min_learning_rate: 1e-7
max_learning_rate: 1e-4
soft_start: 0.3
}
}
regularizer {
type: L1
weight: 3e-5
}
optimizer {
adam {
epsilon: 1e-7
beta1: 0.9
beta2: 0.999
amsgrad: false
}
}
pretrain_model_path: "EXPERIMENT_DIR/pretrained_resnet18/tlt_pretrained_object_detection_vresnet18/resnet_18.hdf5"
}
eval_config {
average_precision_mode: SAMPLE
batch_size: 8
matching_iou_threshold: 0.5
}
nms_config {
confidence_threshold: 0.001
clustering_iou_threshold: 0.5
top_k: 200
}
augmentation_config {
hue: 0.1
saturation: 1.5
exposure:1.5
vertical_flip:0
horizontal_flip: 0.5
jitter: 0.3
output_width: 1248
output_height: 384
output_channel: 3
randomize_input_shape_period: 100
mosaic_prob: 0.5
mosaic_min_ratio:0.2
image_mean {
key: 'b'
value: 103.9
}
image_mean {
key: 'g'
value: 116.8
}
image_mean {
key: 'r'
value: 123.7
}
}
dataset_config {
data_sources: {
tfrecords_path: "/workspace/tao-experiments/data/training/tfrecords/<tfrecords pattern>"
image_directory_path: "/workspace/tao-experiments/data/training"
}
include_difficult_in_training: true
image_extension: "png"
target_class_mapping {
key: "car"
value: "car"
}
target_class_mapping {
key: "pedestrian"
value: "pedestrian"
}
target_class_mapping {
key: "cyclist"
value: "cyclist"
}
target_class_mapping {
key: "van"
value: "car"
}
target_class_mapping {
key: "person_sitting"
value: "pedestrian"
}
validation_data_sources: {
tfrecords_path: "/workspace/tao-experiments/data/val/tfrecords/<tfrecords pattern>"
image_directory_path: "/workspace/tao-experiments/data/val"
}
}
Training Config#
The training configuration (training_config) defines the parameters needed for
training, evaluation, and inference. Details are summarized in the table below.
Field |
Description |
Data Type and Constraints |
Recommended/Typical Value |
batch_size_per_gpu |
The batch size for each GPU; the effective batch size is batch_size_per_gpu * num_gpus |
Unsigned int, positive |
– |
checkpoint_interval |
The number of training epochs per one model checkpoint/validation |
Unsigned int, positive |
10 |
num_epochs |
The number of epochs to train the network |
Unsigned int, positive. |
– |
enable_qat |
Whether to use quantization-aware training |
Boolean |
Note: YOLOv4 does not support loading a pruned QAT model and retraining
it with QAT disabled, or vice versa. For example, to get a pruned QAT model,
perform the initial training with QAT enabled or |
learning_rate |
One soft_start_annealing_schedule and soft_start_cosine_annealing_schedule with the following nested parameters are supported:
|
Message type |
– |
regularizer |
This parameter configures the regularizer to use while training and contains the following nested parameters:
|
Message type |
L1 (Note: NVIDIA suggests using the L1 regularizer when training a network before pruning, as L1 regularization makes the network weights more prunable.) |
optimizer |
The optimizer can be one of adam, sgd, and rmsprop. Each type has the following parameters:
The meanings of above parameters are same as those in Keras. |
Message type |
– |
pretrain_model_path |
The path to the pretrained model, if any At most, one pretrain_model_path, resume_model_path, and pruned_model_path may be present. |
String |
– |
resume_model_path |
The path to the TAO checkpoint model to resume training, if any At most, one pretrain_model_path, resume_model_path, and pruned_model_path may be present. |
String |
– |
pruned_model_path |
The path to the TAO pruned model for re-training, if any At most, one pretrain_model_path, resume_model_path, and pruned_model_path may be present. |
String |
– |
max_queue_size |
The number of prefetch batches in data loading |
Unsigned int, positive |
– |
n_workers |
The number of workers for data loading per GPU |
Unsigned int, positive |
– |
use_multiprocessing |
Whether to use multiprocessing mode of keras sequence data loader |
Boolean |
true (in case of deadlock, restart training and use False) |
visualizer |
Visualization configuration during training. |
Message type |
– |
early_stopping |
The parameters for early stopping |
Message type |
– |
Note
The learning rate is automatically scaled with the number of GPUs used during training, or the effective learning rate is learning_rate * n_gpu.
Visualization during training#
Visualization during training is configured by the visualizer parameter. The parameters of it are described in the table
below.
Parameter |
Description |
Data Type and Constraints |
Default/Suggested Value |
|
Boolean flag to enable or disable this feature |
bool. |
– |
|
The maximum number of images to be visualized in TensorBoard. |
int. |
|
Visualization during training supports 3 types of visualizations, namely: scalar, image and histogram. These types of visualization all leverage the TensorBoard tool. Each type will have a tab in TensorBoard GUI interface. With the scalar tab, it can visualize scalars like loss, learning rate and validation mAP over time(training step). With the image tab, it can visualize augmented images during training, with bounding boxes drawn on the them. With the histogram tab, it can visualize histograms of each layer’s weights and bias of the model being trained.
If the parameter enabled is set to True, then all above visualizations will be enabled.
Otherwise, all visualization will be disabled.
The parameter num_images is used to limit the maximum number of images to be visualized on
the image tab in TensorBoard.
During the training, visualization can be done anywhere that can access the TensorBoard log directory.
Usually the TAO containers will map volumes to host machine, so TensorBoard can be called on host machine.
The command tensorboard --logdir=/path/to/logs can be used to open the TensorBoard
visualization GUI in web browser. Make sure tensorboard is installed before running this command.
One can run pip3 install tensorboard to install it if it is not installed in the environment.
The /path/to/logs argument is the result directory for training,
with the suffix /logs appended.
Early Stopping#
The parameters for early stopping are described in the table below.
Parameter |
Description |
Data Type and Constraints |
Default/Suggested Value |
|
The metric to monitor in order to enable early stopping. |
string |
|
|
The number of checks of |
int |
Positive integers |
|
The delta of the minimum value of |
float |
Non-negative floats |
Evaluation Config#
The evaluation configuration (eval_config) defines the parameters needed for the
evaluation either during training or standalone evaluation. Details are summarized in the table
below.
Field |
Description |
Data Type and Constraints |
Recommended/Typical Value |
average_precision_mode |
Average Precision (AP) calculation mode can be either SAMPLE or INTEGRATE. SAMPLE is used as VOC metrics for VOC 2009 or before. INTEGRATE is used for VOC 2010 or after. |
ENUM type ( SAMPLE or INTEGRATE) |
SAMPLE |
matching_iou_threshold |
The lowest IoU of the predicted box and ground truth box that can be considered a match |
float |
0.5 |
visualize_pr_curve |
Boolean flag to enable or disable visualization of Precision-Recall curve. |
bool. |
– |
Note
The parameter visualize_pr_curve, if set to True, will produce an image of precision-recall curve during the
evaluate command, the exact path of the image can be seen in the screen log. By checking the image, we can see each class’s performance
regarding the tradeoff between precision and recall.
NMS Config#
The NMS configuration (nms_config) defines the parameters needed for the NMS postprocessing.
NMS config applies to the NMS layer of the model in training, validation, evaluation, inference,
and export. Details are summarized in the table below.
Field |
Description |
Data Type and Constraints |
Recommended/Typical Value |
confidence_threshold |
Boxes with a confidence score less than confidence_threshold are discarded before applying NMS. |
float |
0.01 |
cluster_iou_threshold |
The IoU threshold below which boxes will go through the NMS process. |
float |
0.6 |
top_k |
top_k boxes will be output after the NMS keras layer. If the number of valid boxes is less than k, the returned array will be padded with boxes whose confidence score is 0. |
Unsigned int |
200 |
infer_nms_score_bits |
The number of bits to represent the score values in NMS plugin in TensorRT OSS. The valid range is integers in [1, 10]. Setting it to any other values will make it fall back to ordinary NMS. Currently this optimized NMS plugin is only available in FP16 but it should also be selected by INT8 data type as there is no INT8 NMS in TensorRT OSS and hence this fastest implementation in FP16 will be selected. If falling back to ordinary NMS, the actual data type when building the engine will decide the exact precision(FP16 or FP32) to run at. |
int. In the interval [1, 10]. |
0 |
Augmentation Config#
The augmentation configuration (augmentation_config) defines the parameters needed for
online data augmentation. Details are summarized in the table below.
Field |
Description |
Data Type and Constraints |
Recommended/Typical Value |
hue |
Image hue to be changed within [-hue, hue] * 180.0 |
float of [0, 1] |
0.1 |
saturation |
Image saturation to be changed within [1.0 / saturation, saturation] times |
float >= 1.0 |
1.5 |
exposure |
Image exposure to be changed within [1.0 / exposure, exposure] times |
float >= 1.0 |
1.5 |
vertical_flip |
The probability of images to be vertically flipped |
float of [0, 1] |
0 |
horizontal_flip |
The probability of images to be horizontally flipped |
float of [0, 1] |
0.5 |
jitter |
The maximum jitter allowed in augmentation; “jitter” here refers to jitter augmentation in YOLO networks |
float of [0, 1] |
0.3 |
output_width |
The base output image width of augmentation pipeline |
integer, multiple of 32 |
– |
output_height |
The base output image height of augmentation pipeline |
integer, multiple of 32 |
– |
output_channel |
The number of output channels of augmentation pipeline |
1 or 3 |
– |
output_depth |
The number of bits per pixel per channel of the image. Can be 8 or 16. If it is 16, output_channel should be 1. |
8 or 16 |
8 |
randomize_input_shape_period |
The batch interval to randomly change the output width and height. For value K, the augmentation pipeline will adjust output shape per K batches, and the adjusted output width/height will be within 0.6 to 1.5 times of the base width/height. Note: If K=0, the output width/height will always be the exact base width/height as configured, and training will be much faster. But the accuracy of the trained network might not be as good. |
non-negative integer |
10 |
mosaic_prob |
The probability of mosaic augmentation to be applied on one image |
float of [0, 1] |
0.5 |
mosaic_min_ratio |
The minimum ratio of width/height one sub-image should occupy |
float of (0, 0.5) |
0.2 |
image_mean |
A key/value pair to specify image mean values. If omitted, ImageNet mean will be used for image preprocessing. If set, depending on output_channel, either ‘r/g/b’ or ‘l’ key/value pair must be configured. |
dict |
– |
Dataset Config#
YOLOv4 supports two data formats: the sequence format (images folder and raw labels folder
with KITTI format) and the tfrecords format (images folder and TFRecords). From our experience, if mosaic
augmentation is disabled (mosaic_prob=0), training with TFRecords format is faster. If mosaic
augmentation is enabled (mosaic_prob>0), training with sequence format is faster. The
train and evaluate command will determine the data format based on your
dataset_config.
The YOLOv4 dataloader assumes the training/validation split is already done and the data is
prepared in KITTI format: images and labels are in two separate folders, where each image in the
image folder has a .txt label file with the same filename in the label folder, and the
label file content follows KITTI format. The COCO data format is supported but only through TFRecords.
Prepare the TFRecords using dataset_convert.
Sequence format#
The following is an example dataset_config element if you want to use sequence format:
dataset_config {
data_sources: {
label_directory_path: "/workspace/tao-experiments/data/training/label_2"
image_directory_path: "/workspace/tao-experiments/data/training/image_2"
}
data_sources: {
label_directory_path: "/workspace/tao-experiments/data/training/label_3"
image_directory_path: "/workspace/tao-experiments/data/training/image_3"
}
include_difficult_in_training: true
target_class_mapping {
key: "car"
value: "car"
}
target_class_mapping {
key: "pedestrian"
value: "pedestrian"
}
target_class_mapping {
key: "cyclist"
value: "cyclist"
}
target_class_mapping {
key: "van"
value: "car"
}
target_class_mapping {
key: "person_sitting"
value: "pedestrian"
}
validation_data_sources: {
label_directory_path: "/workspace/tao-experiments/data/val/label_1"
image_directory_path: "/workspace/tao-experiments/data/val/image_1"
}
}
The parameters in dataset_config are defined as follows:
data_sources: The path to datasets to train on. If you have multiple data sources for training, you may use multipledata_sources. This field contains 2 parameters:label_directory_path: The path to the data source label folder.image_directory_path: The path to the data source image folder.
include_difficult_in_training: A flag specifying whether to include difficult boxes in training. If set tofalse, difficult boxes will be ignored. Difficult boxes are those with non-zero occlusion levels in KITTI labels.target_class_mapping: This parameter maps the class names in the labels to the target class to be trained in the network. An element is defined for every source class to target class mapping. This field was included with the intention of grouping similar class objects under one umbrella. For example, “car”, “van”, “heavy_truck”, etc. may be grouped under “automobile”. The “key” field is the value of the class name in the tfrecords file, and the “value” field corresponds to the value that the network is expected to learn.validation_data_sources: Captures the path to datasets to validate on. If you have multiple data sources for validation, you may use multiplevalidation_data_sources. Likedata_sources, this field contains two parameters.
Note
The class names key in the target_class_mapping must be identical to the one shown
in the KITTI labels so that the correct classes are picked up for training.
TFRecords format#
TFRecords format requires tfrecords for all labels. The dataset converter has the same functionality and argument requirements as that of detectnet_v2; for details on how to generate tfrecords, check Pre-processing the Dataset in detectnet_v2.
The following is an example dataset_config element if you want to use tfrecords format
that was converted from KITTI data format. Here, we assume your tfrecords are all generated under a folder called tfrecords, which is under
same parent folder with images and labels:
dataset_config {
data_sources: {
tfrecords_path: "/workspace/tao-experiments/data/training/tfrecords/<tfrecords pattern>"
image_directory_path: "/workspace/tao-experiments/data/training"
}
include_difficult_in_training: true
image_extension: "png"
target_class_mapping {
key: "car"
value: "car"
}
target_class_mapping {
key: "pedestrian"
value: "pedestrian"
}
target_class_mapping {
key: "cyclist"
value: "cyclist"
}
target_class_mapping {
key: "van"
value: "car"
}
target_class_mapping {
key: "person_sitting"
value: "pedestrian"
}
validation_data_sources: {
tfrecords_path: "/workspace/tao-experiments/data/val/tfrecords/<tfrecords pattern>"
image_directory_path: "/workspace/tao-experiments/data/val"
}
}
The parameters in dataset_config are defined as follows:
data_sources: The path to datasets to train on. If you have multiple data sources for training, you may use multipledata_sources. This field contains 2 parameters:tfrecords_path: The path to the data source tfrecords.image_directory_path: The path to the root directory containing the image folder.
image_extension: Image extensions of images contained in the image folder. Note, to use tfrecords format, all images must have same extensions and currently we support jpg and pngvalidation_data_sources: Captures the path to datasets to validate on. This field contains two parameters same asdata_sources. If you have multiple data sources for validation, you may use multiplevalidation_data_sources.
All other fields are same as those in sequence format dataset_config.
16-bit Grayscale Image Support#
TAO YOLOv4 can support 16-bit grayscale images. To enable this feature, simply set output_channel
to 1 and output_depth to 16 in augmentation_config. Besides, normally the 16-bit grayscale images will have different
mean value from RGB images, hence it is usually necessary to set a correct channel mean value for it via the
image_mean dict in augmentation_config. In principle, the channel mean value of the 16-bit images is a statistical value
calculated from the training images. Below is an example on how to set the mean value.
image_mean {
key: "l"
value: 10141.5
}
Note that only PNG format can support 16-bit per channel per pixel depth. JPEG format does not support this feature.
Class Weighting Config#
YOLOV4 supports class-level weighting on the loss function during training. The following is an example of
the class weighting configuration (class_weighting_config) to set weights for two classes.
class_weighting_config {
class_weighting{
key: "person"
value: 1.0
}
class_weighting{
key: "bus"
value: 5.0
}
}
The parameters in class_weighting_config are defined as follows:
class_weighting: This parameter maps the class name to the corresponding class weight on the loss function. The class weightvalueshould be greater than 0. If a class weight is not explicitly set in the config, a default value of1.0will be assigned implicitly.enable_auto: This parameter indicates that if the automatic class weighting is enabled in the training. Set it to betrueto automatically generate classes weights based on the training loss of each class.
YOLO4 Config#
The YOLOv4 configuration (yolov4_config) defines the parameters needed for building the
YOLOv4 model. Details are summarized in the table below.
Field |
Description |
Data Type and Constraints |
Recommended/Typical Value |
big_anchor_shape, mid_anchor_shape, and small_anchor_shape |
These settings should be 1-d arrays inside quotation marks. The elements of those arrays are tuples representing the pre-defined anchor shape in the order of “width, height”. The default YOLOv4 configuration has nine predefined anchor shapes. They are divided into three groups
corresponding to big, medium, and small objects. The detection output corresponding to
different groups are from different depths in the network. You should run the |
string |
Use the tao model yolo_v4 kmeans command to those shapes |
box_matching_iou |
This field should be a float number between 0 and 1. Any anchor with at least this IoU to any ground truth boxes will be matched to the ground truth box it has the largest IoU with. In contrast with YOLOv3, one ground truth box might match to multiple anchors in YOLOv4. |
float |
0.5 |
matching_neutral_box_iou |
This field should be a float number between 0.25 and 1. Any inferred bounding box with at least this IoU to any ground truth boxes will not be treated as negative box and will be assigned 0 for its negative objectiveness loss (neutral box) |
float |
0.5 |
loss_loc_weight, loss_neg_obj_weights, and loss_class_weights |
These loss weights can be configured as float numbers. The YOLOv4 loss is a summation of localization loss, negative objectiveness loss, positive objectiveness loss, and classification loss. The weight of positive objectiveness loss is set to 1, while the weights of other losses are read from the config file. |
float |
loss_loc_weight: 5.0 loss_neg_obj_weights: 50.0 loss_class_weights: 1.0 |
label_smoothing |
Label smoothing applied to classification loss. |
float of [0, 0.3] |
0, 0.1, 0.2 |
big_grid_xy_extend, mid_grid_xy_extend, and small_grid_xy_extend |
These settings should be small positive floats. The calculated box center relative to the anchor box will be re-calibrated according to following: center_xy = calculated_xy * (grid_xy_extend + 1.0) - grid_xy_extend / 2.0 The default YOLOv4 has nine predefined anchor shapes. They are divided into three groups corresponding to big, medium, and small objects. The detection output corresponding to different groups are from different depths in the network. The three different grid_xy_extend configs allow users to define different grid_xy_extend values for different anchor-shape groups. The grid_xy_extend settings make it easier for the network to propose an inferenced box with a center that is close to or on the anchor border. |
float of [0, 0.3] |
0.05, 0.1, 0.2 |
arch |
The backbone for feature extraction. Currently, “resnet”, “vgg”, “darknet”, “googlenet”, “mobilenet_v1”, “mobilenet_v2”, “cspdarknet”, and “squeezenet” are supported. |
string |
resnet |
activation |
The activation type used in YOLOv4 CSPDarkNet backbone. Only “relu”, “leaky_relu” and “mish” are supported. For other backbones, this parameter is not useful. |
string |
“leaky_relu” |
nlayers |
The number of conv layers in a specific architecture. For “resnet”, 10, 18, 34, 50 and 101 are supported. For “vgg”, 16 and 19 are supported. For “darknet” or “cspdarknet”, 19 and 53 are supported. All other networks don’t have this configuration, in which case you should just delete this config from the config file. |
Unsigned int |
– |
freeze_bn |
A flag specifying whether to freeze all batch normalization layers during training. |
Boolean |
False |
freeze_blocks |
The list of block IDs to be frozen in the model during training. You can choose to freeze some of the CNN blocks in the model to make the training more stable and/or easier to converge. The definition of a block is heuristic for a specific architecture (for example, by stride or by logical blocks in the model). However, the block ID numbers identify the blocks in the model in a sequential order so you don’t have to know the exact locations of the blocks when you do training. A general principle to keep in mind is that the smaller the block ID, the closer it is to the model input; the larger the block ID, the closer it is to the model output. You can divide the whole model into several blocks and optionally freeze a subset of it. Note that for FasterRCNN, you can only freeze the blocks that are before the ROI pooling layer. Any layer after the ROI pooling layer will not be frozen anyway. For different backbones, the number of blocks and the block ID for each block are different. It deserves some detailed explanations on how to specify the block IDs for each backbone. |
list(repeated integers)
|
– |
force_relu |
A flag specifying whether to replace all activation functions with ReLU. This is useful for training models for NVDLA. |
Boolean |
False |
Generate anchor shape#
The anchor shape should match most ground truth boxes in the dataset to help the network learn
bounding boxes. The YOLOv4 paper proposes using the kmeans algorithm to get the anchor shapes.
Use the output as your anchor shape in the yolov4_config specification file.
Training the Model#
Input Requirement#
Input size: C * W * H (where C = 1 or 3, W >= 128, H >= 128, W, H are multiples of 32)
Image format: JPG, JPEG, PNG
Label format: KITTI detection
Evaluating the Model#
Evaluation runs against the validation set specified in the training specification file.
Running Inference on a YOLOv4 Model#
The inference tool for YOLOv4 networks may be used to visualize bboxes or generate frame-by-frame KITTI format labels on a single image or a directory of images.
Pruning the Model#
Pruning removes parameters from the model to reduce the model size without compromising the integrity of the model itself.
After pruning, the model needs to be retrained. See Re-training the Pruned Model for more details.
Re-training the Pruned Model#
Once the model has been pruned, there might be a slight decrease in accuracy because some
previously useful weights may have been removed. To regain accuracy,
we recommend retraining the pruned model over the same dataset,
with an updated specification file that points to the newly pruned model as the pruned_model_path.
We recommend turning off the regularizer in the training_config for detectnet to recover
the accuracy when retraining a pruned model. You may do this by setting the regularizer type
to NO_REG as mentioned in the Training Config section. All
other parameters in the specification file can be carried over from the previous training.
Exporting the Model#
Exporting the model decouples the training process from inference and allows conversion to
TensorRT engines outside the TAO environment. TensorRT engines are specific to each hardware
configuration and should be generated for each unique inference environment.
The exported model may be used universally across training and deployment hardware.
The exported model format is referred to as .etlt. Like .tlt, the .etlt model
format is also an encrypted model format with the same key of the .tlt model that it is
exported from. This key is required when deploying this model.
INT8 Mode Overview#
TensorRT engines can be generated in INT8 mode to improve performance, but require a calibration
cache at engine creation-time. If tao model yolo_v4 export is run with the --data_type
flag set to int8, the calibration cache is generated using a calibration tensor file.
Pre-generating the calibration information and caching it removes the need for calibrating the
model on the inference machine. Moving the calibration cache is usually much more convenient than
moving the calibration tensorfile since it is a much smaller file and can be moved with the
exported model. Using the calibration cache also speeds up engine creation, as building the
cache can take several minutes depending on the size of the Tensorfile and the model itself.
The export tool can generate an INT8 calibration cache by ingesting training data using either of these options:
Option 1: Using the training data loader to load the training images for INT8 calibration. This option is now the recommended approach to support multiple image directories by leveraging the training dataset loader. This also ensures two important aspects of data during calibration:
Data pre-processing in the INT8 calibration step is the same as in the training process.
The data batches are sampled randomly across the entire training dataset, thereby improving the accuracy of the INT8 model.
Option 2: Pointing the tool to a directory of images that you want to use to calibrate the model. For this option, make sure to create a sub-sampled directory of random images that best represent your training dataset.
FP16/FP32 Model#
The calibration.bin is only required if you need to run inference at INT8 precision. For
FP16/FP32 based inference, the export step is much simpler. All that is required is to provide
a .tlt model from the training/retraining step to be converted into .etlt.
QAT Export#
Note
When exporting a model trained with QAT enabled, the tensor scale factors to calibrate the activations are peeled out of the model and serialized to a JSON file.
Deploying to DeepStream#
For deploying to deep stream, please refer to Deploying to DeepStream for YOLOv4.