facebookresearch / facebookresearch/detectron2

Cannot import name 'cached_property'

Open
#4,910 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
34.7k
Forks
7.9k
PR merge metrics
No merged PRs in 30d

Description

## 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

Contributor guide

Open the contributing guide

Research direction

Start at detectron2/utils/events.py and reproduce the import under the reported Python 3.7 environment. Check the installation instructions and compatibility expectations for the reported Python and PyTorch setup. Done means a supported clean installation imports detectron2.model_zoo without the cached_property or detectron2._C errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.