Error Code 1: Serialization (Serialization assertion stdVersionRead == kSERIALIZATION_VERSION failed.Version tag does not match

dGPU
DS 7

I have trained ocrnet using the latest ocrnet/ocrnet-vit.ipynb notebook. Was trying to use resulting trt.engine in an inference outside the docker container.

Getting this:

06/08/2024-10:15:23] [TRT] [E] 1: [stdArchiveReader.cpp::stdArchiveReaderInitCommon::47] Error Code 1: Serialization (Serialization assertion stdVersionRead == kSERIALIZATION_VERSION failed.Version tag does not match. Note: Current Version: 237, Serialized Engine Version: 236)

More specifically: I’m running /tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts/inference.py

Question: What versions do no match and what to do with this?

Please check the TensorRT version inside the docker. If you generate a tensorrt engine inside the docker, and want to use it directly outside the docker, the TensorRT version outside should be the same.
Suggest you to use trtexec to generate tensorrt engine again if you run inference outside the docker.

You are really a helpful mind here. Thanks. Will check that out. Have a nice weekend

But it didn’t help somehow. Is it the onnx file? This has been produced by docker.

Conversion

/usr/src/tensorrt/bin/trtexec  --onnx=/home/ubuntu/tao-experiments/ocrnet/export/best_accuracy.onnx --saveEngine=/home/ubuntu/tao-experiments/ocrnet/export/trt.engine --fp16 --verbose --workspace=4096

Runtime:

engine-path /home/ubuntu/tao-experiments/ocrnet/export/trt.engine
[06/08/2024-19:38:20] [TRT] [E] 1: [stdArchiveReader.cpp::stdArchiveReaderInitCommon::47] Error Code 1: Serialization (Serialization assertion stdVersionRead == kSERIALIZATION_VERSION failed.Version tag does not match. Note: Current Version: 237, Serialized Engine Version: 236)

The “engine-path” trace has been added by me, so it is the right file which is attempted to be loaded.

Maybe next week.

TensorRT version is the same, inside and outside the Docker

8.6.1.6-1+cuda12.0

@Morganh Would you have another suggestion how to solve this?

Suggest you to double check inside docker and outside the docker.

  1. Inside the docker,
    $ dpkg -l |grep cuda
    More, can the inference run successfully? What is the command line and log?

  2. outside the docker,
    $ dpkg -l |grep cuda
    More, can the inference run successfully? What is the command line(or script?) and log?

Inside docker

