windows系统中安装目标检测平台detectron2

detectron2是Facebook研发并开源的目标检测平台,包含了大量业内最具代表性的目标检测、图像分割、关键点检测算法等。Detectron2基于新版的Pytorch进行更新,包含了更大的灵活性与扩展性。​

笔者将在本文中介绍如何在windows系统中安装Detectron2​

首先按照官方文件指导,只需要下载相关代码,然后pip 即可,具体两行命令如下:

git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2

​​笔者在执行第一行命令进行下载的时候,完全没有问题。但是第二行则直接报错,相关错误如下:

Requirement already satisfied: setuptools>=41.0.0 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (56.0.0)
Requirement already satisfied: werkzeug>=1.0.1 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (2.0.1)
Requirement already satisfied: grpcio>=1.24.3 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (1.43.0)
Requirement already satisfied: absl-py>=0.4 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (1.3.0)
Requirement already satisfied: google-auth<3,>=1.6.3 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (2.14.1)
Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (0.6.1)
Requirement already satisfied: protobuf<4,>=3.9.2 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (3.17.3)
Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (1.8.1)
Requirement already satisfied: markdown>=2.6.8 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (3.4.1)
Requirement already satisfied: requests<3,>=2.21.0 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (2.26.0)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (0.4.6)
Requirement already satisfied: wheel>=0.26 in d:\python39\lib\site-packages (from tensorboard->detectron2==0.6) (0.38.4)
Requirement already satisfied: six in d:\python39\lib\site-packages (from cycler>=0.10->matplotlib->detectron2==0.6) (1.16.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in d:\python39\lib\site-packages (from google-auth<3,>=1.6.3->tensorboard->detectron2==0.6) (0.2.8)
Requirement already satisfied: cachetools<6.0,>=2.0.0 in d:\python39\lib\site-packages (from google-auth<3,>=1.6.3->tensorboard->detectron2==0.6) (5.2.0)
Requirement already satisfied: rsa<5,>=3.1.4 in d:\python39\lib\site-packages (from google-auth<3,>=1.6.3->tensorboard->detectron2==0.6) (4.9)
Requirement already satisfied: requests-oauthlib>=0.7.0 in d:\python39\lib\site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard->detectron2==0.6) (1.3.1)
Requirement already satisfied: importlib-metadata>=4.4 in d:\python39\lib\site-packages (from markdown>=2.6.8->tensorboard->detectron2==0.6) (4.7.0)
Requirement already satisfied: certifi>=2017.4.17 in d:\python39\lib\site-packages (from requests<3,>=2.21.0->tensorboard->detectron2==0.6) (2021.5.30)
Requirement already satisfied: idna<4,>=2.5 in d:\python39\lib\site-packages (from requests<3,>=2.21.0->tensorboard->detectron2==0.6) (3.2)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in d:\python39\lib\site-packages (from requests<3,>=2.21.0->tensorboard->detectron2==0.6) (1.26.6)
Requirement already satisfied: charset-normalizer~=2.0.0 in d:\python39\lib\site-packages (from requests<3,>=2.21.0->tensorboard->detectron2==0.6) (2.0.4)
Requirement already satisfied: pywin32>=226 in d:\python39\lib\site-packages (from portalocker->iopath<0.1.10,>=0.1.7->detectron2==0.6) (301)
Requirement already satisfied: zipp>=0.5 in d:\python39\lib\site-packages (from importlib-metadata>=4.4->markdown>=2.6.8->tensorboard->detectron2==0.6) (3.5.0)
Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in d:\python39\lib\site-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard->detectron2==0.6) (0.4.8)
Requirement already satisfied: oauthlib>=3.0.0 in d:\python39\lib\site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard->detectron2==0.6) (3.2.2)
Building wheels for collected packages: fvcore, antlr4-python3-runtime, pycocotools
  Building wheel for fvcore (setup.py) ... done
  Created wheel for fvcore: filename=fvcore-0.1.5.post20221221-py3-none-any.whl size=61438 sha256=148e752c75e8b8249cd61300067a0865eb1d991d8b6d0976a97dbe1b258b0fed
  Stored in directory: c:\users\condor\appdata\local\pip\cache\wheels\83\42\02\66178d16e5c44dc26d309931834956baeda371956e86fbd876
  Building wheel for antlr4-python3-runtime (setup.py) ... done
  Created wheel for antlr4-python3-runtime: filename=antlr4_python3_runtime-4.9.3-py3-none-any.whl size=144586 sha256=8d81a5cc43b5baf0700291f1993519452c38cc9d4e51e1fbbb5108e9423d533b
  Stored in directory: c:\users\condor\appdata\local\pip\cache\wheels\23\cf\80\f3efa822e6ab23277902ee9165fe772eeb1dfb8014f359020a
  Building wheel for pycocotools (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for pycocotools (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-39
      creating build\lib.win-amd64-cpython-39\pycocotools
      copying pycocotools\coco.py -> build\lib.win-amd64-cpython-39\pycocotools
      copying pycocotools\cocoeval.py -> build\lib.win-amd64-cpython-39\pycocotools
      copying pycocotools\mask.py -> build\lib.win-amd64-cpython-39\pycocotools
      copying pycocotools\__init__.py -> build\lib.win-amd64-cpython-39\pycocotools
      running build_ext
      cythoning pycocotools/_mask.pyx to pycocotools\_mask.c
      C:\Users\condor\AppData\Local\Temp\pip-build-env-61ev7sr7\overlay\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\condor\AppData\Local\Temp\pip-install-6tnrh7ir\pycocotools_07ef0386581d473a80b1cee866d0bc03\pycocotools\_mask.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      building 'pycocotools._mask' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pycocotools
Successfully built fvcore antlr4-python3-runtime
Failed to build pycocotools
ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml-based projects

可以看到其中关键信息:​

error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/​

笔者经查询,解决方案如下:​

第一步: 安装java jdk并设置系统变量和环境变量​

第二步: 根据python版本选择Jpype进行安装 https://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype​

第三步: 安装Microsoft C++ 生成工具 – Visual Studio :https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/

​​

安装成功即可​

我看到网上文章还提到继续安装pyhanlp​

pip install pyhanlp

但是笔者这里安装的时候报错了,忽略该问题,直接跳转到上面安装Detectron2,发现成功安装。

​​

此条目发表在深度学习分类目录,贴了, , 标签。将固定链接加入收藏夹。

发表回复