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.45k stars 7.47k forks source link

Can I install detectron2 on Win10? #9

Open JinyuanShao opened 5 years ago

JinyuanShao commented 5 years ago

Can I install detectron2 on Win10?

VJoer commented 3 years ago

@huangweiwade just had the same problem. I stumbled upon some bash script to fix a couple of cpp things:

#!/bin/bash

SITE=/mnt/c/Users/thomas.jungblut/AppData/Local/Programs/Python/Python37/Lib/site-packages
sed -i.bak -e 's/CONSTEXPR_EXCEPT_WIN_CUDA/const/g' "${SITE}/torch/include/torch/csrc/jit/api/module.h"
sed -i.bak -e 's/return \*(this->value)/return \*((type\*)this->value)/g' "${SITE}/torch/include/pybind11/cast.h"
sed -i.bak '/static constexpr Symbol Kind/d' "${SITE}/torch/include/torch/csrc/jit/ir/ir.h"

Change the site variable up to your installation path in Conda (D:/Users/huang/anaconda3/lib/site-packages). Then a plain installation via git clone and python -m pip install -e detectron2 works as advertised.

Thank you for the detailed steps provided.

carlosedubarreto commented 3 years ago

Try the instructions on this page. It helped me a lot https://ivanpp.cc/detectron2-walkthrough-windows/

markstrefford commented 3 years ago

I had similar issues. In the end I installed it using WSL2 using CUDA11.2 and an RTX3070 GPU: https://github.com/markstrefford/running-detectron2-on-windows-wsl2-rtx30xx

marcosterland commented 3 years ago

Since v0.3 I can simply install it with conda. Here's my environment.yml:

name: detectron2
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python>=3.8
  - numpy
  - cudatoolkit=10.1
  - pytorch==1.6
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/detectron2.git@v0.3

Hope this helps someone.

markstrefford commented 3 years ago

Since v0.3 I can simply install it with conda. Here's my environment.yml:

name: detectron2
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python>=3.8
  - numpy
  - cudatoolkit=10.1
  - pytorch==1.6
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/detectron2.git@v0.3

Hope this helps someone.

This didn't work for me using RTX3070, CUDA 11.2.

marcosterland commented 3 years ago

This didn't work for me using RTX3070, CUDA 11.2.

Have you tried to change the dependencies accordingly?

  - cudatoolkit=11.2
  - pytorch==1.7

Maybe it also works with only the CUDA line changed.

markstrefford commented 3 years ago

This didn't work for me using RTX3070, CUDA 11.2.

Have you tried to change the dependencies accordingly?

  - cudatoolkit=11.2
  - pytorch==1.7

Maybe it also works with only the CUDA line changed.