ubuntu@aiqa:~$ docker run --rm -it --entrypoint bash 28ef22908199
root@2e8530b8c748:/opt/nvidia/tools# dpkg -l |grep cuda
ii  cuda-cccl-12-3                         12.3.101-1                                  amd64        CUDA CCCL
ii  cuda-compat-12-3                       545.23.08-1                                 amd64        CUDA Compatibility Platform
ii  cuda-crt-12-3                          12.3.107-1                                  amd64        CUDA crt
ii  cuda-cudart-12-3                       12.3.101-1                                  amd64        CUDA Runtime native Libraries
ii  cuda-cudart-dev-12-3                   12.3.101-1                                  amd64        CUDA Runtime native dev links, headers
ii  cuda-cuobjdump-12-3                    12.3.101-1                                  amd64        CUDA cuobjdump
ii  cuda-cupti-12-3                        12.3.101-1                                  amd64        CUDA profiling tools runtime libs.
ii  cuda-cupti-dev-12-3                    12.3.101-1                                  amd64        CUDA profiling tools interface.
ii  cuda-driver-dev-12-3                   12.3.101-1                                  amd64        CUDA Driver native dev stub library
ii  cuda-gdb-12-3                          12.3.101-1                                  amd64        CUDA-GDB
ii  cuda-nvcc-12-3                         12.3.107-1                                  amd64        CUDA nvcc
ii  cuda-nvdisasm-12-3                     12.3.101-1                                  amd64        CUDA disassembler
ii  cuda-nvml-dev-12-3                     12.3.101-1                                  amd64        NVML native dev links, headers
ii  cuda-nvprof-12-3                       12.3.101-1                                  amd64        CUDA Profiler tools
ii  cuda-nvprune-12-3                      12.3.101-1                                  amd64        CUDA nvprune
ii  cuda-nvrtc-12-3                        12.3.107-1                                  amd64        NVRTC native runtime libraries
ii  cuda-nvrtc-dev-12-3                    12.3.107-1                                  amd64        NVRTC native dev links, headers
ii  cuda-nvtx-12-3                         12.3.101-1                                  amd64        NVIDIA Tools Extension
ii  cuda-nvvm-12-3                         12.3.107-1                                  amd64        CUDA nvvm
ii  cuda-profiler-api-12-3                 12.3.101-1                                  amd64        CUDA Profiler API
ii  cuda-sanitizer-12-3                    12.3.101-1                                  amd64        CUDA Sanitizer
ii  cuda-toolkit-12-3-config-common        12.3.101-1                                  all          Common config package for CUDA Toolkit 12.3.
ii  cuda-toolkit-12-config-common          12.3.101-1                                  all          Common config package for CUDA Toolkit 12.
ii  cuda-toolkit-config-common             12.3.101-1                                  all          Common config package for CUDA Toolkit.
ii  libcudnn8                              8.9.7.29-1+cuda12.2                         amd64        cuDNN runtime libraries
ii  libcudnn8-dev                          8.9.7.29-1+cuda12.2                         amd64        cuDNN development libraries and headers
ii  libnccl-dev                            2.19.3-1+cuda12.3                           amd64        NVIDIA Collective Communication Library (NCCL) Development Files
ii  libnccl2                               2.19.3-1+cuda12.3                           amd64        NVIDIA Collective Communication Library (NCCL) Runtime
ii  libnvinfer-bin                         8.6.1.6-1+cuda12.0                          amd64        TensorRT binaries
ii  libnvinfer-dev                         8.6.1.6-1+cuda12.0                          amd64        TensorRT development libraries
ii  libnvinfer-dispatch-dev                8.6.1.6-1+cuda12.0                          amd64        TensorRT development dispatch runtime libraries
ii  libnvinfer-dispatch8                   8.6.1.6-1+cuda12.0                          amd64        TensorRT dispatch runtime library
ii  libnvinfer-headers-dev                 8.6.1.6-1+cuda12.0                          amd64        TensorRT development headers
ii  libnvinfer-headers-plugin-dev          8.6.1.6-1+cuda12.0                          amd64        TensorRT plugin headers
ii  libnvinfer-lean-dev                    8.6.1.6-1+cuda12.0                          amd64        TensorRT lean runtime libraries
ii  libnvinfer-lean8                       8.6.1.6-1+cuda12.0                          amd64        TensorRT lean runtime library
ii  libnvinfer-plugin-dev                  8.6.1.6-1+cuda12.0                          amd64        TensorRT plugin libraries
ii  libnvinfer-plugin8                     8.6.1.6-1+cuda12.0                          amd64        TensorRT plugin libraries
ii  libnvinfer-vc-plugin-dev               8.6.1.6-1+cuda12.0                          amd64        TensorRT vc-plugin library
ii  libnvinfer-vc-plugin8                  8.6.1.6-1+cuda12.0                          amd64        TensorRT vc-plugin library
ii  libnvinfer8                            8.6.1.6-1+cuda12.0                          amd64        TensorRT runtime libraries
ii  libnvonnxparsers-dev                   8.6.1.6-1+cuda12.0                          amd64        TensorRT ONNX libraries
ii  libnvonnxparsers8                      8.6.1.6-1+cuda12.0                          amd64        TensorRT ONNX libraries
ii  libnvparsers-dev                       8.6.1.6-1+cuda12.0                          amd64        TensorRT parsers libraries
ii  libnvparsers8                          8.6.1.6-1+cuda12.0                          amd64        TensorRT parsers libraries
ii  tensorrt-dev                           8.6.1.6-1+cuda12.0                          amd64        Meta package for TensorRT development libraries
root@2e8530b8c748:/opt/nvidia/tools# 

Outside docker:

