[Solved] Import Error for Detectron2 after installation on Ubuntu 18.04 #3211
Unanswered
JaninaMattes
asked this question in
Q&A
Replies: 1 comment
-
The change to |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I did install Detectron2 on an Ubuntu 18.04 Bionic Azure insance without GPU access. The Python version is python 3.8. I am using PyTorch 1.8.1 with CPU support. However, when trying to run my python script I receive the following error:
Error Message
File "finetune_net_dla.py", line 29, in <module> from detectron2.evaluation import ( ImportError: cannot import name 'CityscapesEvaluator' from 'detectron2.evaluation' (/anaconda/lib/python3.8/site-packages/detectron2/detectron2/evaluation/__init__.py)
Python Script
My python script's imports look like the following:
import logging import os import datetime from collections import OrderedDict import torch import detectron2.utils.comm as comm from detectron2.checkpoint import DetectionCheckpointer from detectron2.config import get_cfg from detectron2.data import MetadataCatalog from detectron2.engine import DefaultTrainer, default_argument_parser, default_setup, hooks, launch from detectron2.evaluation import ( CityscapesEvaluator, COCOEvaluator, COCOPanopticEvaluator, DatasetEvaluators, LVISEvaluator, PascalVOCDetectionEvaluator, SemSegEvaluator, verify_results, ) from detectron2.modeling import GeneralizedRCNNWithTTA from detectron2.data.datasets import register_coco_instances from detectron2.utils.logger import setup_logger logger = logging.getLogger("detectron2")
What I have done so far
I followed the described INSTALL.md with
python -m pip install 'git+https://github.com/facebookresearch/detectron2.git' and also tried git clone https://github.com/facebookresearch/detectron2.git python -m pip install -e detectron2
I further tried it with
rm -rf build/ **/*.so
. I yet tried to clone the detectron repo into my own repo before I built it and into a different directory; I renamed the folders after the built ... I cloned the Detectron2 repo directly into../../site-packages
. However, I receive the same error even if I try to install everything within a Docker container or simply with a Anaconda environment. If I usewhich python
in Anaconda I receive/anaconda/bin/python
and when I usepython -m site
it returns meUnder
/anaconda/lib/python3.8/site-packages
I can find the detectron2 egg.link as follows:-rw-rw-r--+ 1 mattesjanina1 sudo 47 Jun 30 15:36 detectron2.egg-link -rwxrwxrwx 4 root sudo 152 Jan 25 20:06 distutils-precedence.pth drwxrwsr-x+ 10 root sudo 4096 Jun 1 12:23 docker
My Docker file
My Docker file follows the structure of the
./docker/Dockerfile
of the Detectron2 repo and looks like the following:`FROM python:3.8-slim-buster
RUN apt-get update -y
RUN apt-get -y install apt-utils nano build-essential libglib2.0-0 libsm6 libxext6 libxrender-dev
python3-opencv ca-certificates python3-dev git wget sudo unzip ninja-build &&
rm -rf /var/lib/apt/lists/*
ARG USER_ID=1000
RUN useradd -m --no-log-init --system --uid ${USER_ID} appuser -g sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER appuser
WORKDIR /home/appuser
ENV PATH="/home/appuser/.local/bin:${PATH}"
RUN pip install --user torchtext==0.9.1
RUN pip install --user torchvision torchtext==0.9.1 tensorboard cython cmake pyyaml==5.1 gdown
RUN pip install --user torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
RUN pip install --user -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
RUN mkdir /home/appuser/detectron2_repo
COPY configs/ /home/appuser/detectron2_repo/configs
COPY finetune_net_dla.py /home/appuser/detectron2_repo
WORKDIR /home/appuser/detectron2_repo
RUN pip install --user 'git+https://github.com/facebookresearch/fvcore'
RUN python3 -m pip install --user detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/index.html
RUN pip install --user pdf2image gunicorn Pillow opencv-python
RUN mkdir /home/appuser/detectron2_repo/datasets
RUN gdown https://drive.google.com/uc?id=XXXX
RUN unzip custom_data.zip -d /home/appuser/detectron2_repo/datasets
RUN rm -r custom_data.zip
RUN mkdir /home/appuser/detectron2_repo/pretrained_models
RUN wget https://www.dropbox.com/sh/wgt9skz67usliei/AADGw0h1y7K5vO0akulyXm-qa/model_final.pth -P /home/appuser/detectron2_repo/pretrained_models/
ENTRYPOINT [ "python3", "finetune_net_dla.py" ]
`
#-----------------------------------------------------------
So far I didn't manage to solve the issue myself. If you have any idea what might cause the problem - I am very glad about any hint or idea 💯 !!.
Beta Was this translation helpful? Give feedback.
All reactions