I changed that, but get this issue when I try from detectron2.engine import DefaultPredictor:


    from detectron2.engine import DefaultPredictor

  File "C:\Users\Mark\anaconda3\envs\detectron2\lib\site-packages\detectron2\engine\__init__.py", line 4, in <module>
    from .train_loop import *

  File "C:\Users\Mark\anaconda3\envs\detectron2\lib\site-packages\detectron2\engine\train_loop.py", line 13, in <module>
    from detectron2.utils.events import EventStorage, get_event_storage

  File "C:\Users\Mark\anaconda3\envs\detectron2\lib\site-packages\detectron2\utils\events.py", line 12, in <module>
    from detectron2.utils.file_io import PathManager

  File "C:\Users\Mark\anaconda3\envs\detectron2\lib\site-packages\detectron2\utils\file_io.py", line 1, in <module>
    from fvcore.common.file_io import HTTPURLHandler, OneDrivePathHandler, PathHandler, PathManagerBase

  File "C:\Users\Mark\anaconda3\envs\detectron2\lib\site-packages\fvcore\common\file_io.py", line 10, in <module>
    from iopath.common.file_io import (

  File "C:\Users\Mark\anaconda3\envs\detectron2\lib\site-packages\iopath\common\file_io.py", line 14, in <module>
    import portalocker  # type: ignore

  File "C:\Users\Mark\anaconda3\envs\detectron2\lib\site-packages\portalocker\__init__.py", line 4, in <module>
    from . import portalocker

  File "C:\Users\Mark\anaconda3\envs\detectron2\lib\site-packages\portalocker\portalocker.py", line 11, in <module>
    import win32file

ImportError: DLL load failed while importing win32file: The specified module could not be found.```

I don't get this error when running in WSL2 / Ubuntu with all of the same code versions.
markstrefford commented 3 years ago

Ah! Fixed it! conda install pywin32 fixes it. Here's my yml file:

name: detectron2
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python=3.8
  - numpy
  - pywin32
  - cudatoolkit=11.0
  - pytorch==1.7.1
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/detectron2.git@v0.3
sebastian-ruiz commented 3 years ago

This might be relevant for issues: #1842 #2908 #2769 #2703 #1494

You can run the latest version of detectron2 (at this moment in time v0.4 or commit 9c7f8a1) on CPU. I did this by following the circleCI which passes for windows CPU.

Do the following:

conda create -n detectron2 python=3.7
conda activate detectron2

pip install certifi --ignore-installed
pip install numpy cython
pip install opencv-python-headless pytest-xdist pycocotools tensorboard
pip install -U git+https://github.com/facebookresearch/fvcore
pip install -U git+https://github.com/facebookresearch/iopath
pip install torch==1.7 torchvision==0.8 -f https://download.pytorch.org/whl/cpu/torch_stable.html

Clone the latest version of detectron2 and do:

cd detectron2
pip install --progress-bar off -e .[all]
python -m detectron2.utils.collect_env

You should get the following output (also you see this output on circleCI):

No CUDA runtime is found, using CUDA_HOME='C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1'
---------------------  -----------------------------------------------------------------------------------
sys.platform           win32
Python                 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)]
numpy                  1.20.2
detectron2             0.4 @C:\Users\asdf\Documents\detectron2_stuff\detectron2\detectron2
Compiler               MSVC 192829914
CUDA compiler          not available
DETECTRON2_ENV_MODULE  <not set>
PyTorch                1.7.0+cpu @C:\Users\asdf\.anaconda3\envs\detectron2\lib\site-packages\torch
PyTorch debug build    True
GPU available          False
Pillow                 8.2.0
torchvision            0.8.0 @C:\Users\asdf\.anaconda3\envs\detectron2\lib\site-packages\torchvision
fvcore                 0.1.5
iopath                 0.1.7
cv2                    4.5.1
---------------------  -----------------------------------------------------------------------------------
PyTorch built with:
  - C++ Version: 199711
  - MSVC 192729112
  - Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191125 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v1.6.0 (Git Hash 5ef631a030a6f73131c77892041042805a06064f)
  - OpenMP 2019
  - CPU capability usage: AVX
  - Build settings: BLAS=MKL, BUILD_TYPE=Release, CXX_FLAGS=/DWIN32 /D_WINDOWS /GR /EHsc /w /bigobj -openmp:experimental -DNDEBUG -DUSE_FBGEMM -DUSE_VULKAN_WRAPPER, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=0, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=OFF, USE_OPENMP=ON,

It works!!! 😃

I did not get it working on GPU however. Replacing the torch install line with:

conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=10.1 -c pytorch

and then running

pip install --progress-bar off -e .[all]

Gives a long error ending with:

      File "C:\Users\asdf\.anaconda3\envs\detectron2_gpu\lib\site-packages\torch\utils\cpp_extension.py", line 1538, in _run_ninja_build
        raise RuntimeError(message) from e
    RuntimeError: Error compiling objects for extension
    Error in atexit._run_exitfuncs:
    Traceback (most recent call last):
      File "C:\Users\asdf\.anaconda3\envs\detectron2_gpu\lib\site-packages\colorama\ansitowin32.py", line 59, in closed
        return stream.closed
    ValueError: underlying buffer has been detached
akkiss commented 3 years ago

Ah! Fixed it! conda install pywin32 fixes it. Here's my yml file:

name: detectron2
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python=3.8
  - numpy
  - pywin32
  - cudatoolkit=11.0
  - pytorch==1.7.1
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/detectron2.git@v0.3

What compiler did you use? This does not work for me with VS2015 (v140, update 3).

mallyagirish commented 3 years ago

Ah! Fixed it! conda install pywin32 fixes it. Here's my yml file:

name: detectron2
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python=3.8
  - numpy
  - pywin32
  - cudatoolkit=11.0
  - pytorch==1.7.1
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/detectron2.git@v0.3

That worked like a charm, thank you! I was about to go down the WSL2+Ubuntu road as described in your repo, but then noticed a link to this. Saved me a lot of time! :)

markstrefford commented 3 years ago

Thanks for the update.

markstrefford commented 3 years ago

Ah! Fixed it! conda install pywin32 fixes it. Here's my yml file:

name: detectron2
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python=3.8
  - numpy
  - pywin32
  - cudatoolkit=11.0
  - pytorch==1.7.1
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/detectron2.git@v0.3

What compiler did you use? This does not work for me with VS2015 (v140, update 3).

@akkiss You need VS2017 or later

xiezhiyu275 commented 3 years ago

rtx3060 python3.7 pytorch1.7.1 cuda11.1

File "D:\Desktop\detectron2_solov2_six\AdelaiDet-master\detectron2\data__init.py", line 4, in from .build import ( File "D:\Desktop\detectron2_solov2_six\AdelaiDet-master\detectron2\data\build.py", line 12, in from detectron2.structures import BoxMode File "D:\Desktop\detectron2_solov2_six\AdelaiDet-master\detectron2\structures\init.py", line 6, in from .keypoints import Keypoints, heatmaps_to_keypoints File "D:\Desktop\detectron2_solov2_six\AdelaiDet-master\detectron2\structures\keypoints.py", line 6, in from detectron2.layers import interpolate File "D:\Desktop\detectron2_solov2_six\AdelaiDet-master\detectron2\layers\init__.py", line 3, in from .deform_conv import DeformConv, ModulatedDeformConv File "D:\Desktop\detectron2_solov2_six\AdelaiDet-master\detectron2\layers\deform_conv.py", line 10, in from detectron2 import _C ImportError: DLL load failed:

solarflarefx commented 3 years ago

@ppwwyyxx One question I have is that if one gets detectron2 running in Windows on a multi-gpu machine, could that setup work for DDP training? It looks like DDP was added to Windows on PyTorch release 1.7: https://pytorch.org/blog/pytorch-1.7-released/

One question is would anything have to be changed to get train_net.py working? Would you have to force a gloo backend?

henry-luo commented 3 years ago

@xiezhiyu275 I encountered same DLL loading error as you, and have just managed to resolve it. The cause of the problem was that the binary DLLs were not actually properly built.

To build Detectron2 on Windows, you'll need to:

It is important to run vcvars64.bat before running setup.py. Without vcvars64.bat, setup.py will only install the Python files without building the binary DLLs, thus leading to the error.

Can refer to this repo: https://github.com/conansherry/detectron2 for more info.

yogeshkumarpilli commented 3 years ago

Hello If you are facing issues with windows installation, please refer this "https://github.com/yogeshkumarpilli/detectron2/blob/master/README.md" I did it successfully with the latest build version of detectron2 i.e v0.5

Cheers

austinulfers commented 3 years ago

Ah! Fixed it! conda install pywin32 fixes it. Here's my yml file:

name: detectron2
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python=3.8
  - numpy
  - pywin32
  - cudatoolkit=11.0
  - pytorch==1.7.1
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/detectron2.git@v0.3

This worked like a charm for my system which has an RTX 3070.

MilkClouds commented 2 years ago

In Windows 10 after let ninja.exe on PATH, I succeeded installing detectron2 v0.6 I also installed pywin32, and sth else few that I don't remember, but I think it is due to ninja.exe that installation succeeded.

What I have done:

choco install visualstudio2017-workload-vctools
# letting ninja.exe on my path
# cuda 11.3, pytorch 1.10.0
# installed detectron v0.6 by cloning + pip install cloned repository

# I also installed pywin32, but I guess it isn't the component to make detectron installation succeed.

I also executed inference code of videopose3d successfully. no error.

I hope anybody who want to install this on windows got help.

akkiss commented 2 years ago

Also had problems building detectron2 on windows, bottom line is it builds with ninja but does not build without it (see details in #2770).

EtagiBI commented 2 years ago

Here's my environment.yml file:

name: detectron2win
channels:
  - pytorch
  - conda-forge
  - anaconda
  - defaults
dependencies:
  - python=3.7
  - numpy
  - pywin32
  - cudatoolkit=11.3
  - pytorch==1.10.1
  - torchvision
  - git
  - pip
  - pip:
    - git+https://github.com/facebookresearch/detectron2.git@v0.6

When I run conda env create -f environment.yml, I get the following error:

... 
copying detectron2\model_zoo\configs\new_baselines\mask_rcnn_R_50_FPN_50ep_LSJ.py -> build\lib.win-amd64-3.7\detectron2\model_zoo\configs\new_baselines
    running build_ext
    error: [WinError 2] The system cannot find the file specified

failed

CondaEnvException: Pip failed
QQ2737499951 commented 2 years ago

这是来自AAAAAAAAAAAAAA  

EtagiBI commented 2 years ago

I've tried a bunch of different instructions, but still can't get past this build_ext-related error: https://stackoverflow.com/questions/70751751/cant-build-detectron2-on-windows-10

Any help is appreciated!

ouhkedu commented 2 years ago

conda create -n detectron_env python=3.8 conda activate detectron_env pip install cython conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch git clone https://github.com/facebookresearch/detectron2.git cd detectron2 pip install -e . pip install opencv-python conda install pywin32

======Work on my WindowsOS with "cpu" , run underneath code...

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

import cv2 import numpy as np import requests

Load an image

res = requests.get("https://live.staticflickr.com/700/33224654191_fdaee2e3f1_c_d.jpg") image = np.asarray(bytearray(res.content), dtype="uint8") image = cv2.imdecode(image, cv2.IMREAD_COLOR)

config_file = 'COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml' cfg = get_cfg() cfg.merge_from_file(model_zoo.get_config_file(config_file)) cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.75 # Threshold cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url(config_file) cfg.MODEL.DEVICE = "cpu" #"cuda" # cpu or cuda

Create predictor

predictor = DefaultPredictor(cfg)

Make prediction

output = predictor(image) print(output) v = Visualizer(image[:, :, ::-1], scale=0.8, metadata=MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), instance_mode=ColorMode.IMAGE ) v = v.draw_instance_predictions(output["instances"].to("cpu")) cv2.imshow('images', v.get_image()[:, :, ::-1]) cv2.waitKey(0)

QQ2737499951 commented 2 years ago

这是来自AAAAAAAAAAAAAA  

ouhkedu commented 2 years ago

这都是来自BBBBBBBBBBBBBB

khushaljethava commented 1 year ago

Try this one, it works on Windows 10 and 11 for me.

pip install git+https://github.com/khushaljethava/detectron2.git

QQ2737499951 commented 1 year ago

这是来自AAAAAAAAAAAAAA  

MatiasGil88 commented 1 year ago

Try this one, it works on Windows 10 and 11 for me.

pip install git+https://github.com/khushaljethava/detectron2.git

Is there a way you can do a step by step to try this? Does it works with gpu?

QQ2737499951 commented 1 year ago

这是来自AAAAAAAAAAAAAA  

carlosedubarreto commented 1 year ago

Try this one, it works on Windows 10 and 11 for me. pip install git+https://github.com/khushaljethava/detectron2.git

Is there a way you can do a step by step to try this? Does it works with gpu?

Hello @MatiasGil88 , I was able to install detectron2 some time ago using this explanation from stackexchage

https://stackoverflow.com/questions/60631933/install-detectron2-on-windows-10/72784255#72784255

MatiasGil88 commented 1 year ago

Try this one, it works on Windows 10 and 11 for me. pip install git+https://github.com/khushaljethava/detectron2.git

Is there a way you can do a step by step to try this? Does it works with gpu?

Hello @MatiasGil88 , I was able to install detectron2 some time ago using this explanation from stackexchage

https://stackoverflow.com/questions/60631933/install-detectron2-on-windows-10/72784255#72784255

Where you able to use gpu?

carlosedubarreto commented 1 year ago

yep, using cuda 11.7

here are my notes with more information image

MatiasGil88 commented 12 months ago

yep, using cuda 11.7

here are my notes with more information image

Amazing Carlos, huge thanks!!