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.

Import error from importing model_zoo

See original GitHub issue

I am working in CoLab, below is the code used to install and import libraries install dependencies

!pip install pyyaml==5.1
!pip install torch==1.8
!pip install wandb

import torch, torchvision
print(torch.__version__, torch.cuda.is_available())
 
!gcc --version
!git clone https://github.com/facebookresearch/detectron2
!pip install pycocotools wandb gputil psutil humanize
!pip install azure-storage-blob==2.1.0
 
# memory footprint support libraries/code
!ln -sf /opt/bin/nvidia-smi /usr/bin/nvidia-smi
 
# opencv is pre-installed on colab
 
# install detectron2: (Colab has CUDA 10.1 + torch 1.7)
# See https://detectron2.readthedocs.io/tutorials/install.html for instructions
assert torch.__version__.startswith("1.8")
!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.8/index.html
# exit(0)  # After installation, you need to "restart runtime" in Colab. This line can also restart runtime>

#Code below is imports used

import os
import uuid
import sys
from pathlib import Path
from azure.storage.blob import BlockBlobService, PublicAccess

from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import numpy as np
import cv2
from google.colab.patches import cv2_imshow

import random
import wandb
import json
from pycocotools.coco import COCO 

import psutil
import humanize
import os
import GPUtil as GPU

import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()

from collections import defaultdict
# import some common detectron2 utilities
from detectron2 import model_zoo
from detectron2.data.datasets import register_coco_instances
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog, DatasetCatalog

from detectron2 import model_zoo

When using the above line I get an import error:

ImportError                               Traceback (most recent call last)
<ipython-input-2-0396cd12a8c0> in <module>()
     27 from collections import defaultdict
     28 # import some common detectron2 utilities
---> 29 from detectron2 import model_zoo
     30 from detectron2.data.datasets import register_coco_instances
     31 from detectron2.engine import DefaultPredictor

4 frames
/usr/local/lib/python3.7/dist-packages/detectron2/layers/deform_conv.py in <module>()
      9 from torchvision.ops import deform_conv2d
     10 
---> 11 from detectron2 import _C
     12 
     13 from .wrappers import _NewEmptyTensorOp

ImportError: libtorch_cuda_cu.so: cannot open shared object file: No such file or directory

My code was working a few days ago and I am not sure if there was a version change and I might need to adjust something to incorporate this.

Any advice would be greatly appreciated.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
funatsufumiyacommented, Oct 6, 2021

I solved this on Colab. You have to check your CUDA version and PyTorch version matches to detectron2 ones.

# check CUDA version
!nvcc --version
# check PyTorch version
import torch
print(torch.__version__, torch.cuda.is_available())

If not, change it.

# list of available cuda versions
!ls -d /usr/local/cuda-*
# ex) change cuda version to 11.1
import os
p = os.getenv('PATH')
ld = os.getenv('LD_LIBRARY_PATH')
os.environ['PATH'] = f"/usr/local/cuda-11.1/bin:{p}"
os.environ['LD_LIBRARY_PATH'] = f"/usr/local/cuda-11.1/lib64:{ld}"
# change pytorch version
!pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html

Then restart your runtime, and retry installing detectron2.

2reactions
gchhablanicommented, Aug 5, 2021

I am getting the same error. Steps to reproduce:

  • Use Colab with GPU
# See https://detectron2.readthedocs.io/tutorials/install.html for instructions
%%capture
!pip install pyyaml==5.1
!pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu101/torch1.8/index.html
from detectron2.modeling import build_model
from detectron2.checkpoint import DetectionCheckpointer
from detectron2.structures.image_list import ImageList
from detectron2.data import transforms as T
from detectron2.modeling.box_regression import Box2BoxTransform
from detectron2.modeling.roi_heads.fast_rcnn import FastRCNNOutputs
from detectron2.structures.boxes import Boxes
from detectron2.layers import nms
from detectron2 import model_zoo
from detectron2.config import get_cfg

Error:

/usr/local/lib/python3.7/dist-packages/detectron2/layers/deform_conv.py in <module>()
      9 from torchvision.ops import deform_conv2d
     10 
---> 11 from detectron2 import _C
     12 
     13 from .wrappers import _NewEmptyTensorOp

ImportError: /usr/local/lib/python3.7/dist-packages/detectron2/_C.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZNK2at6Tensor7is_cudaEv

CC @ppwwyyxx

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError from detectron2 import model_zoo - Stack Overflow
The code that raise the error is: import cv2 import torch, torchvision import detectron2 from detectron2.utils.logger import setup_logger ...
Read more >
Errors importing models from ONNX Model Zoo - Questions
Hi, I am trying to import some pre-trained ONNX models from here https://github.com/onnx/models. I have met some issues, and I was wondering if...
Read more >
TDA4VM: Error while importing Yolov3 from onnx model zoo ...
Part Number: TDA4VM Hi all, I want to import Yolov3 model from ONNX models for performance evaluation, using the Edge AI Cloud ....
Read more >
Import Model — OpenVINO™ documentation — Version(latest)
This document focuses on importing a model from the Open Model Zoo. If you want to learn about importing original model, see the...
Read more >
model-zoo - PyPI
model-zoo 0.4.1 ... ModelZoo. A Scaffold to help you build Deep-learning Model much more ... from model_zoo import Model import tensorflow as tf...
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