A dead simple python wrapper for darknet that works with OpenCV 4.1, CUDA 10.1

Overview

What

Dead simple python wrapper for Yolo V3 using AlexyAB's darknet fork. Works with CUDA 10.1 and OpenCV 4.1 or later (I use OpenCV master as of Jun 23, 2019)

Why

  • OpenCV's DNN module, as of today, does not support NVIDIA GPUs. There is a GSOC WIP that will change this. Till then, this library is what I needed.

  • I used Alexy's fork because he keeps it more updated with required changes (like using std++-11 etc.).
    W

  • Other excellent libraries such as pyyolo, Yolo34Py did not work for me with CUDA 10.1 and OpenCV 4.1. They all had compiler issues

How to use this library

By dead simple, I mean dead simple.

  • This module doesn't bother cloning/building darknet. Build it whichever way you want, and simply make libdarknet.so accessible to this module.

  • Modify cfg/coco.data names= to point to where you have the labels (typically coco.names)

  • See example.py

Sample:

import simpleyolo.simpleYolo as yolo

configPath='./cfg/yolov3.cfg'
weightPath='./yolov3.weights'
metaPath='./cfg/coco.data'
imagePath='data/dog.jpg'

# initialize
m = yolo.SimpleYolo(configPath=configPath, 
                    weightPath=weightPath, 
                    metaPath=metaPath, 
                    darknetLib='./libdarknet_gpu.so', 
                    useGPU=True)
print ('detecting...')
detections = m.detect(imagePath)
print (detections)

When to use/not to use

  • Use this library if you want GPU support for YoloV3.
  • DON'T USE THIS LIBRARY if you want CPU support. It will work, but OpenCV's DNN module for YoloV3 is around 10x faster than using darknet directly. Really.
  • On CPU, Intel Xeon 32GB RAM, 4 core, 3.1GHz, OpenCV DNN YoloV3 with blas/atlas takes ~2-4s
  • On CPU, Intel Xeon 32GB RAM, 4 core, 3.1GHz, darkneti YoloV3 takes ~45s (gaah!)
  • BUT, on GPU, NVIDIA GeForce 1050 Ti, 4GB, same CPU, darknet YoloV3 takes 91ms (woot!)

If you really want to know how to get darknet working with OpenCV 4.1

Assuming you have built/installed CUDA/cuDNN and optionally OpenCV 4.1:

git clone https://github.com/AlexeyAB/darknet
cd darknet

Edit the Makefile, set:
GPU=1
CUDNN=1
LIBSO=1

If you want darknet to use OPENCV (not necessary), also set

OPENCV=1 

Notes:

  • You will make to change the Makefile to change pkg-config --libs opencv to pkg-config --libs opencv4 (2 instances). This will not be needed after Alexy fixes this issue

  • The above will only work if you previously compiled OpenCV 4+ with OPENCV_GENERATE_PKGCONFIG=ON and then copied the generated pc file like so: sudo cp unix-install/opencv4.pc /usr/lib/pkgconfig/

Pretty, please, how do we build OpenCV 4.1 with CUDA 10.1?

Assuming you have built/installed CUDA/cuDNN:

git clone https://github.com/opencv/opencv
git clone https://github.com/opencv/opencv_contrib
cd opencv
mkdir build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
        -D CMAKE_INSTALL_PREFIX=/usr/local \
        -D PYTHON_DEFAULT_EXECUTABLE=$(which python3) \
        -D INSTALL_PYTHON_EXAMPLES=OFF \
        -D INSTALL_C_EXAMPLES=OFF \
        -D OPENCV_ENABLE_NONFREE=ON \
        -D OPENCV_EXTRA_MODULES_PATH=/home/pp/opencv_contrib/modules \
        -D BUILD_EXAMPLES=OFF \
        -D WITH_CUDA=ON \
        -D ENABLE_FAST_MATH=ON \
        -D CUDA_FAST_MATH=ON \
        -D WITH_CUBLAS=ON \
        -D WITH_OPENCL=ON \
        -D BUILD_opencv_cudacodec=OFF \
        -D BUILD_opencv_world=OFF \
        -D WITH_NVCUVID=OFF \
        -D WITH_OPENGL=ON \
        -D BUILD_opencv_python3=ON \
        -D OPENCV_GENERATE_PKGCONFIG=ON \
        ..
make -j$(nproc)
sudo make install

# don't forget this, for darknet and other libs to find opencv4 later
sudo cp unix-install/opencv4.pc /usr/lib/pkgconfig/

Pretty pretty please, how do I build CUDA 10.1 and nvidia drivers?

Maybe later.

Owner
Pliable Pixels
I code like a Kindergartner
Pliable Pixels
Keyword2Text This repository contains the code of the paper: "A Plug-and-Play Method for Controlled Text Generation"

Keyword2Text This repository contains the code of the paper: "A Plug-and-Play Method for Controlled Text Generation", if you find this useful and use

57 Dec 27, 2022
Official PyTorch Implementation of Convolutional Hough Matching Networks, CVPR 2021 (oral)

