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.

maskrcnn_resnet50_fpn use _save_for_lite_interpreter error

See original GitHub issue

🐛 Bug

To Reproduce

Steps to reproduce the behavior:

model = torchvision.models.detection.maskrcnn_resnet50_fpn(num_classes=24,pretrained=False).to(device) model.load_state_dict(checkpoint[‘model’]) model.eval() 2. script_model = torch.jit.script(model) opt_model = optimize_for_mobile(script_model) opt_model._save_for_lite_interpreter(“mask_rcnn_1.pt”) 3. RuntimeError: torch types other than torchbind (torch.torch.classes)are not supported in lite interpreter. Workaround: instead of using arbitrary class type (class Foo()), define a pytorch class (class Foo(torch.nn.Module)). SharedScreenshot

Expected behavior

Environment

Please copy and paste the output from our environment collection script (or fill out the checklist below manually).

You can get the script and run it with:

wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

PyTorch version: 1.9.0+cpu Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 专业版 GCC version: Could not collect Clang version: Could not collect CMake version: version 3.18.1 Libc version: N/A

Python version: 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] (64-bit runtime) Python platform: Windows-10-10.0.19041-SP0 Is CUDA available: False CUDA runtime version: No CUDA GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A

Versions of relevant libraries: [pip3] numpy==1.18.5 [pip3] torch==1.9.0 [pip3] torchaudio==0.9.0 [pip3] torchvision==0.10.0 [conda] Could not collect

Additional context

cc @datumbox @fmassa @vfdev-5 @pmeier

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
datumboxcommented, Sep 10, 2021

I spent a bit of time looking at it.

The issue appears not only in mask_rcnn but also in all *rcnn and ssd models. Those models do include a few classes that inherit from object instead of nn.Module (BalancedPositiveNegativeSampler, BoxCoder, Matcher, LevelMapper, etc). I tried converting them and see if the issue is resolved (see #4389, it’s quick and dirty, perhaps I missed something?) but the issue persists.

The error message, definitely doesn’t help to find which class is responsible. Perhaps we should involve someone from JIT to help out.

Edit: During debugging I strongly advise to use ssd300_vgg16 instead of mask_rcnn. It has less moving parts and can still reproduce the problem, so might be easier to find out what’s wrong. I use @pmeier’s snippet to trigger the error.

0reactions
RobinGRAPINcommented, Jul 20, 2022

Hello, any news about how to save a jitted RCNN model using _save_for_lite_interpreter() ? I would like to use it for mobile on iOS so this format is required, but as mentionned many classes such as ImageList aren’t supported in lite interpreter. I tried to make them inherit of torch.nn.Module() but it still lead to problems

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can't convert the pytorch maskrcnn_resnet50_fpn model to ...
I think this is because of config problem. Here is my approach to config: Download Libtorch from libtorch dl and unzip it where...
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