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.

  1. Full runnable code or full changes you made:
# Some basic setup:
# Setup detectron2 logger
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()

# import some common libraries
import numpy as np
import os, json, cv2, random
from google.colab.patches import cv2_imshow

# import some common detectron2 utilities
from detectron2 import model_zoo

Trying to run this code from https://colab.research.google.com/drive/16jcaJoc6bCFAQ96jDe2HwtXj7BMD_-m5, and have this report:

/usr/local/lib/python3.7/dist-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: libtorch_cuda_cu.so: cannot open shared object file: No such file or directory
  warn(f"Failed to load image Python extension: {e}")
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-1-9283645e3740>](https://localhost:8080/#) in <module>()
     11 
     12 # import some common detectron2 utilities
---> 13 from detectron2 import model_zoo
     14 from detectron2.engine import DefaultPredictor
     15 from detectron2.config import get_cfg

9 frames
[/usr/local/lib/python3.7/dist-packages/torchvision/models/quantization/mobilenetv2.py](https://localhost:8080/#) in <module>()
      3 from torch import Tensor
      4 from torch import nn
----> 5 from torch.ao.quantization import QuantStub, DeQuantStub
      6 from torchvision.models.mobilenetv2 import InvertedResidual, MobileNetV2, model_urls
      7 

ImportError: cannot import name 'QuantStub' from 'torch.ao.quantization' (/usr/local/lib/python3.7/dist-packages/torch/ao/quantization/__init__.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Expected behavior:

Imports without errors

Environment:

I try to use google colab to correctly install detectron to use it then for LayoutLMv2 Paste the output of the following command:

2022-05-05 12:14:23 URL:https://raw.githubusercontent.com/facebookresearch/detectron2/main/detectron2/utils/collect_env.py [8391/8391] -> "collect_env.py" [1]
/usr/local/lib/python3.7/dist-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: libtorch_cuda_cu.so: cannot open shared object file: No such file or directory
  warn(f"Failed to load image Python extension: {e}")
Traceback (most recent call last):
  File "collect_env.py", line 11, in <module>
    import torchvision
  File "/usr/local/lib/python3.7/dist-packages/torchvision/__init__.py", line 7, in <module>
    from torchvision import models
  File "/usr/local/lib/python3.7/dist-packages/torchvision/models/__init__.py", line 18, in <module>
    from . import quantization
  File "/usr/local/lib/python3.7/dist-packages/torchvision/models/quantization/__init__.py", line 1, in <module>
    from .mobilenet import *
  File "/usr/local/lib/python3.7/dist-packages/torchvision/models/quantization/mobilenet.py", line 1, in <module>
    from .mobilenetv2 import QuantizableMobileNetV2, mobilenet_v2, __all__ as mv2_all
  File "/usr/local/lib/python3.7/dist-packages/torchvision/models/quantization/mobilenetv2.py", line 5, in <module>
    from torch.ao.quantization import QuantStub, DeQuantStub
ImportError: cannot import name 'QuantStub' from 'torch.ao.quantization' (/usr/local/lib/python3.7/dist-packages/torch/ao/quantization/__init__.py)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

1reaction
linbinbin92commented, May 9, 2022

someone in the previous post seems to have resolved the issue, see https://github.com/facebookresearch/detectron2/issues/4183#issue-1216345007

0reactions
github-actions[bot]commented, May 17, 2022

Requested information was not provided in 7 days, so we’re closing this issue.

Please open new issue if information becomes available. Otherwise, use github discussions for free-form discussions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix ImportError: Cannot Import Name in Python - Rollbar
The Python ImportError: cannot import name error occurs when an imported class is not accessible or is in a circular dependency.
Read more >
Understanding the Functions of ImportError in Python - eduCBA
In Python, ImportError occurs when the Python program tries to import module which does not exist in the private table. This exception can...
Read more >
Built-in Exceptions — Python 3.11.1 documentation
A subclass of ImportError which is raised by import when a module could not be located. It is also raised when None is...
Read more >
Python Exception Handling: ImportError and ... - Airbrake Blog
The ImportError is raised when an import statement has trouble successfully importing the specified module. Typically, such a problem is due to ...
Read more >
Python error "ImportError: No module named" - Stack Overflow
Python error "ImportError: No module named" · Check that you have read permission to that file from python. · Please be sure to...
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