Convolutional Hough Matching Networks This is the implementation of the paper "Convolutional Hough Matching Network" by J. Min and M. Cho. Implemented

Juhong Min 70 Nov 22, 2022
N-RPG - Novel role playing game da turfu

N-RPG Ce README sera la page de garde du projet. Contenu Il contiendra la présen

4 Mar 15, 2022
Unofficial PyTorch implementation of MobileViT based on paper "MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer".

MobileViT RegNet Unofficial PyTorch implementation of MobileViT based on paper MOBILEVIT: LIGHT-WEIGHT, GENERAL-PURPOSE, AND MOBILE-FRIENDLY VISION TR

Hong-Jia Chen 91 Dec 02, 2022
This repo implements several applications of the proposed generalized Bures-Wasserstein (GBW) geometry on symmetric positive definite matrices.

GBW This repo implements several applications of the proposed generalized Bures-Wasserstein (GBW) geometry on symmetric positive definite matrices. Ap

Andi Han 0 Oct 22, 2021
PyTorch implementation for COMPLETER: Incomplete Multi-view Clustering via Contrastive Prediction (CVPR 2021)

Completer: Incomplete Multi-view Clustering via Contrastive Prediction This repo contains the code and data of the following paper accepted by CVPR 20

XLearning Group 72 Dec 07, 2022
A Model for Natural Language Attack on Text Classification and Inference

TextFooler A Model for Natural Language Attack on Text Classification and Inference This is the source code for the paper: Jin, Di, et al. "Is BERT Re

Di Jin 418 Dec 16, 2022
The Python3 import playground

The Python3 import playground I have been confused about python modules and packages, this text tries to clear the topic up a bit. Sources: https://ch

Michael Moser 5 Feb 22, 2022
This repository is a basic Machine Learning train & validation Template (Using PyTorch)

pytorch_ml_template This repository is a basic Machine Learning train & validation Template (Using PyTorch) TODO Markdown 사용법 Build Docker 사용법 Anacond

1 Sep 15, 2022
Official implementation of "Articulation Aware Canonical Surface Mapping"

Articulation-Aware Canonical Surface Mapping Nilesh Kulkarni, Abhinav Gupta, David F. Fouhey, Shubham Tulsiani Paper Project Page Requirements Python

Nilesh Kulkarni 56 Dec 16, 2022
Fast Neural Style for Image Style Transform by Pytorch

FastNeuralStyle by Pytorch Fast Neural Style for Image Style Transform by Pytorch This is famous Fast Neural Style of Paper Perceptual Losses for Real

Bengxy 81 Sep 03, 2022
PyTorch implementation of the Quasi-Recurrent Neural Network - up to 16 times faster than NVIDIA's cuDNN LSTM

Quasi-Recurrent Neural Network (QRNN) for PyTorch Updated to support multi-GPU environments via DataParallel - see the the multigpu_dataparallel.py ex

Salesforce 1.3k Dec 28, 2022
Graph Self-Attention Network for Learning Spatial-Temporal Interaction Representation in Autonomous Driving

GSAN Introduction Code for paper GSAN: Graph Self-Attention Network for Learning Spatial-Temporal Interaction Representation in Autonomous Driving, wh

YE Luyao 6 Oct 27, 2022
Adversarially Learned Inference

Adversarially Learned Inference Code for the Adversarially Learned Inference paper. Compiling the paper locally From the repo's root directory, $ cd p

Mohamed Ishmael Belghazi 308 Sep 24, 2022
Official implementation for the paper: "Multi-label Classification with Partial Annotations using Class-aware Selective Loss"

Multi-label Classification with Partial Annotations using Class-aware Selective Loss Paper | Pretrained models Official PyTorch Implementation Emanuel

99 Dec 27, 2022
Codebase for Attentive Neural Hawkes Process (A-NHP) and Attentive Neural Datalog Through Time (A-NDTT)

Introduction Codebase for the paper Transformer Embeddings of Irregularly Spaced Events and Their Participants. This codebase contains two packages: a

Alan Yang 28 Dec 12, 2022
A time series processing library

Timeseria Timeseria is a time series processing library which aims at making it easy to handle time series data and to build statistical and machine l

Stefano Alberto Russo 11 Aug 08, 2022
Real-Time High-Resolution Background Matting

Real-Time High-Resolution Background Matting Official repository for the paper Real-Time High-Resolution Background Matting. Our model requires captur

Peter Lin 6.1k Jan 03, 2023
CoaT: Co-Scale Conv-Attentional Image Transformers

CoaT: Co-Scale Conv-Attentional Image Transformers Introduction This repository contains the official code and pretrained models for CoaT: Co-Scale Co

mlpc-ucsd 191 Dec 03, 2022
Consensus Learning from Heterogeneous Objectives for One-Class Collaborative Filtering

Consensus Learning from Heterogeneous Objectives for One-Class Collaborative Filtering This repository provides the source code of "Consensus Learning

SeongKu-Kang 6 Apr 29, 2022