Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization Error in verifyHeader: 0 #32

Open
jin-wong1031 opened this issue May 3, 2020 · 4 comments
Open

Serialization Error in verifyHeader: 0 #32

jin-wong1031 opened this issue May 3, 2020 · 4 comments

Comments

@jin-wong1031
Copy link

jin-wong1031 commented May 3, 2020

i done the installation and ran python3 iva.py 0, errors occur:

[TensorRT] ERROR: ../rtSafe/coreReadArchive.cpp (31) - Serialization Error in verifyHeader: 0 (Magic tag does not match)
[TensorRT] ERROR: INVALID_STATE: std::exception
[TensorRT] ERROR: INVALID_CONFIG: Deserialize the cuda engine failed.
Traceback (most recent call last):
File "iva.py", line 39, in
model_trt.load_state_dict(torch.load(OPTIMIZED_MODEL))
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 815, in load_state_dict
load(self)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 810, in load
state_dict, prefix, local_metadata, True, missing_keys, unexpected_keys, error_msgs)
File "/usr/local/lib/python3.6/dist-packages/torch2trt/torch2trt.py", line 309, in _load_from_state_dict
self.context = self.engine.create_execution_context()
AttributeError: 'NoneType' object has no attribute 'create_execution_context'

Any ideas?

seems related to the model...did you test your model on jetson nano?

@azf99
Copy link

azf99 commented Dec 9, 2020

@jin-wong1031 Were you able to fix it?

@azf99
Copy link

azf99 commented Dec 12, 2020

@jin-wong1031

The reason for this error is that ActionAI gives us the TensorRT engine for the pose detection model. Since these engine files are GPU specific, they won't run on your machine. You need to build your own engine from the original Pytorch model.

Download this Pytorch model https://drive.google.com/open?id=1XYDdCUdiF2xxx4rznmLb62SdOUZuoNbd
You'll get this file: resnet18_baseline_att_224x224_A_epoch_249.pth

I got it from the trt_pose repository.

You must have already got the human_pose.json file with you.

Use the following code to build your own TensorRT engine:

import json
import trt_pose.coco

with open('human_pose.json', 'r') as f:
    human_pose = json.load(f)

topology = trt_pose.coco.coco_category_to_topology(human_pose)

import trt_pose.models

num_parts = len(human_pose['keypoints'])
num_links = len(human_pose['skeleton'])

model = trt_pose.models.resnet18_baseline_att(num_parts, 2 * num_links).cuda().eval()

import torch

MODEL_WEIGHTS = 'resnet18_baseline_att_224x224_A_epoch_249.pth'
model.load_state_dict(torch.load(MODEL_WEIGHTS))

WIDTH = 224
HEIGHT = 224
data = torch.zeros((1, 3, HEIGHT, WIDTH)).cuda()

import torch2trt

model_trt = torch2trt.torch2trt(model, [data], fp16_mode=True, max_workspace_size=1<<25)
OPTIMIZED_MODEL = 'models/resnet18_baseline_att_224x224_A_epoch_249_trt.pth'
torch.save(model_trt.state_dict(), OPTIMIZED_MODEL)

And now, its done. place the new resnet18_baseline_att_224x224_A_epoch_249_trt.pth file in the models folder.

@baixianger
Copy link

sounds like it's the big difference between Jetson and respiberrypi. the model in Jetson is Nvidia GPU specialized. so if you deploy actionAI in another platform(like respiberrypi), you would meet this issue.
as @azf99 mentioned before, you need download a cpu-based model.

@baixianger
Copy link

sounds like it's the big difference between Jetson and respiberrypi. the model in Jetson is Nvidia GPU specialized. so if you deploy actionAI in another platform(like respiberrypi), you would meet this issue.
as @azf99 mentioned before, you need download a cpu-based model.

sorry, I am wrong. I think it once again, may it's because the version of tensorRT, so we need convert the original models into the typical version of tensorRT, so the converted trt model the author providing is no longer suit to our person of tensorRT. in other word, one version of tensorRT model may not be used in another version,so I have to convert it locally. an I right?

best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants