question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coverting torchvision trained models for use with DeepStream

See original GitHub issue

Hi

This might not be completely relevant here, but I have a ResNet-50 architecture, which was fetched from torchvision, and then fine-tuned on our own dataset. torch2trt is able to generate a trt_model as instructed. I want to use the generated engines with deepstream (DS). The generated engine file works, file and is deserialized successfully when used with DS. However, I noticed that I was not getting any classification results. I manually inspected the final layer output, and it showed that the model outputs scores instead of probabilities. The deepstream nvinfer plugin expects to work only with probabilities. The torchvision models do not have a final softmax layer, and are trained using nn.CrossEntropyLoss().

I tried to add a softmax layer to our model manually using:

model.add_module('softmax', torch.nn.Softmax(1))

and then export the model to model_trt using:

model_trt = torch2trt(model, [x])

I was once again able to generate an engine file, however, that engine file also outputs scores instead of probabilities. Is there a correct way to add a softmax layer so that torch2trt is able to work with it and generate an appropriate engine file? Or am I limited to post-processing the output myself? I am not really too familiar with tensorrt. If this is relevant, any help would be appreciated.

Regards Salman

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jaybdubcommented, Jun 10, 2020

Hi Salman,

Thanks for reaching out!

I think you’re on the right track, but I don’t think that model.add_module changes the execution behavior of the resnet50 module.

Can you try wrapping the model in a Sequential module and adding softmax? For example

backbone = resnet50(...)

# load your backbone weights

model = torch.nn.Sequential(
  backbone,
  torch.nn.Softmax(1)
)

model_trt = torch2trt(model, [x])

Please let me know if this works or you run into any issues.

Best, John

0reactions
doutdexcommented, Apr 8, 2021

https://github.com/dusty-nv/jetson-inference

I followed pytorch ssd example tutorial creating pth model https://github.com/dusty-nv/jetson-inference/blob/master/docs/pytorch-ssd.md

by the way on tutorial doesn’t exist the steps to export to engine in deepstream, I exported to onnx but is not working maybe Bbox Custom, the issue is not show any bbox detection while running a test video example Not exist example for deepstream app

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pytorch model example on Deepstream 5.0
I am interested in just doing an example flow of running a pytorch model using deepstream 5.0, before I use my own custom...
Read more >
How to Convert a Model from PyTorch to TensorRT and ...
Learn how to convert a PyTorch model to TensorRT to speed up inference. We provide step by step instructions with code.
Read more >
How to Convert a PyTorch Model to ONNX in 5 Minutes - Deci AI
Converting deep learning models from PyTorch to ONNX is quite straightforward. Start by loading a pre-trained ResNet-50 model from PyTorch's ...
Read more >
Few-Shot Object Detection with YOLOv5 and Roboflow
Traditionally if you want to train a machine learning model, you would use a public dataset such as the Pascal VOC 2012 dataset...
Read more >
Problem about pytorch-->onnx-->tensorrt-->DS
I use the pytorch to load ResNet50 in torchvision. I hope to train it by my own dataset, and translate it by tensorrt...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found