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.

Problems converting different networks.

See original GitHub issue

I succesfully tried the repo on some network in the examples, however i encountered some issues trying to convert different networks. I use a jetson nano with Tensorrt 5.0.6 and torch 1.2.0 First i tried to convert Inceptionv3 from torchvision models, the network is not converted and the error is: During conversion: [TensorRT] ERROR: Unused Input: i Then during inference: AttributeError: 'NoneType' object has no attribute 'get_binding_index'

I also tried to convert an implementation of SSD-mobilenet-v2 that can be found at: “https://github.com/qfgaohao/pytorch-ssd” this time the conversion script runs without any problem however the resulting network gives completely wrong score prediction, what could be the reason?

For both the cases there was the unsupported operation torch.unsqueeze that is a simple addition of a singleton dimension, if i understood it correctly, for this reason i used the same converter of function view to implement it.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
redzhepdxcommented, May 18, 2021

You can create your own wrapper for the torchvision models or any model that contains a dictionary output(OrderedDict etc). Here is my solution for torchvision.detection models’ backbones:

[Tested with retinanet_resnet50_fpn]

class BackboneWrapper(nn.Module):
    def __init__(self, model: nn.Module):
        super(BackboneWrapper, self).__init__()
        self.model = model

    def forward(self, x) -> List[torch.Tensor]:
        outputs = self.model(x)
        return [output for name, output in outputs.items()]

Usage :

backbone = BackboneWrapper(retina_fpn_model.backbone)
trt_backbone = torch2trt(backbone, [x])

Also to be able to re-create the model from the saved backbone you will need another wrapper to map these output tensors into a dictionary with corresponding tags(Probably there will an expectation in the main forward function of the model).

class BackboneDeWrapper(nn.Module):
    def __init__(self, model: nn.Module, return_names: List[int]):
        super(BackboneDeWrapper, self).__init__()
        self.model = model
        self.return_names = return_names

    def forward(self, x) -> OrderedDict:
        outputs = self.model(x)
        return OrderedDict({str(name): output for output, name in zip(outputs, self.return_names)})

Usage :

backbone = torch.load("saved_backbone")
returned_layers = [2, 3, 4, 6, 7] # P2, P3, P4, P6 and P7 for fpn
model.backbone = BackboneDeWrapper(backbone, return_names=returned_layers)
1reaction
jaybdubcommented, Dec 17, 2019

It’s possible that an unsupported operation was not detected. Currently, it’s not perfect how this is done (primarily looks for functions under torch.xxx, torch.nn.xxx, torch.nn.functional.xxx.

For the SSD model in particular, there are likely operations related to anchor box parsing that are not supported. Typically though, object detection models contain a backbone CNN, which likely is supported.

I haven’t investigated the model you sent in particular, but it may look something like

backbone_trt = torch2trt(model.backbone, [data])  # may vary, for illustrative purposes

model.backbone = backbone_trt

Are you able to determine if this method matches your use case?

Best, John

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are the problems and solutions of media converter?
1.Problem: Power supply broke · 2.Problem: Media converter broke by bad weather · 3.Problem: The optical module broke · 4.Problem: Problems outside ...
Read more >
A Quick Guide to Media Converters & Network Extenders
This article explains what a media converter is and how to use it, the models available, and highlights some new time-saving features unique...
Read more >
The Layman's Guide to Solving Wireless Network Interference ...
The Layman's Guide to Solving Wireless Network Interference Problems. One of the most common root causes for having slow and unstable wireless  ......
Read more >
Connecting Networks of Networks: The Internetworking Problem
This lecture looks at the issues—primarily those of heterogeneity and scale—that arise in internetworking different networks together.
Read more >
Is there a way of converting a neural network to another one ...
In practice, there are issues with performing such a reduction. ... that can be varied to generate multiple distinct models with different ......
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