How to run Facebook AI’s Detectron2 (or any other GUI based program) on Windows Subsystem for Linux (WSL1 or WSL2)

Mohamed Faizan Cassim
3 min readJan 29, 2021

Many of you must have gone through many of the draw backs of dual booting or installing Linux on a virtual machine, whenever you have a project that needs the use of Linux (Ubuntu,Mint, Kali etc.). One of the major drawbacks of using virtual machines: is the need to re-setup the virtual machine, when ever you run out of free storage in the VM and the other main drawback being the difficult process of the transfer of files between your Windows Machine and Linux (without the use of your USB drive).

Windows Subsystem for Linux (WSL1/WSL2) is the solution for all this, but how does one run GUI based apps on a system that only seems to support a Command Line Interface? The answer to that is the X windowing system. The aim of this article is to show how easy it is to set up and run OpenCV (Such as FBAI’s Detectron2) based apps in WSL.

Screenshot of WSL/WSL2

Installation and setup of OpenCV

The installation and setup of OpenCV on WSL/WSL2 is just like any other installation of Linux. However, if you have not done this before, the steps given bellow will give a good idea of how this should be done.

1. Install the build-essential tools; a software toolset that consists of gcc, g++ and cmake, using the following command: sudo apt install build-essential.

2. Install the latest version of python: sudo apt install python3.9 (could be different if newer version available).

3. Download the opencv and opencv_contrib repositories from the OpenCV GitHub page (https://github.com/opencv/).

4. Follow this tutorial for a comprehensive guide on building OpenCV on Linux: https://docs.opencv.org/master/d2/de6/tutorial_py_setup_in_ubuntu.html.

5. (Optional) If you want to set up the opencv_contrib libraries, then launch cmake similar to the following: cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-master/modules ../opencv-master (Link: https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html)

Note: There is no space between ‘-DOPENCV_EXTRA_MODULES_PATH=’ and ‘../opencv_contrib-master’.

Installation and Setup of PyTorch

PyToch is a computer vision library for python that has a C++ backend; the process of training and running neural networks pretty fast. In order to install PyToch on WSL/WSL2, visit https://pytorch.org/get-started/locally/ and follow the instructions. Select Stable | Linux | Pip |Python | Cuda (If you got an Nvidia Graphics Card) for a straightforward install.

PyTorch Download Tool

Installing and Setting up detectron2.

The Facebook AI’s Detectron 2 libarary can be installed by following the instructions mentioned here: https://detectron2.readthedocs.io/en/latest/tutorials/install.html. The exact installation that you choose can vary based on your computer setup.

Finally, Installing VcXsrv and setting up the x-windowing system.

Download VcXsrv on your Windows 10 machine from the following link: shorturl.at/suyBI. Then start your respective WSL/WSL2 app and enter the following command:

export DISPLAY=:0

Then start vcxsrv.exe and then you can run your GUI based application.

The Result

Screenshot of Detectron2 Keypoints Detection running on WSL.

--

--

Mohamed Faizan Cassim

Robotics Engineer from Kolonnawa, Sri Lanka. Lived in 4 different countries and been to 6. Programing: C, C++, C# and Python (beginner at Rust).