1

我正在尝试在 Docker 容器中安装 detectron2 以将其用于项目中,但是在能够安装所有依赖项之后,当我尝试导入时出现错误model_zoo

  1. 完整的可运行代码或您所做的全部更改:

引发错误的代码是:

import cv2
import torch, torchvision
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()

# import some common libraries
import numpy as np
import os, json, cv2, random

# import some common detectron2 utilities
from detectron2 import model_zoo
  1. 您运行的确切命令:
from detectron2 import model_zoo

错误如下:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-c68fc36ab8f3> in <module>
      8 
      9 # import some common detectron2 utilities
---> 10 from detectron2 import model_zoo
     11 from detectron2.engine import DefaultPredictor
     12 from detectron2.config import get_cfg

/detectron2_repo/detectron2/model_zoo/__init__.py in <module>
      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"]

/detectron2_repo/detectron2/model_zoo/model_zoo.py in <module>
      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 

/detectron2_repo/detectron2/modeling/__init__.py in <module>
      1 # Copyright (c) Facebook, Inc. and its affiliates.
----> 2 from detectron2.layers import ShapeSpec
      3 
      4 from .anchor_generator import build_anchor_generator, ANCHOR_GENERATOR_REGISTRY
      5 from .backbone import (

/detectron2_repo/detectron2/layers/__init__.py in <module>
      2 from .batch_norm import FrozenBatchNorm2d, get_norm, NaiveSyncBatchNorm
      3 from .deform_conv import DeformConv, ModulatedDeformConv
----> 4 from .mask_ops import paste_masks_in_image
      5 from .nms import batched_nms, batched_nms_rotated, nms, nms_rotated
      6 from .roi_align import ROIAlign, roi_align

/detectron2_repo/detectron2/layers/mask_ops.py in <module>
      6 from torch.nn import functional as F
      7 
----> 8 from detectron2.structures import Boxes
      9 
     10 __all__ = ["paste_masks_in_image"]

/detectron2_repo/detectron2/structures/__init__.py in <module>
      5 from .instances import Instances
      6 from .keypoints import Keypoints, heatmaps_to_keypoints
----> 7 from .masks import BitMasks, PolygonMasks, polygons_to_bitmask
      8 from .rotated_boxes import RotatedBoxes
      9 from .rotated_boxes import pairwise_iou as pairwise_iou_rotated

/detectron2_repo/detectron2/structures/masks.py in <module>
      4 import numpy as np
      5 from typing import Any, Iterator, List, Union
----> 6 import pycocotools.mask as mask_util
      7 import torch
      8 

~/.local/lib/python3.8/site-packages/pycocotools/mask.py in <module>
      1 __author__ = 'tsungyi'
      2 
----> 3 import pycocotools._mask as _mask
      4 
      5 # Interface for manipulating masks stored in RLE format.

pycocotools/_mask.pyx in init pycocotools._mask()

ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

环境:

我使用的 Dockerfile 如下:

FROM ubuntu:20.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get -y update
RUN apt-get install -y python3-pip python3-dev
RUN apt-get install -y libglib2.0-0
RUN apt-get install -y git 
RUN apt-get install -y libgl1-mesa-dev
RUN apt-get install -y libsm6 libxext6 libxrender-dev
RUN pip3 install --user tensorboard cmake   # cmake from apt-get is too old
RUN pip3 install --user torch==1.8 torchvision==0.9 -f https://download.pytorch.org/whl/cu101/torch_stable.html
RUN pip3 install --user 'git+https://github.com/facebookresearch/fvcore'
RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo
RUN pip3 install --user -e detectron2_repo
RUN pip3 -q install pip --upgrade
RUN pip3 install opencv-python
RUN pip3 install jupyter notebook

# RUN mkdir src
WORKDIR src/
COPY . .
RUN pip3 install -r requirements.txt

CMD ["jupyter", "notebook", "--port=8888", "--ip=0.0.0.0", "--allow-root"]

另外,我的requirements.txt文件是:

absl-py==0.11.0
argon2-cffi==20.1.0
astunparse==1.6.3
async-generator==1.10
attrs==20.3.0
backcall==0.2.0
bleach==3.3.0
cachetools==4.2.1
certifi==2020.12.5
cffi==1.14.5
chardet==4.0.0
click==7.1.2
colorama==0.4.4
cycler==0.10.0
decorator==4.4.2
defusedxml==0.7.1
entrypoints==0.3
Flask==1.1.2
flatbuffers==1.12
gast==0.3.3
google-auth==1.27.0
google-auth-oauthlib==0.4.2
google-pasta==0.2.0
grpcio==1.32.0
h5py==2.10.0
idna==2.10
ipykernel==5.5.0
ipython
ipython-genutils==0.2.0
ipywidgets==7.6.3
itsdangerous==1.1.0
jedi==0.18.0
Jinja2==2.11.3
joblib==1.0.1
jsonschema==3.2.0
jupyter==1.0.0
jupyter-client==6.1.11
jupyter-console==6.3.0
jupyter-core==4.7.1
jupyterlab-pygments==0.1.2
jupyterlab-widgets==1.0.0
Keras-Preprocessing==1.1.2
kiwisolver==1.3.1
Markdown==3.3.4
MarkupSafe==1.1.1
matplotlib==3.3.4
mistune==0.8.4
nbclient==0.5.3
nbconvert==6.0.7
nbformat==5.1.2
nest-asyncio==1.5.1
notebook==6.3.0
numpy==1.19.5
oauthlib==3.1.0
opencv-python==4.5.1.48
opt-einsum==3.3.0
packaging==20.9
pandas
pandocfilters==1.4.3
parso==0.8.1
pickleshare==0.7.5
Pillow==8.1.0
prometheus-client==0.9.0
prompt-toolkit==3.0.16
protobuf==3.15.3
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
Pygments==2.8.0
pyparsing==2.4.7
pyrsistent==0.17.3
python-dateutil==2.8.1
pytz==2021.1
pyzmq==22.0.3
qtconsole==5.0.3
QtPy==1.9.0
requests==2.25.1
requests-oauthlib==1.3.0
rsa==4.7.2
scikit-learn==0.24.1
scipy
Send2Trash==1.5.0
six==1.15.0
tensorboard==2.4.1
tensorboard-plugin-wit==1.8.0
tensorflow==2.4.1
tensorflow-estimator==2.4.0
termcolor==1.1.0
terminado==0.9.3
testpath==0.4.4
threadpoolctl==2.1.0
tornado==6.1
traitlets
typing-extensions==3.7.4.3
urllib3==1.26.3
wcwidth==0.2.5
webencodings==0.5.1
Werkzeug==1.0.1
widgetsnbextension==3.5.1
wrapt==1.12.1
4

0 回答 0