open-mmlab / mmdeploy

OpenMMLab Model Deployment Framework
https://mmdeploy.readthedocs.io/en/latest/
Apache License 2.0
2.78k stars 636 forks source link

Serialization assertion magicTagRead == magicTag failed.Magic tag does not match #805

Closed brilliant-soilder closed 2 years ago

brilliant-soilder commented 2 years ago

I have converted the model on Ubuntu platform. When I perform the inference on Windows platform, it shows an error as this "Serialization assertion magicTagRead == magicTag failed.Magic tag does not match". Mask_rcnn_static_640x256. I'm using 640x256 as dimensions.

Here's the error information:

loading mmdeploy_execution ... loading mmdeploy_cpu_device ... loading mmdeploy_cuda_device ... loading mmdeploy_graph ... loading mmdeploy_directory_model ... [2022-07-25 01:10:55.359] [mmdeploy] [info] [model.cpp:95] Register 'DirectoryModel' loading mmdeploy_transform ... loading mmdeploy_cpu_transform_impl ... loading mmdeploy_cuda_transform_impl ... loading mmdeploy_transform_module ... loading mmdeploy_trt_net ... loading mmdeploy_net_module ... loading mmdeploy_mmcls ... loading mmdeploy_mmdet ... loading mmdeploy_mmseg ... loading mmdeploy_mmocr ... loading mmdeploy_mmedit ... loading mmdeploy_mmpose ... loading mmdeploy_mmrotate ... [2022-07-25 01:10:55.402] [mmdeploy] [info] [model.cpp:38] DirectoryModel successfully load sdk model F:\mmdeploy-0.6.0\test\mask_rcnn_static_640 [2022-07-25 01:10:55.498] [mmdeploy] [info] [common.h:29] config: { "context": { "device": "", "stream": "" }, "input": [ "image" ], "name": "mmdetection", "output": [ "det" ], "params": { "model": "" }, "type": "Inference" } [2022-07-25 01:10:55.499] [mmdeploy] [info] [common.h:29] config: { "context": { "device": "", "model": "", "stream": "" }, "input": [ "img" ], "module": "Transform", "name": "Preprocess", "output": [ "prep_output" ], "transforms": [ { "type": "LoadImageFromFile" }, { "keep_ratio": false, "size": [ 256, 640 ], "type": "Resize" }, { "mean": [ 123.675, 116.28, 103.53 ], "std": [ 58.395, 57.12, 57.375 ], "to_rgb": true, "type": "Normalize" }, { "size_divisor": 1, "type": "Pad" }, { "type": "DefaultFormatBundle" }, { "keys": [ "img" ], "meta_keys": [ "ori_shape", "ori_filename", "flip", "flip_direction", "scale_factor", "filename", "img_shape", "valid_ratio", "img_norm_cfg", "pad_shape" ], "type": "Collect" } ], "type": "Task" } [2022-07-25 01:10:55.501] [mmdeploy] [info] [common.h:29] config: { "context": { "device": "", "model": "", "stream": "" }, "input": [ "img" ], "module": "Transform", "name": "Preprocess", "output": [ "prep_output" ], "transforms": [ { "type": "LoadImageFromFile" }, { "keep_ratio": false, "size": [ 256, 640 ], "type": "Resize" }, { "mean": [ 123.675, 116.28, 103.53 ], "std": [ 58.395, 57.12, 57.375 ], "to_rgb": true, "type": "Normalize" }, { "size_divisor": 1, "type": "Pad" }, { "type": "DefaultFormatBundle" }, { "keys": [ "img" ], "meta_keys": [ "ori_shape", "ori_filename", "flip", "flip_direction", "scale_factor", "filename", "img_shape", "valid_ratio", "img_norm_cfg", "pad_shape" ], "type": "Collect" } ], "type": "Task" } [2022-07-25 01:10:55.502] [mmdeploy] [info] [common.h:29] config: { "context": { "device": "", "model": "", "stream": "" }, "input": [ "prep_output" ], "input_map": { "img": "input" }, "module": "Net", "name": "maskrcnn", "output": [ "infer_output" ], "type": "Task" } [2022-07-25 01:10:55.502] [mmdeploy] [info] [common.h:29] config: { "context": { "device": "", "model": "", "stream": "" }, "input": [ "prep_output" ], "input_map": { "img": "input" }, "module": "Net", "name": "maskrcnn", "output": [ "infer_output" ], "type": "Task" } [2022-07-25 01:10:55.503] [mmdeploy] [info] [cuda_device.cpp:61] Default CUDA allocator initialized [2022-07-25 01:10:56.021] [mmdeploy] [error] [trt_net.cpp:28] TRTNet: 1: [stdArchiveReader.cpp::nvinfer1::rt::StdArchiveReader::StdArchiveReader::30] Error Code 1: Serialization (Serialization assertion magicTagRead == magicTag failed.Magic tag does not match) [2022-07-25 01:10:56.022] [mmdeploy] [error] [trt_net.cpp:28] TRTNet: 4: [runtime.cpp::nvinfer1::Runtime::deserializeCudaEngine::50] Error Code 4: Internal Error (Engine deserialization failed.) [2022-07-25 01:10:56.022] [mmdeploy] [error] [trt_net.cpp:75] failed to deserialize TRT CUDA engine [2022-07-25 01:10:56.029] [mmdeploy] [error] [task.cpp:67] error parsing config: { "context": { "device": "", "model": "", "stream": "" }, "input": [ "prep_output" ], "input_map": { "img": "input" }, "module": "Net", "name": "maskrcnn", "output": [ "infer_output" ], "type": "Task" } [2022-07-25 01:10:56.029] [mmdeploy] [error] [pipeline.cpp:146] could not create maskrcnn: Task [2022-07-25 01:10:56.030] [mmdeploy] [error] [pipeline.cpp:160] error parsing config: unknown (6) @ :0 [2022-07-25 01:10:56.030] [mmdeploy] [error] [pipeline.cpp:27] exception caught: unknown (6) @ :0 failed to create detector, code: 6

