Running YOLO v2 on the Microsoft Data Science Virtual Machine
This week I attended the Industry Partner workshop at the Future of Infrastructure and Built Environment at the University of Cambridge. During the day I had a number of conversations with construction industry professionals and one of the topics we got into talking about how technology from HoloLens, to Data Science is revolutionising the construction industry.
During the breakouts we got into a discussion around the automation and monitoring of works on constructions sites from using tools such as Deep Learning to simply having drones or video capturing and analysing images of progress.
I remembered seeing an a article around this a few years ago, which showed the work from the University of Illinois one of the Project involves tracking the activity of individual construction workers in video footage https://www.technologyreview.com/s/540836/new-boss-on-construction-sites-is-a-drone/ but a huge downfall for the system was that the data and output was simply not in real time.
Improvement in Deep Learning
We then got into the discussion of how modern day technology and services make ML, AI so much more accessible and significantly improve the success of object and activity identification and recognition in real time. One of my colleagues Jamie Dalton is very much into this space and a recent tool he has been using is called YOLO You only look once, which you can run on Azure Deep Learning Virtual Machine Deep Learning Virtual Machine.
So what is YOLO
YOLO is a state of the art real-time object detection system that works using what I can only describe as amazing. Jamie has been doing some amazing work with YOLO and you can see this at his blog https://blogs.msdn.microsoft.com/jamiedalton
With the Azure's Deep Learning Virtual Machine (DLVM) with GPU its super easy for student and academic to now setup a real time detection system and thanks to the work Jamie has been doing here is a quick guide to getting your own DLVM setup working with YOLO.
All students now get a FREE Azure Account with no credit card required which give $100 of Azure credit so this is great way to try a small experiment into deep learning https://aka.,ms/azure4students
In the Azure Portal, create a Deep Learning Virtual Machine (DVLM) NC-Series GPU on Windows (Linux also available). Once provisioned, you can RDP into the environment and complete your image/object recognition projects, if you want to spin up a standalone new VM there are numerous guides out there to walk through setting up a Windows development environment for YOLO. I strongly encourage you to read the following first: https://pjreddie.com/darknet/ and https://github.com/AlexeyAB/darknet/blob/master/README.md.
The DVLM has a bucket load of tools already installed on it. However, there are a few updates and additional libraries you need to install to get YOLO up and running.
- Update the Visual Studio Installer
- Update Visual Studio Community 2017 (currently v15.6.4)
- Add the VC++ 2017 version 14.4 v14.11 toolset (for side by side MSVC toolsets: https://blogs.msdn.microsoft.com/vcblog/2017/11/15/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2017/)
- Download OpenCV 3.40 (not higher as it won't work: https://github.com/AlexeyAB/darknet/issues/402) and extract to the path c:\opencv_3.0
- Install CUDA 9.1 https://developer.nvidia.com/cuda-downloads (Windows 2016 version for DLVM)
Please note: If you get the error "CUDA Error: CUDA driver version is insufficient for CUDA runtime version" when running the darknet.exe.
You simply need to re-install CUDA again
- Your environment variables should look like the below including CUDNN (as per: https://github.com/AlexeyAB/darknet/blob/master/README.md#how-to-compile-on-windows) which is already installed on the DLVM at the path C:\NVIDIA\cuda. You'll also need to add a system variable for OPENCV_DIR to C:\opencv_3.0\opencv\build
- Tweak the C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include\crt\host_config.h file to update it with the latest VS version eg:
- Clone AlexyAB's fork of the darknet repo: https://github.com/AlexeyAB/darknet.git
- Copy the C:\Program Files (x86)\Microsoft Visual Studio\Preview\Community\VC\Auxiliary\Build\14.11\ props file to the darknet\build\darknet solution folder eg:
- Edit the darknet.vcxproj file to include the v14.11.props file copied above (again ref: https://blogs.msdn.microsoft.com/vcblog/2017/11/15/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2017/)
- Open the darknet.sln solution - retarget the project
- Build (Release x64 bit)
- Open the solution/x64 output directory and you should see darknet.exe
- Copy the OpenCV dependencies into the output directory above:
- Download the YOLO9000 weights: https://pjreddie.com/media/files/yolo9000.weights
- Run solution/x64/darknet_coco_9000.cmd
Learning more about YOLO and getting started tutorials
There some great tutorials at https://www.youtube.com/watch?v=PyjBd7IDYZs&list=PLX-LrBk6h3wSGvuTnxB2Kj358XfctL4BM