Nvidia Tao 3 Yolov4 export in int8

Hi in the hekp you say there are 2 options to calibrate:

Blockquote
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.

I am interested in option 1. Thus my questions are:
1)how do I use the training data loader to load the training images for INT8 calibration?
Is it just changing the path in the -cal_image_dir from one to another?
2) are the arguments of batch size and batches also relevant in the Option 1:?
3)I tried to use also Option2 and pointed with the -cal_image_dir into some directory where there are 78 images and --batch_size 1 \ and --batches 10
And when tried to run this I have got some error message
“not enough images provided 78 <160”
Where did the160 come from and what does this message mean?

No, your mentioned is for option2. For option1, you can just use your spec file to run command. No specific folder is needed.

They are related to option2.

Could you share the full command and full log? Thanks.

Hi, to clarify smthg regarding what you have answered me in opt1:
you say:

Blockquote For option1, you can just use your spec file to run command. No specific folder is needed.

Here is the command in jupyter I use:

The question is:

  1. Inside the the specs file (retrain specs file) I have a links to docker folders for trainig and validation, and those are enough for succesful exporting in int8, and NO specific changes or additions are needed. Right?
  2. what are numbers 585->271 mean?
  3. same regarding the 10/10 ? (note: we have 8 datasets used in training)
    image
  1. Yes.
  2. The ONNX operator numbers decreased during the optimization.
  3. What do you mean by 10/10?

Hey
Thanks for the answer, but though you say that we did everything fine in op1(without pointing to the library with the calibration images)
we get very strange results comparing to the fp16:
please see the attached image:

*I apologize for the images are black since the images are our client’s property

Please help us find a solution.

Can you share the export command?

Sure, here it is:

From the log, it is running for 10 batches. What is the batch-size in your spec file? I am afraid the images are not enough for calibration.

Suggest you to follow option2 to add cal_image_dir to run calibration. A simple way is pointing cal_image_dir to all the training images.

For now let us see the op 1. We have a big training dataset with 8 directories that include more than 2000 images. And to say the truth I have no I idea where does it get the batches =10
Please see the attached specs file we use for retrain and also we point ti while exporting in int8 (as you could see in a command in my previous reply)

random_seed: 42
yolov4_config {
big_anchor_shape: “[(228.26, 118.00),(301.58, 111.00), (277.13, 137.00)]”
mid_anchor_shape: “[(193.58, 98.00),(184.38, 125.17),(258.79, 92.00)]”
small_anchor_shape: “[(74.38, 72.00),(196.64, 59.00), (136.53, 94.00)]”
box_matching_iou: 0.25
matching_neutral_box_iou: 0.5
arch: “resnet”
nlayers: 18
arch_conv_blocks: 2
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 {
visualizer {
enabled: True
num_images: 3
}
batch_size_per_gpu: 1
num_epochs: 100
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: NO_REG
weight: 3e-9
}
optimizer {
adam {
epsilon: 1e-7
beta1: 0.9
beta2: 0.999
amsgrad: false
}
}
pruned_model_path: “/workspace/tao-experiments/yolo_v4/experiment_dir_pruned/yolov4_resnet18_pruned.tlt”
model_ema: true
}
eval_config {
average_precision_mode: SAMPLE
batch_size: 2
matching_iou_threshold: 0.5
}
nms_config {
confidence_threshold: 0.001
clustering_iou_threshold: 0.5
top_k: 200
force_on_cpu: true
}
augmentation_config {
#hue: 0.1
hue: 0.2
saturation: 1.9
exposure:1.9
vertical_flip:0
horizontal_flip: 0.5
jitter: 0.3
output_width: 864
output_height: 480
output_channel: 3
randomize_input_shape_period: 0
mosaic_prob: 0.5
mosaic_min_ratio:0.2
}
dataset_config {
data_sources: {
label_directory_path: “/workspace/tao-experiments/data/dataset1/training/label_2”
image_directory_path: “/workspace/tao-experiments/data/dataset1/training/image_2”
}
data_sources: {
label_directory_path: “/workspace/tao-experiments/data/dataset2/training/label_2”
image_directory_path: “/workspace/tao-experiments/data/dataset2/training/image_2”
}
data_sources: {
label_directory_path: “/workspace/tao-experiments/data/dataset3/training/label_2”
image_directory_path: “/workspace/tao-experiments/data/dataset3/training/image_2”
}
data_sources: {
label_directory_path: “/workspace/tao-experiments/data/dataset4/training/label_2”
image_directory_path: “/workspace/tao-experiments/data/dataset4/training/image_2”
}
data_sources: {
label_directory_path: “/workspace/tao-experiments/data/dataset5/training/label_2”
image_directory_path: “/workspace/tao-experiments/data/dataset5/training/image_2”
}
data_sources: {
label_directory_path: “/workspace/tao-experiments/data/dataset6/training/label_2”
image_directory_path: “/workspace/tao-experiments/data/dataset6/training/image_2”
}
data_sources: {
label_directory_path: “/workspace/tao-experiments/data/dataset7/training/label_2”
image_directory_path: “/workspace/tao-experiments/data/dataset7/training/image_2”
}
data_sources: {
label_directory_path: “/workspace/tao-experiments/data/dataset8/training/label_2”
image_directory_path: “/workspace/tao-experiments/data/dataset8/training/image_2”
}
include_difficult_in_training: true
image_extension: “png”
target_class_mapping {
key: “cluster”
value: “cluster”
}
validation_data_sources: [
{
label_directory_path: “/workspace/tao-experiments/data/dataset1/val/label”
image_directory_path: “/workspace/tao-experiments/data/dataset1/val/image”
},
{
label_directory_path: “/workspace/tao-experiments/data/dataset2/val/label”
image_directory_path: “/workspace/tao-experiments/data/dataset2/val/image”
},
{
label_directory_path: “/workspace/tao-experiments/data/dataset3/val/label”
image_directory_path: “/workspace/tao-experiments/data/dataset3/val/image”
},
{
label_directory_path: “/workspace/tao-experiments/data/dataset4/val/label”
image_directory_path: “/workspace/tao-experiments/data/dataset4/val/image”
},
{
label_directory_path: “/workspace/tao-experiments/data/dataset5/val/label”
image_directory_path: “/workspace/tao-experiments/data/dataset5/val/image”
},
{
label_directory_path: “/workspace/tao-experiments/data/dataset6/val/label”
image_directory_path: “/workspace/tao-experiments/data/dataset6/val/image”
},
{
label_directory_path: “/workspace/tao-experiments/data/dataset7/val/label”
image_directory_path: “/workspace/tao-experiments/data/dataset7/val/image”
},
{
label_directory_path: “/workspace/tao-experiments/data/dataset8/val/label”
image_directory_path: “/workspace/tao-experiments/data/dataset8/val/image”
}
]
}

That is the default value.
Assume you have totally 2000 images, can you add below in the command line?

--batch_size 1 \
--batches 2000 \
...

Thank you we will try
please dont close this topic yeat