F:\mmdeploy-0.6.0\sdk\build\Release\object_detection.exe (进程 4116)已退出,代码为 1。 要在调试停止时自动关闭控制台,请启用“工具”->“选项”->“调试”->“调试停止时自动关闭控制台”。 按任意键关闭此窗口. . .

brilliant-soilder commented 2 years ago

command:

include

include <opencv2/imgcodecs/imgcodecs.hpp>

include <opencv2/imgproc/imgproc.hpp>

include

include

include "detector.h"

stTimeRecord_t stc, startTime, finishTime; int main() {

const char* image_path = R"(F:\mmdeploy-0.6.0\test\1_0050.bmp)";

const char* model_path = R"(F:\mmdeploy-0.6.0\test\mask_rcnn_static_640)";

const char* device_name = "cuda";

//int main(int argc, char *argv[]) { // if (argc != 4) { // fprintf(stderr, "usage:\n object_detection device_name model_path image_path\n"); // return 1; // } // auto device_name = argv[1]; // auto model_path = argv[2]; // auto image_path = argv[3];

cv::Mat img = cv::imread(image_path); if (!img.data) { fprintf(stderr, "failed to load image: %s\n", image_path); return 1; }

mm_handle_t detector{}; int status{}; status = mmdeploy_detector_create_by_path(model_path, device_name, 0, &detector); if (status != MM_SUCCESS) { fprintf(stderr, "failed to create detector, code: %d\n", (int)status); return 1; }

//TIME_START(startTime); // /*测试部分*****/ //TIME_END(finishTime); //CACL_TIME_PRINT(startTime, finishTime, s_tc, "The time---------: ");

TIME_START(startTime); mm_mat_t mat{img.data, img.rows, img.cols, 3, MM_BGR, MM_INT8};

mm_detect_t bboxes{}; int res_count{}; status = mmdeploy_detector_apply(detector, &mat, 1, &bboxes, &res_count); if (status != MM_SUCCESS) { fprintf(stderr, "failed to apply detector, code: %d\n", (int)status); return 1; }

fprintf(stdout, "bbox_count=%d\n", *res_count);

for (int i = 0; i < *res_count; ++i) { const auto &box = bboxes[i].bbox; const auto &mask = bboxes[i].mask;

fprintf(stdout, "box %d, left=%.2f, top=%.2f, right=%.2f, bottom=%.2f, label=%d, score=%.4f\n",
        i, box.left, box.top, box.right, box.bottom, bboxes[i].label_id, bboxes[i].score);

// skip detections with invalid bbox size (bbox height or width < 1)
if ((box.right - box.left) < 1 || (box.bottom - box.top) < 1) {
  continue;
}

// skip detections less than specified score threshold
if (bboxes[i].score < 0.3) {
  continue;
}

// generate mask overlay if model exports masks
if (mask != nullptr) {
  fprintf(stdout, "mask %d, height=%d, width=%d\n", i, mask->height, mask->width);

  cv::Mat imgMask(mask->height, mask->width, CV_8UC1, &mask->data[0]);
  int x0 = max(std::floor(box.left) - 1, 0.f);
  int y0 = max(std::floor(box.top) - 1, 0.f);
  cv::Rect roi((int)x0, (int)y0, mask->width, mask->height);

  // split the RGB channels, overlay mask to a specific color channel
  cv::Mat ch[3];
  split(img, ch);
  int col = 0;  // int col = i % 3;
  cv::bitwise_or(imgMask, ch[col](roi), ch[col](roi));
  merge(ch, 3, img);
}
TIME_END(finishTime);
CACL_TIME_PRINT(startTime, finishTime, stc, "The time---------: ");
cv::rectangle(img, cv::Point{(int)box.left, (int)box.top},
              cv::Point{(int)box.right, (int)box.bottom}, cv::Scalar{0, 255, 0});

}

cv::imwrite("F:\mmdeploy-0.6.0\test\build_pictures\1_0050.bmp", img);

mmdeploy_detector_release_result(bboxes, res_count, 1);

mmdeploy_detector_destroy(detector);

return 0; }

brilliant-soilder commented 2 years ago

check_env:

2022-07-21 08:26:22,024 - mmdeploy - INFO -

