Problem about pytorch-->onnx-->tensorrt-->DS

Dear professor, this is a hurry problem for me, it makes me crazy server days.

I use the pytorch to load ResNet50 in torchvision. I hope to train it by my own dataset, and translate it by tensorrt for deepstream. However, it is a crushing problem for me.

(1) My model is:

class ResNet50_with_softmax(nn.Module):
def init(self):
super(ResNet50_with_softmax, self).init()
self.net = models.resnet50(weights=models.ResNet50_Weights.DEFAULT)
fc_features = self.net.fc.in_features
self.net.fc = nn.Linear(fc_features, 3)
self.softmax = nn.Softmax(dim=1)

def forward(self, x):
    x = self.net(x)
    x = self.softmax(x)
    return x

(2) My onnx transform as below:

import torch
from myModel import ResNet50_with_softmax
input_names = [“input”]
output_names = [“predictions/Softmax”]
input_data = torch.randn((2, 3, 200, 200))
model = ResNet50_with_softmax()

param_dic = torch.load(“ResNet50_with_softmax_GPU_dict.pth”)

model.load_state_dict(param_dic)

model.eval()
output = model(input_data)
print(output)
torch.onnx.export(model,
input_data,
‘ResNet18_with_softmax_GPU_dict.onnx’,
export_params=True,
do_constant_folding=True,
input_names=input_names,
output_names=output_names,
dynamic_axes={‘input’: {0: ‘batch_size’, 2:‘width’, 3:‘height’},
‘predictions/Softmax’: {0: ‘batch_size’}})

(3) My command for translating the onnx into tensorrt as below

/usr/src/tensorrt/bin/trtexec --onnx=ResNet18_with_softmax_GPU_dict.onnx
–minShapes=input:1x3x300x200
–optShapes=input:8x3x300x200
–maxShapes=input:16x3x300x200
–workspace=14096
–saveEngine=SGIE_with_softmax_D.engine --fp16

my problem is: a few times I can get the result from the engine by Deepstream,but many times I can not, despite the code and processes are the same,
It makes me crazy. Please kindly help me.

I tried many times,
(1) If I download the pre-trained RestNet18 from pytorch automatically, and don’t train it by my dataset, deepstream can get the result.
(2) Based on (1), I train RestNet18 on my dataset, Deepstream can get the result.
But!!
(3) Go on, I change RestNet18 to Resnet50,Deepstream CAN Not get the result.
(4) I retry ResNet18, it can not work
(5) I reboot the computer, It can not work both ResNet50 and ResNet18.

The code and the process are the same!
what the matter?

Thank you very much! someone kindly help me.