ubuntu@aiqa:~$ dpkg -l |grep cuda
ii  cuda-cccl-12-1                         12.1.109-1                                  amd64        CUDA CCCL
ii  cuda-cccl-12-2                         12.2.140-1                                  amd64        CUDA CCCL
ii  cuda-command-line-tools-12-2           12.2.2-1                                    amd64        CUDA command-line tools
ii  cuda-compiler-12-2                     12.2.2-1                                    amd64        CUDA compiler
ii  cuda-crt-12-2                          12.2.140-1                                  amd64        CUDA crt
ii  cuda-cudart-12-1                       12.1.105-1                                  amd64        CUDA Runtime native Libraries
ii  cuda-cudart-12-2                       12.2.140-1                                  amd64        CUDA Runtime native Libraries
ii  cuda-cudart-dev-12-1                   12.1.105-1                                  amd64        CUDA Runtime native dev links, headers
ii  cuda-cudart-dev-12-2                   12.2.140-1                                  amd64        CUDA Runtime native dev links, headers
ii  cuda-cuobjdump-12-2                    12.2.140-1                                  amd64        CUDA cuobjdump
ii  cuda-cupti-12-2                        12.2.142-1                                  amd64        CUDA profiling tools runtime libs.
ii  cuda-cupti-dev-12-2                    12.2.142-1                                  amd64        CUDA profiling tools interface.
ii  cuda-cuxxfilt-12-2                     12.2.140-1                                  amd64        CUDA cuxxfilt
ii  cuda-documentation-12-2                12.2.140-1                                  amd64        CUDA documentation
ii  cuda-driver-dev-12-1                   12.1.105-1                                  amd64        CUDA Driver native dev stub library
ii  cuda-driver-dev-12-2                   12.2.140-1                                  amd64        CUDA Driver native dev stub library
ii  cuda-gdb-12-2                          12.2.140-1                                  amd64        CUDA-GDB
ii  cuda-libraries-12-2                    12.2.2-1                                    amd64        CUDA Libraries 12.2 meta-package
ii  cuda-libraries-dev-12-2                12.2.2-1                                    amd64        CUDA Libraries 12.2 development meta-package
ii  cuda-nsight-12-2                       12.2.144-1                                  amd64        CUDA nsight
ii  cuda-nsight-compute-12-2               12.2.2-1                                    amd64        NVIDIA Nsight Compute
ii  cuda-nsight-systems-12-2               12.2.2-1                                    amd64        NVIDIA Nsight Systems
ii  cuda-nvcc-12-1                         12.1.105-1                                  amd64        CUDA nvcc
ii  cuda-nvcc-12-2                         12.2.140-1                                  amd64        CUDA nvcc
ii  cuda-nvdisasm-12-2                     12.2.140-1                                  amd64        CUDA disassembler
ii  cuda-nvml-dev-12-2                     12.2.140-1                                  amd64        NVML native dev links, headers
ii  cuda-nvprof-12-2                       12.2.142-1                                  amd64        CUDA Profiler tools
ii  cuda-nvprune-12-2                      12.2.140-1                                  amd64        CUDA nvprune
ii  cuda-nvrtc-12-2                        12.2.140-1                                  amd64        NVRTC native runtime libraries
ii  cuda-nvrtc-dev-12-2                    12.2.140-1                                  amd64        NVRTC native dev links, headers
ii  cuda-nvtx-12-2                         12.2.140-1                                  amd64        NVIDIA Tools Extension
ii  cuda-nvvm-12-2                         12.2.140-1                                  amd64        CUDA nvvm
ii  cuda-nvvp-12-2                         12.2.142-1                                  amd64        CUDA Profiler tools
ii  cuda-opencl-12-2                       12.2.140-1                                  amd64        CUDA OpenCL native Libraries
ii  cuda-opencl-dev-12-2                   12.2.140-1                                  amd64        CUDA OpenCL native dev links, headers
ii  cuda-profiler-api-12-2                 12.2.140-1                                  amd64        CUDA Profiler API
ii  cuda-sanitizer-12-2                    12.2.140-1                                  amd64        CUDA Sanitizer
ii  cuda-toolkit-12-1-config-common        12.1.105-1                                  all          Common config package for CUDA Toolkit 12.1.
ii  cuda-toolkit-12-2                      12.2.2-1                                    amd64        CUDA Toolkit 12.2 meta-package
ii  cuda-toolkit-12-2-config-common        12.2.140-1                                  all          Common config package for CUDA Toolkit 12.2.
ii  cuda-toolkit-12-config-common          12.5.39-1                                   all          Common config package for CUDA Toolkit 12.
ii  cuda-toolkit-config-common             12.5.39-1                                   all          Common config package for CUDA Toolkit.
ii  cuda-tools-12-2                        12.2.2-1                                    amd64        CUDA Tools meta-package
ii  cuda-visual-tools-12-2                 12.2.2-1                                    amd64        CUDA visual tools
ii  graphsurgeon-tf                        8.6.1.6-1+cuda12.0                          amd64        GraphSurgeon for TensorRT package
ii  libcudart11.0:amd64                    11.5.117~11.5.1-1ubuntu1                    amd64        NVIDIA CUDA Runtime Library
ii  libcudnn8                              8.9.7.29-1+cuda12.2                         amd64        cuDNN runtime libraries
ii  libcudnn8-dev                          8.9.7.29-1+cuda12.2                         amd64        cuDNN development libraries and headers
ii  libnvinfer-bin                         8.6.1.6-1+cuda12.0                          amd64        TensorRT binaries
ii  libnvinfer-dev                         8.6.1.6-1+cuda12.0                          amd64        TensorRT development libraries
ii  libnvinfer-dispatch-dev                8.6.1.6-1+cuda12.0                          amd64        TensorRT development dispatch runtime libraries
ii  libnvinfer-dispatch8                   8.6.1.6-1+cuda12.0                          amd64        TensorRT dispatch runtime library
ii  libnvinfer-headers-dev                 8.6.1.6-1+cuda12.0                          amd64        TensorRT development headers
ii  libnvinfer-headers-plugin-dev          8.6.1.6-1+cuda12.0                          amd64        TensorRT plugin headers
ii  libnvinfer-lean-dev                    8.6.1.6-1+cuda12.0                          amd64        TensorRT lean runtime libraries
ii  libnvinfer-lean8                       8.6.1.6-1+cuda12.0                          amd64        TensorRT lean runtime library
ii  libnvinfer-plugin-dev                  8.6.1.6-1+cuda12.0                          amd64        TensorRT plugin libraries
ii  libnvinfer-plugin8                     8.6.1.6-1+cuda12.0                          amd64        TensorRT plugin libraries
ii  libnvinfer-samples                     8.6.1.6-1+cuda12.0                          all          TensorRT samples
ii  libnvinfer-vc-plugin-dev               8.6.1.6-1+cuda12.0                          amd64        TensorRT vc-plugin library
ii  libnvinfer-vc-plugin8                  8.6.1.6-1+cuda12.0                          amd64        TensorRT vc-plugin library
ii  libnvinfer8                            8.6.1.6-1+cuda12.0                          amd64        TensorRT runtime libraries
ii  libnvonnxparsers-dev                   8.6.1.6-1+cuda12.0                          amd64        TensorRT ONNX libraries
ii  libnvonnxparsers8                      8.6.1.6-1+cuda12.0                          amd64        TensorRT ONNX libraries
ii  libnvparsers-dev                       8.6.1.6-1+cuda12.0                          amd64        TensorRT parsers libraries
ii  libnvparsers8                          8.6.1.6-1+cuda12.0                          amd64        TensorRT parsers libraries
ii  nvidia-cuda-dev:amd64                  11.5.1-1ubuntu1                             amd64        NVIDIA CUDA development files
ii  nvidia-cuda-gdb                        11.5.114~11.5.1-1ubuntu1                    amd64        NVIDIA CUDA Debugger (GDB)
ii  nvidia-cuda-toolkit                    11.5.1-1ubuntu1                             amd64        NVIDIA CUDA development toolkit
ii  nvidia-cuda-toolkit-doc                11.5.1-1ubuntu1                             all          NVIDIA CUDA and OpenCL documentation
ii  onnx-graphsurgeon                      8.6.1.6-1+cuda12.0                          amd64        ONNX GraphSurgeon for TensorRT package
ii  python3-libnvinfer-dispatch            8.6.1.6-1+cuda12.0                          amd64        Python 3 bindings for TensorRT dispatch runtime
ii  python3-libnvinfer-lean                8.6.1.6-1+cuda12.0                          amd64        Python 3 bindings for TensorRT lean runtime
ii  uff-converter-tf                       8.6.1.6-1+cuda12.0                          amd64        UFF converter for TensorRT package
ubuntu@aiqa:~$ 

Yes, I can run inference inside docker. Command is from notebook:

tao model ocrnet inference -e $SPECS_DIR/experiment-vit.yaml \
                  inference.checkpoint=$RESULTS_DIR/experiment_dir_retrain/best_accuracy.pth \
                  inference.inference_dataset_dir=$DATA_DIR/test_samples \
                  inference.results_dir=$RESULTS_DIR/experiment_dir_retrain/ \
                  dataset.character_list_file=$DATA_DIR/character_list

Log:

2024-06-09 18:38:18,909 [TAO Toolkit] [INFO] root 160: Registry: ['nvcr.io']
2024-06-09 18:38:18,973 [TAO Toolkit] [INFO] nvidia_tao_cli.components.instance_handler.local_instance 360: Running command in container: nvcr.io/nvidia/tao/tao-toolkit:5.3.0-pyt
2024-06-09 18:38:18,982 [TAO Toolkit] [WARNING] nvidia_tao_cli.components.docker_handler.docker_handler 290: 
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 "/home/ubuntu/.tao_mounts.json" file. You can obtain your
users UID and GID by using the "id -u" and "id -g" commands on the
terminal.
2024-06-09 18:38:18,982 [TAO Toolkit] [INFO] nvidia_tao_cli.components.docker_handler.docker_handler 303: Printing tty value True
sys:1: UserWarning: 
'experiment-vit.yaml' is validated against ConfigStore schema with the same name.
This behavior is deprecated in Hydra 1.1 and will be removed in Hydra 1.2.
See https://hydra.cc/docs/next/upgrades/1.0_to_1.1/automatic_schema_matching for migration instructions.
/usr/local/lib/python3.10/dist-packages/nvidia_tao_pytorch/core/hydra/hydra_runner.py:107: UserWarning: 
'experiment-vit.yaml' is validated against ConfigStore schema with the same name.
This behavior is deprecated in Hydra 1.1 and will be removed in Hydra 1.2.
See https://hydra.cc/docs/next/upgrades/1.0_to_1.1/automatic_schema_matching for migration instructions.
  _run_hydra(
/usr/local/lib/python3.10/dist-packages/hydra/_internal/hydra.py:119: UserWarning: Future Hydra versions will no longer change working directory at job runtime by default.
See https://hydra.cc/docs/next/upgrades/1.1_to_1.2/changes_to_job_working_dir/ for more information.
  ret = run_job(
/usr/local/lib/python3.10/dist-packages/nvidia_tao_pytorch/core/loggers/api_logging.py:240: UserWarning: Log file already exists at /results/experiment_dir_retrain/status.json
  rank_zero_warn(
Starting OCRNet inference
loading pretrained model from /results/experiment_dir_retrain/best_accuracy.pth
+----------------------------------+--------------------+--------------------+
| image_path                       | predicted_labels   |   confidence score |
|----------------------------------+--------------------+--------------------|
| /data/test_samples/word_1006.png | point              |             0.9961 |
| /data/test_samples/word_1008.png | the                |             0.9993 |
| /data/test_samples/word_1002.png | reatroom           |             0.9332 |
| /data/test_samples/word_1007.png | theatre            |             0.9521 |
| /data/test_samples/word_1009.png | esplanade          |             0.8117 |
| /data/test_samples/word_1003.png | carpark            |             0.7014 |
| /data/test_samples/word_1004.png | passages           |             0.9935 |
| /data/test_samples/word_1001.png | passages           |             0.888  |
| /data/test_samples/word_100.png  | fairprice          |             0.758  |
| /data/test_samples/word_1000.png | meets              |             0.8069 |
| /data/test_samples/word_1005.png | meeding            |             0.971  |
+----------------------------------+--------------------+--------------------+
Execution status: PASS
2024-06-09 18:38:43,790 [TAO Toolkit] [INFO] nvidia_tao_cli.components.docker_handler.docker_handler 365: Stopping container.

I’m trying to run inference.py from tao-deploy project (as you suggested) outside Docker. That fails with the a.m. error

How did you generate tensorrt engine? By using tao deploy gen_trt_engine xxx ,right? If yes, please check the TensonRT version from the deploy docker. Above you shared is from tao pytorch docker.

How did you generate tensorrt engine? By using tao deploy gen_trt_engine xxx ,right?

No. As said earlier:

/usr/src/tensorrt/bin/trtexec  --onnx=/home/ubuntu/tao-experiments/ocrnet/export/best_accuracy.onnx --saveEngine=/home/ubuntu/tao-experiments/ocrnet/export/trt.engine --fp16 --verbose --workspace=4096

Is above running inside a docker?

Is above running inside a docker?

No

Please try to use trtexec to generate engine where you are going to run inference. In short, to ease your work, please run inference in the environment where the engine is generated. Then the TensorRT version should match.

I really don’t understand. Here the entire causal chain again, maybe for your understanding.

  • I need to run inference.py (ffrom the nvidia_tao_deploy) OUTSIDE docker. I need to utilize OCRNet from OpenCV in my project, since the tuple OCDNet/OCRNet is not performant enough to run inference at 30 fps.

  • I was using the ocrnet-vit noteboot, since I need to train the OCRNet. Then I was using the final resulting engine from inference.py outside docker and failed with the error in the caption

  • Your suggestion was to create the engine in the same environment where inference.py is running. So I did and used trtexec to create the engine, but I got the same error again (version mismatch)

  • You asked me to check for the TRT version inside/outside Docker. I see no difference, do you?

Now your suggestion is

Please try to use trtexec to generate engine where you are going to run inference. I

But I’m sure, this is what I did, and the error persists.

What is wrong here?

Your steps look no problem. It is really weird. Can you share your standalone inference.py?
Also, can you share the command line and full log? Thanks.

inference.py is unchanged compared to the current state of nvidia_tao_deploy.

OK, to recap:

  • Using ocrnet-vit notebook (completely UNCHANGED), do a training, create trt.engine and use this engine from inference.py (UNCHANGED) outside Docker → version mismatch

  • Using ocrnet-vit notebook (completely UNCHANGED), do a training, create trt.engine outside docker using trtexec and use this engine from inference.py (UNCHANGED) outside Docker → version mismatch

Two ways, same fail. I maybe could attempt that on another machine again…

For “use this engine from inference.py (UNCHANGED) outside Docker”, can you share the command line and full log?

OK, first I copied the experiments-vit.yaml from the tao-experiments ocrnet-vit notebook spec to ~/tao_deploy/nvidia_tao_deploy/cv/ocrnet/specs and adjusted the paths, since the spec file is meant to be used in a container usually.

Here the current content of ~/tao_deploy/nvidia_tao_deploy/cv/ocrnet/specs/experiments-vit.yaml:

results_dir: /home/ubuntu/tao-experiments/ocrnet/experiment_dir_retrain
encryption_key: nvidia_tao
model:
  TPS: True
  backbone: FAN_tiny_2X
  sequence: BiLSTM
  hidden_size: 256
  prediction: Attn
  quantize: False
  input_width: 200
  input_height: 64
  input_channel: 1
dataset:
  train_dataset_dir: []
  val_dataset_dir: /data/test/lmdb
  character_list_file: "/home/ubuntu/tao-experiments/data/ocrnet/character_list"
  max_label_length: 25
  batch_size: 32
  workers: 4
  augmentation:
    keep_aspect_ratio: False
train:
  seed: 1111
  gpu_ids: [0]
  optim:
    name: "adadelta"
    lr: 0.1
  clip_grad_norm: 5.0
  num_epochs: 10
  checkpoint_interval: 2
  validation_interval: 1
evaluate:
  gpu_id: 0
  checkpoint: "??"
  test_dataset_dir: "??"
  results_dir: "${results_dir}/evaluate"
prune:
  gpu_id: 0
  checkpoint: "??"
  results_dir: "${results_dir}/prune"
  prune_setting:
    mode: "amount"
    amount: 0.1
    granularity: 8
    raw_prune_score: L1
inference:
  gpu_id: 0
  checkpoint: "/home/ubuntu/tao-experiments/ocrnet/experiment_dir_retrain/best_accuracy.pth"
  inference_dataset_dir: "/home/ubuntu/tao-experiments/data/ocrnet/test_samples"
  results_dir: "/home/ubuntu/tao-experiments/ocrnet/experiment_dir_retrain/inference"
  trt_engine: "/home/ubuntu/tao-experiments/ocrnet/export/trt.engine"
  batch_size: 1
  input_width: 200
  input_height: 64
export:
  gpu_id: 0
  checkpoint: "??"
  results_dir: "${results_dir}/export"
dataset_convert:
  input_img_dir: "??"
  gt_file: "??"
  results_dir: "${results_dir}/convert_dataset"
gen_trt_engine:
  onnx_file: "??"
  results_dir: "${results_dir}/convert_dataset"

I only adjusted the properties, which were explicitly touched by the inference.py script in ~/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts.

I made some minimal changes to inference.py, first to be able to resolve the nvidia_tao_deploy imports and then some extra prints for showing the parameters. This is my inference.py now:

# Copyright (c) 2023, NVIDIA CORPORATION.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""OCRNet TensorRT inference."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import logging
import os

import sys
sys.path.append("../../../../")

from nvidia_tao_deploy.cv.common.decorators import monitor_status
from nvidia_tao_deploy.cv.ocrnet.dataloader import OCRNetLoader
from nvidia_tao_deploy.cv.ocrnet.inferencer import OCRNetInferencer
from nvidia_tao_deploy.cv.common.hydra.hydra_runner import hydra_runner
from nvidia_tao_deploy.cv.ocrnet.config.default_config import ExperimentConfig
from nvidia_tao_deploy.cv.ocrnet.utils import decode_ctc, decode_attn

logging.basicConfig(format='%(asctime)s [TAO Toolkit] [%(levelname)s] %(name)s %(lineno)d: %(message)s',
                    level="INFO")
logger = logging.getLogger(__name__)
spec_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

@hydra_runner(
    config_path=os.path.join(spec_root, "specs"),
    config_name="experiment-vit", schema=ExperimentConfig
)
@monitor_status(name="ocrnet", mode="inference")
def main(cfg: ExperimentConfig) -> None:
    """Convert encrypted uff or onnx model to TRT engine."""
    engine_file = cfg.inference.trt_engine
    batch_size = cfg.inference.batch_size
    img_dirs = cfg.inference.inference_dataset_dir
    character_list_file = cfg.dataset.character_list_file
    img_width = cfg.inference.input_width
    img_height = cfg.inference.input_height
    img_channel = cfg.model.input_channel
    prediction_type = cfg.model.prediction
    shape = [img_channel, img_height, img_width]

    print("engine_file", engine_file)
    print("batch_size", batch_size)
    print("img_dirs", img_dirs)
    print("character_list_file", character_list_file)
    print("img_width", img_width)
    print("img_height", img_height)
    print("img_channel", img_channel)
    print("prediction_type", prediction_type)
    print("shape", shape)

    ocrnet_engine = OCRNetInferencer(engine_path=engine_file,
                                     batch_size=batch_size)

    if prediction_type == "CTC":
        character_list = ["CTCBlank"]
    elif prediction_type == "Attn":
        character_list = ["[GO]", "[s]"]
    else:
        raise ValueError(f"Unsupported prediction type: {prediction_type}")
    with open(character_list_file, "r", encoding="utf-8") as f:
        for ch in f.readlines():
            ch = ch.strip()
            character_list.append(ch)

    inf_dl = OCRNetLoader(shape=shape,
                          image_dirs=[img_dirs],
                          batch_size=batch_size,
                          dtype=ocrnet_engine.inputs[0].host.dtype)

    for idx, (imgs, _) in enumerate(inf_dl):
        y_preds = ocrnet_engine.infer(imgs)
        output_probs, output_ids = y_preds
        img_paths = inf_dl.image_paths[idx * batch_size: (idx + 1) * batch_size]
        assert len(output_ids) == len(output_probs) == len(img_paths)
        for img_path, output_id, output_prob in zip(img_paths, output_ids, output_probs):
            if prediction_type == "CTC":
                text, conf = decode_ctc(output_id, output_prob, character_list=character_list)
            else:
                text, conf = decode_attn(output_id, output_prob, character_list=character_list)
            print(f"{img_path}: {text} {conf}")

    logging.info("TensorRT engine inference finished successfully.")

cfg = ExperimentConfig()

if __name__ == '__main__':
    main()

I run it with python3 inference.py in the ~/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts dir. Even though there are some warnings, I can see my configuration. Also, the /home/ubuntu/tao-experiments/ocrnet/export/trt.engine is the one generated outside the Docker using the trtexec command line shown.

The output is:

sys:1: UserWarning: 
'experiment-vit' is validated against ConfigStore schema with the same name.
This behavior is deprecated in Hydra 1.1 and will be removed in Hydra 1.2.
See https://hydra.cc/docs/1.2/upgrades/1.0_to_1.1/automatic_schema_matching for migration instructions.
/home/ubuntu/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts/../../../../nvidia_tao_deploy/cv/common/hydra/hydra_runner.py:99: UserWarning: 
'experiment-vit' is validated against ConfigStore schema with the same name.
This behavior is deprecated in Hydra 1.1 and will be removed in Hydra 1.2.
See https://hydra.cc/docs/1.2/upgrades/1.0_to_1.1/automatic_schema_matching for migration instructions.
  _run_hydra(
/home/ubuntu/.local/lib/python3.10/site-packages/hydra/_internal/hydra.py:119: UserWarning: Future Hydra versions will no longer change working directory at job runtime by default.
See https://hydra.cc/docs/1.2/upgrades/1.1_to_1.2/changes_to_job_working_dir/ for more information.
  ret = run_job(
Log file already exists at /home/ubuntu/tao-experiments/ocrnet/experiment_dir_retrain/status.json
Starting ocrnet inference.
engine_file /home/ubuntu/tao-experiments/ocrnet/export/trt.engine
batch_size 1
img_dirs /home/ubuntu/tao-experiments/data/ocrnet/test_samples
character_list_file /home/ubuntu/tao-experiments/data/ocrnet/character_list
img_width 200
img_height 64
img_channel 1
prediction_type Attn
shape [1, 64, 200]
engine-path /home/ubuntu/tao-experiments/ocrnet/export/trt.engine
[06/11/2024-16:16:43] [TRT] [E] 1: [stdArchiveReader.cpp::stdArchiveReaderInitCommon::47] Error Code 1: Serialization (Serialization assertion stdVersionRead == kSERIALIZATION_VERSION failed.Version tag does not match. Note: Current Version: 237, Serialized Engine Version: 236)
'NoneType' object has no attribute 'create_execution_context'
Error executing job with overrides: []
Traceback (most recent call last):
  File "/home/ubuntu/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts/../../../../nvidia_tao_deploy/cv/common/decorators.py", line 63, in _func
    raise e
  File "/home/ubuntu/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts/../../../../nvidia_tao_deploy/cv/common/decorators.py", line 47, in _func
    runner(cfg, **kwargs)
  File "/home/ubuntu/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts/inference.py", line 70, in main
    ocrnet_engine = OCRNetInferencer(engine_path=engine_file,
  File "/home/ubuntu/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts/../../../../nvidia_tao_deploy/cv/ocrnet/inferencer.py", line 39, in __init__
    super().__init__(engine_path)
  File "/home/ubuntu/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts/../../../../nvidia_tao_deploy/inferencer/trt_inferencer.py", line 50, in __init__
    self.context = self.engine.create_execution_context()
AttributeError: 'NoneType' object has no attribute 'create_execution_context'

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.
Exception ignored in: <function OCRNetInferencer.__del__ at 0x742c8d0c5360>
Traceback (most recent call last):
  File "/home/ubuntu/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts/../../../../nvidia_tao_deploy/cv/ocrnet/inferencer.py", line 115, in __del__
    if self.context:
AttributeError: 'OCRNetInferencer' object has no attribute 'context'

I believe, the main problem is and was this:

[06/11/2024-16:16:43] [TRT] [E] 1: [stdArchiveReader.cpp::stdArchiveReaderInitCommon::47] Error Code 1: Serialization (Serialization assertion stdVersionRead == kSERIALIZATION_VERSION failed.Version tag does not match. Note: Current Version: 237, Serialized Engine Version: 236)

The rest is just follow up errors for now.

OK, found it.

I checked the installed Python tensorrt. While the dpkg package was 8.6.1.6 (as shown), the python package was 10.0.1. I must have accidentally installed that during some tests.

I uninstalled tensorrt 10.0.1 and installed 8.6.1 and tadaa - inference.py can load the engine:

sys:1: UserWarning: 
'experiment-vit' is validated against ConfigStore schema with the same name.
This behavior is deprecated in Hydra 1.1 and will be removed in Hydra 1.2.
See https://hydra.cc/docs/1.2/upgrades/1.0_to_1.1/automatic_schema_matching for migration instructions.
/home/ubuntu/tao_deploy/nvidia_tao_deploy/cv/ocrnet/scripts/../../../../nvidia_tao_deploy/cv/common/hydra/hydra_runner.py:99: UserWarning: 
'experiment-vit' is validated against ConfigStore schema with the same name.
This behavior is deprecated in Hydra 1.1 and will be removed in Hydra 1.2.
See https://hydra.cc/docs/1.2/upgrades/1.0_to_1.1/automatic_schema_matching for migration instructions.
  _run_hydra(
/home/ubuntu/.local/lib/python3.10/site-packages/hydra/_internal/hydra.py:119: UserWarning: Future Hydra versions will no longer change working directory at job runtime by default.
See https://hydra.cc/docs/1.2/upgrades/1.1_to_1.2/changes_to_job_working_dir/ for more information.
  ret = run_job(
Log file already exists at /home/ubuntu/tao-experiments/ocrnet/experiment_dir_retrain/status.json
Starting ocrnet inference.
engine_file /home/ubuntu/tao-experiments/ocrnet/export/trt.engine
batch_size 1
img_dirs /home/ubuntu/tao-experiments/data/ocrnet/test_samples
character_list_file /home/ubuntu/tao-experiments/data/ocrnet/character_list
img_width 200
img_height 64
img_channel 1
prediction_type Attn
shape [1, 64, 200]
engine-path /home/ubuntu/tao-experiments/ocrnet/export/trt.engine
[06/11/2024-17:51:05] [TRT] [W] The getMaxBatchSize() function should not be used with an engine built from a network created with NetworkDefinitionCreationFlag::kEXPLICIT_BATCH flag. This function will always return 1.
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1006.png: point 0.9970703125
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1008.png: the 0.9990234375
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1002.png: reatroom 0.9338503479957581
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1007.png: theatre 0.9537250399589539
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1009.png: esplanade 0.810028612613678
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1003.png: carpark 0.7116650938987732
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1004.png: passages 0.9931783676147461
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1001.png: passages 0.8872658014297485
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_100.png: fairprice 0.7623412609100342
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1000.png: meets 0.8055083155632019
/home/ubuntu/tao-experiments/data/ocrnet/test_samples/word_1005.png: meeding 0.9714475274085999
TensorRT engine inference finished successfully.
Inference finished successfully.

Thanks for your help.