2022-07-21 08:26:22,024 - mmdeploy - INFO - Environmental information 2022-07-21 08:26:23,874 - mmdeploy - INFO - sys.platform: linux 2022-07-21 08:26:23,875 - mmdeploy - INFO - Python: 3.9.12 (main, Jun 1 2022, 11:38:51) [GCC 7.5.0] 2022-07-21 08:26:23,875 - mmdeploy - INFO - CUDA available: True 2022-07-21 08:26:23,875 - mmdeploy - INFO - GPU 0: NVIDIA GeForce GTX 1650 2022-07-21 08:26:23,875 - mmdeploy - INFO - CUDA_HOME: /usr/local/cuda-10.2 2022-07-21 08:26:23,875 - mmdeploy - INFO - NVCC: Cuda compilation tools, release 10.2, V10.2.89 2022-07-21 08:26:23,875 - mmdeploy - INFO - GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 2022-07-21 08:26:23,875 - mmdeploy - INFO - PyTorch: 1.8.0 2022-07-21 08:26:23,875 - mmdeploy - INFO - PyTorch compiling details: PyTorch built with:

GCC 7.3
C++ Version: 201402
Intel(R) oneAPI Math Kernel Library Version 2021.4-Product Build 20210904 for Intel(R) 64 architecture applications
Intel(R) MKL-DNN v1.7.0 (Git Hash 7aed236906b1f7a05c0917e5257a1af05e9ff683)
OpenMP 201511 (a.k.a. OpenMP 4.5)
NNPACK is enabled
CPU capability usage: AVX2
CUDA Runtime 10.2
NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
CuDNN 7.6.5
Magma 2.5.2
Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=10.2, CUDNN_VERSION=7.6.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.8.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON,

2022-07-21 08:26:23,875 - mmdeploy - INFO - TorchVision: 0.2.2 2022-07-21 08:26:23,875 - mmdeploy - INFO - OpenCV: 4.6.0 2022-07-21 08:26:23,875 - mmdeploy - INFO - MMCV: 1.4.0 2022-07-21 08:26:23,875 - mmdeploy - INFO - MMCV Compiler: GCC 7.3 2022-07-21 08:26:23,875 - mmdeploy - INFO - MMCV CUDA Compiler: 10.2 2022-07-21 08:26:23,875 - mmdeploy - INFO - MMDeploy: 0.5.0+fa034e0 2022-07-21 08:26:23,875 - mmdeploy - INFO -

2022-07-21 08:26:23,875 - mmdeploy - INFO - Backend information 2022-07-21 08:26:27,741 - mmdeploy - INFO - onnxruntime: 1.10.0 ops_is_avaliable : True 2022-07-21 08:26:27,928 - mmdeploy - INFO - tensorrt: 8.2.3.0 ops_is_avaliable : True 2022-07-21 08:26:27,936 - mmdeploy - INFO - ncnn: None ops_is_avaliable : False 2022-07-21 08:26:27,939 - mmdeploy - INFO - pplnn_is_avaliable: False 2022-07-21 08:26:27,942 - mmdeploy - INFO - openvino_is_avaliable: False 2022-07-21 08:26:27,942 - mmdeploy - INFO -

2022-07-21 08:26:27,942 - mmdeploy - INFO - Codebase information 2022-07-21 08:26:27,994 - mmdeploy - INFO - mmdet: 2.20.0 2022-07-21 08:26:27,994 - mmdeploy - INFO - mmseg: None 2022-07-21 08:26:27,995 - mmdeploy - INFO - mmcls: None 2022-07-21 08:26:27,995 - mmdeploy - INFO - mmocr: None 2022-07-21 08:26:27,995 - mmdeploy - INFO - mmedit: None 2022-07-21 08:26:27,995 - mmdeploy - INFO - mmdet3d: None 2022-07-21 08:26:27,995 - mmdeploy - INFO - mmpose: None 2022-07-21 08:26:27,995 - mmdeploy - INFO - mmrotate: None

brilliant-soilder commented 2 years ago

It's quite a little bit weird. It performs the inference well on the Ubantu platform, wether python or SDk, but It can't runs on the win10.. And it also performs well on the win10 system using the model exported a few days earlier. When I changed the instance-seg_tensorrt-fp16_static-640x256.py and a resize keep_ratio, this error occured.

lzhangzz commented 2 years ago

[stdArchiveReader.cpp::nvinfer1::rt::StdArchiveReader::StdArchiveReader::30] Error Code 1: Serialization (Serialization assertion magicTagRead == magicTag failed.Magic tag does not match)

This error is caused by loading the engine using a different TensorRT version than the version used to build the engine. Check your environment to see if multiple TensorRT libs or cuDNN libs are involved.

brilliant-soilder commented 2 years ago

I recovered the "keep_ratio" of "resize " from False to True, and it become alright. But I quite not understand why, when i changed the dimensions, should't lay down the swift "resize"?

lzhangzz commented 2 years ago

You may try to load the engine with trtexec bundled with TensorRT release and see if that works.

sherry521sherry commented 1 year ago

You may try to load the engine with trtexec bundled with TensorRT release and see if that works.

how to do it?