Facebook AI Research recently released Detectron2, their next generation software system that implements state-of-the-art object detection algorithms.
Although it is built using a Windows pipeline, there is no official support for it on Windows. There are versions of Detectron2 available for Windows, but at the time of writing, these are older versions of the code and have been modified to remove Linux specific code and replace it with Windows specific code. This means you lose out on later features, bug fixes, improvements, etc. that Facebook include.
This tutorial shows how to get the latest version of Detectron2 working on Windows using WSL2 (Windows Subsystem for Linux), and includes steps for running this on the latest NVidia RTX30xx cards.
In addition, I'll show you how to call Detectron2 running inside WSL2 from Anaconda running natively within Windows.
This tutorial has been tested on the following PC build:
For this, we will install:
Most of this information is available on the Microsoft and Nvidia websites, with some information buried in responses to issues on a number of forums, so for those of you wanting to do this, here's all the information in one place.
Note that for this tutorial, I'm assuming that you already have a good understanding of Windows, Linux and Python.
There are now 2 approches for installing below:
There's also a section on calling Detectron2 using a RESTful API.
If you have any issues with this, or over time the instructions change, please raise an issue stating the following:
nvidia-smi
from within Ubuntu. You should see the usage statistics for your GPU.conda
instructions below, use pip
if you need to):
conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch
conda install -c conda-forge pycocotools
import torch
torch.cuda.is_available()
should return True
. If you get false, please revisit the above steps.import pycocotools
import detectron2
from within Python.If you've got this far, then Detectron2 is installed and ready for you to use.
Detectron2, at the time of writing, does not have a native API. This is simple to setup using Flask. You can of course import detectron2
into your code directly, but if you want to move to an API based approach, here's an example of how to get this working.
Optional If you want to run Anaconda in Windows and call Detectron2 in Ubuntu, then you'll need to get the internal IP address of your Ubuntu container using ipconfig
. On my system, I used the IP address of the eth0
adapter, which was of the format 172.x.x.x
. Note this IP address can change between reboots.
I've provided an example script to get you started. Note that this isn't production ready, it's purely for development and test purposes. This example code isn't designe to handle multiple concurrent requests, etc.
To call the API, please see this notebook. For information on the output format of the API, please read the Detectron2 documentation.
You'll notice that these scripts use the Blosc library. This is to facilitate transfering binary (image) data over HTTP inside a JSON request/response.
Note that you will need Cuda 11.2 or later and Visual Studio 2017-2019 (Inclusive)
A conda YML file for install directly into Conda on Windows can be found here:
https://github.com/facebookresearch/detectron2/issues/9#issuecomment-781301784
Thanks to @b_pronod for helping with the WSL2 and CUDA setup.