How to generate calib file for yolo_v4

How to generate the calibration file needed, for exporting int8 model trained with yolov4 model.

# Uncomment to export in INT8 mode (generate calibration cache file). 
!tao yolo_v4 export -m $USER_EXPERIMENT_DIR/experiment_dir_retrain/weights/yolov4_resnet18_epoch_80.tlt  \
                     -o $USER_EXPERIMENT_DIR/export/yolov4_resnet18_epoch_int8_80.etlt \
                     -e $SPECS_DIR/yolo_v4_retrain_resnet18_kitti.txt \
                     -k $KEY \
                     --cal_image_dir  $USER_EXPERIMENT_DIR/data/testing/image_2 \
                     --data_type int8 \
                     --batch_size 16 \
                     --batches 10 \
                     --cal_cache_file $USER_EXPERIMENT_DIR/export/cal.bin  \
                     --cal_data_file $USER_EXPERIMENT_DIR/export/cal.tensorfile

Do you mean cal.tensorfile and cal.bin? You can have it in your $USER_EXPERIMENT_DIR/export after executing the above command, but the pre-condition is to train your model successfully to have yolov4_resnet18_epoch_80.tlt.

I have this error, but I have the models, i see them in terminal, also I export in fp32, and it works.

WARNING:tensorflow:Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them.
/usr/local/lib/python3.6/dist-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.5) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
Traceback (most recent call last):
  File "/root/.cache/bazel/_bazel_root/ed34e6d125608f91724fda23656f1726/execroot/ai_infra/bazel-out/k8-fastbuild/bin/magnet/packages/iva/build_wheel.runfiles/ai_infra/iva/yolo_v4/scripts/export.py", line 12, in <module>
  File "/root/.cache/bazel/_bazel_root/ed34e6d125608f91724fda23656f1726/execroot/ai_infra/bazel-out/k8-fastbuild/bin/magnet/packages/iva/build_wheel.runfiles/ai_infra/iva/common/export/app.py", line 268, in launch_export
  File "/root/.cache/bazel/_bazel_root/ed34e6d125608f91724fda23656f1726/execroot/ai_infra/bazel-out/k8-fastbuild/bin/magnet/packages/iva/build_wheel.runfiles/ai_infra/iva/common/export/app.py", line 232, in run_export
  File "/root/.cache/bazel/_bazel_root/ed34e6d125608f91724fda23656f1726/execroot/ai_infra/bazel-out/k8-fastbuild/bin/magnet/packages/iva/build_wheel.runfiles/ai_infra/iva/common/export/keras_exporter.py", line 93, in set_keras_backend_dtype
  File "/root/.cache/bazel/_bazel_root/ed34e6d125608f91724fda23656f1726/execroot/ai_infra/bazel-out/k8-fastbuild/bin/magnet/packages/iva/build_wheel.runfiles/ai_infra/iva/common/utils.py", line 385, in get_decoded_filename
ValueError: Cannot find input file name.
2022-09-19 13:34:23,138 [INFO] tlt.components.docker_handler.docker_handler: Stopping container.

this worked,

!tao yolo_v4 export -m $USER_EXPERIMENT_DIR/experiment_dir_retrain/weights/yolov4_resnet18_epoch_080.tlt \
                    -k $KEY \
                    -o $USER_EXPERIMENT_DIR/export/yolov4_resnet18_fp16_epoch_080_V1.etlt \
                    -e $SPECS_DIR/yolo_v4_retrain_resnet18_kitti.txt \
                    --batch_size 16 \
                    --data_type fp16

Please make sure your $USER_EXPERIMENT_DIR/experiment_dir_retrain/weights/yolov4_resnet18_epoch_80.tlt is available.

You can use below to check.

!tao yolo_v4 run ls $USER_EXPERIMENT_DIR/experiment_dir_retrain/weights/yolov4_resnet18_epoch_80.tlt

Yes, it works… I said, that exporting with data-type f32 it works…


2022-09-20 13:16:28,165 [INFO] root: Registry: ['nvcr.io']
2022-09-20 13:16:31,697 [INFO] tlt.components.instance_handler.local_instance: Running command in container: nvcr.io/nvidia/tao/tao-toolkit-tf:v3.22.05-tf1.15.5-py3
2022-09-20 13:16:31,724 [WARNING] tlt.components.docker_handler.docker_handler: 
Docker will run the commands as root. If you would like to retain your
local host permissions, please add the "user":"UID:GID" in the
DockerOptions portion of the "/root/.tao_mounts.json" file. You can obtain your
users UID and GID by using the "id -u" and "id -g" commands on the
terminal.
yolov4_resnet18_epoch_010.tlt  yolov4_resnet18_epoch_050.tlt
yolov4_resnet18_epoch_020.tlt  yolov4_resnet18_epoch_060.tlt
yolov4_resnet18_epoch_030.tlt  yolov4_resnet18_epoch_070.tlt
yolov4_resnet18_epoch_040.tlt  yolov4_resnet18_epoch_080.tlt
2022-09-20 13:16:37,493 [INFO] tlt.components.docker_handler.docker_handler: Stopping container.

It needs a calib file, where to generate? In clasification notebook, there is a separate function to generate calibration files

For yolov4, it is different from classification.
When you run export, the etlt file, cal.bin and cal.tensorfile are the output files.
The calibration file is generated when you run export command.

I showed you it throws an error, would you help me?
The model is there, when I export fp32 and fp16 it works, when I try int8 …it throws the error above, that I already posted

ValueError: Cannot find input file name.

I said, this from the beggining, you’re not helping me:)) yet:))

This ValueError means the the input file does not exist.
As mentioned above, please check if it is available.
!tao yolo_v4 run ls $USER_EXPERIMENT_DIR/experiment_dir_retrain/weights/yolov4_resnet18_epoch_80.tlt

If you still see the error, please share the full command and full log again.

@Morganh I already shared the output of the command you sugest…hereeee, did you read it? The input files are thereee, also the export workss, but only for fp16 fp32

OK, but it does not make sense to get above error when you can run fp16/fp32 well but not int8.
Can you run again? Thanks.