facebookresearch / detectron2

Detectron2 is a platform for object detection, segmentation and other visual recognition tasks.
https://detectron2.readthedocs.io/en/latest/
Apache License 2.0
30.59k stars 7.5k forks source link

Cannot import name 'cached_property' #4910

Open Thornbach opened 1 year ago

Thornbach commented 1 year ago

Instructions To Reproduce the 🐛 Bug:

  1. Full runnable code or full changes you made:
    
    !python -m pip install pyyaml==5.1
    import sys, os, distutils.core
    # Note: This is a faster way to install detectron2 in Colab, but it does not include all functionalities.
    # See https://detectron2.readthedocs.io/tutorials/install.html for full installation instructions
    !git clone 'https://github.com/facebookresearch/detectron2'
    dist = distutils.core.run_setup("./detectron2/setup.py")
    !python -m pip install {' '.join([f"'{x}'" for x in dist.install_requires])}
    sys.path.insert(0, os.path.abspath('./detectron2'))

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

import some common libraries

import numpy as np

import some common detectron2 utilities

from detectron2 import model_zoo from detectron2.engine import DefaultPredictor from detectron2.config import get_cfg from detectron2.utils.visualizer import Visualizer from detectron2.data import MetadataCatalog, DatasetCatalog

2. What exact command you run: from detectron2 import model_zoo
3. __Full logs__ or other relevant observations:

ImportError Traceback (most recent call last) /tmp/ipykernel_23/155909432.py in 9 10 # import some common detectron2 utilities ---> 11 from detectron2 import model_zoo 12 from detectron2.engine import DefaultPredictor 13 from detectron2.config import get_cfg

/kaggle/working/detectron2/detectron2/model_zoo/init.py in 6 """ 7 ----> 8 from .model_zoo import get, get_config_file, get_checkpoint_url, get_config 9 10 all = ["get_checkpoint_url", "get", "get_config_file", "get_config"]

/kaggle/working/detectron2/detectron2/model_zoo/model_zoo.py in 7 from detectron2.checkpoint import DetectionCheckpointer 8 from detectron2.config import CfgNode, LazyConfig, get_cfg, instantiate ----> 9 from detectron2.modeling import build_model 10 11

/kaggle/working/detectron2/detectron2/modeling/init.py in 18 SwinTransformer, 19 ) ---> 20 from .meta_arch import ( 21 META_ARCH_REGISTRY, 22 SEM_SEG_HEADS_REGISTRY,

/kaggle/working/detectron2/detectron2/modeling/meta_arch/init.py in 4 from .build import META_ARCH_REGISTRY, build_model # isort:skip 5 ----> 6 from .panoptic_fpn import PanopticFPN 7 8 # import all the meta_arch, so they will be registered

/kaggle/working/detectron2/detectron2/modeling/meta_arch/panoptic_fpn.py in 12 from ..postprocessing import detector_postprocess, sem_seg_postprocess 13 from .build import META_ARCH_REGISTRY ---> 14 from .rcnn import GeneralizedRCNN 15 from .semantic_seg import build_sem_seg_head 16

/kaggle/working/detectron2/detectron2/modeling/meta_arch/rcnn.py in 10 from detectron2.layers import move_device_like 11 from detectron2.structures import ImageList, Instances ---> 12 from detectron2.utils.events import get_event_storage 13 from detectron2.utils.logger import log_first_n 14

/kaggle/working/detectron2/detectron2/utils/events.py in 7 from collections import defaultdict 8 from contextlib import contextmanager ----> 9 from functools import cached_property 10 from typing import Optional 11 import torch

ImportError: cannot import name 'cached_property' from 'functools' (/opt/conda/lib/python3.7/functools.py)

4. please simplify the steps as much as possible so they do not require additional resources to
   run, such as a private dataset.

## Expected behavior:

It seems to have trouble importing model_zoo from detectron2. A couple days ago it just worked fine.

## Environment:

Provide your environment information using the following command:

sys.platform linux Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:53) [GCC 9.4.0] numpy 1.21.6 detectron2 imported a wrong installation detectron2._C not built correctly: No module named 'detectron2._C' Compiler ($CXX) c++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 CUDA compiler Build cuda_11.3.r11.3/compiler.29920130_0 DETECTRON2_ENV_MODULE PyTorch 1.13.0 @/opt/conda/lib/python3.7/site-packages/torch PyTorch debug build False torch._C._GLIBCXX_USE_CXX11_ABI True GPU available Yes GPU 0,1 Tesla T4 (arch=7.5) Driver version 470.161.03 CUDA_HOME /usr/local/cuda Pillow 9.3.0 torchvision 0.14.0 @/opt/conda/lib/python3.7/site-packages/torchvision torchvision arch flags 3.7, 6.0, 7.0, 7.5 fvcore 0.1.5.post20221221 iopath 0.1.9 cv2 4.5.4



If your issue looks like an installation issue / environment issue,
please first try to solve it yourself with the instructions in
https://detectron2.readthedocs.io/tutorials/install.html#common-installation-issues
github-actions[bot] commented 1 year ago

We found that not enough information is provided about this issue. Please provide details following the issue template.

RajUpadhyay commented 1 year ago

Maybe try installing newer version of python, 3.8.11, if not then 3.9?

andresh97 commented 1 year ago

@Thornbach did you find any solution other than changing the python version?

Thornbach commented 1 year ago

Hey! Sadly not. The only solution is indeed to switch into another python version. I was using Kaggle, thus it is combined with quite a hassle. Maybe i will just switch to Google Colab for this. But I'll let you know if I have any other solutions for this.

KHochia commented 1 year ago

hello! I have the same problem, and my solution is trying the following command line: !pip install 'git+https://github.com/facebookresearch/detectron2.git@d779ea63faa54fe42b9b4c280365eaafccb280d6', which means downloading the latest version before the commit with bug so that it's unnecessary to change python version.