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
Resilience from Diversity: Population-based approach to harden models against adversarial attacks

Resilience from Diversity: Population-based approach to harden models against adversarial attacks Requirements To install requirements: pip install -r

0 Nov 23, 2021
[ICCV'21] NEAT: Neural Attention Fields for End-to-End Autonomous Driving

NEAT: Neural Attention Fields for End-to-End Autonomous Driving Paper | Supplementary | Video | Poster | Blog This repository is for the ICCV 2021 pap

254 Jan 02, 2023
A scikit-learn-compatible module for estimating prediction intervals.

|Anaconda|_ MAPIE - Model Agnostic Prediction Interval Estimator MAPIE allows you to easily estimate prediction intervals using your favourite sklearn

SimAI 584 Dec 27, 2022
Synthetic LiDAR sequential point cloud dataset with point-wise annotations

SynLiDAR dataset: Learning From Synthetic LiDAR Sequential Point Cloud This is official repository of the SynLiDAR dataset. For technical details, ple

78 Dec 27, 2022
This is 2nd term discrete maths project done by UCU students that uses backtracking to solve various problems.

Backtracking Project Sponsors This is a project made by UCU students: Olha Liuba - crossword solver implementation Hanna Yershova - sudoku solver impl

Dasha 4 Oct 17, 2021
LETR: Line Segment Detection Using Transformers without Edges

LETR: Line Segment Detection Using Transformers without Edges Introduction This repository contains the official code and pretrained models for Line S

mlpc-ucsd 157 Jan 06, 2023
Text Generation by Learning from Demonstrations

Text Generation by Learning from Demonstrations The README was last updated on March 7, 2021. The repo is based on fairseq (v0.9.?). Paper arXiv Prere

38 Oct 21, 2022
A configurable, tunable, and reproducible library for CTR prediction

FuxiCTR This repo is the community dev version of the official release at huawei-noah/benchmark/FuxiCTR. Click-through rate (CTR) prediction is an cri

XUEPAI 397 Dec 30, 2022
TuckER: Tensor Factorization for Knowledge Graph Completion

TuckER: Tensor Factorization for Knowledge Graph Completion This codebase contains PyTorch implementation of the paper: TuckER: Tensor Factorization f

Ivana Balazevic 296 Dec 06, 2022
CMSC320 - Introduction to Data Science - Fall 2021

CMSC320 - Introduction to Data Science - Fall 2021 Instructors: Elias Jonatan Gonzalez and José Manuel Calderón Trilla Lectures: MW 3:30-4:45 & 5:00-6

Introduction to Data Science 6 Sep 12, 2022
Fast Differentiable Matrix Sqrt Root

Official Pytorch implementation of ICLR 22 paper Fast Differentiable Matrix Square Root

YueSong 42 Dec 30, 2022
Repository providing a wide range of self-supervised pretrained models for computer vision tasks.

Hierarchical Pretraining: Research Repository This is a research repository for reproducing the results from the project "Self-supervised pretraining

Colorado Reed 53 Nov 09, 2022
A Python package to create, run, and post-process MODFLOW-based models.

Version 3.3.5 — release candidate Introduction FloPy includes support for MODFLOW 6, MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, and MODFLOW-2000. Other s

388 Nov 29, 2022
[CVPR 2022] CoTTA Code for our CVPR 2022 paper Continual Test-Time Domain Adaptation

CoTTA Code for our CVPR 2022 paper Continual Test-Time Domain Adaptation Prerequisite Please create and activate the following conda envrionment. To r

Qin Wang 87 Jan 08, 2023
Implementation of EMNLP 2017 Paper "Natural Language Does Not Emerge 'Naturally' in Multi-Agent Dialog" using PyTorch and ParlAI

Language Emergence in Multi Agent Dialog Code for the Paper Natural Language Does Not Emerge 'Naturally' in Multi-Agent Dialog Satwik Kottur, José M.

Karan Desai 105 Nov 25, 2022
Pmapper is a super-resolution and deconvolution toolkit for python 3.6+

pmapper pmapper is a super-resolution and deconvolution toolkit for python 3.6+. PMAP stands for Poisson Maximum A-Posteriori, a highly flexible and a

NASA Jet Propulsion Laboratory 8 Nov 06, 2022
Simplified interface for TensorFlow (mimicking Scikit Learn) for Deep Learning

SkFlow has been moved to Tensorflow. SkFlow has been moved to http://github.com/tensorflow/tensorflow into contrib folder specifically located here. T

3.2k Dec 29, 2022
Hi Guys, here I am providing examples, which will help you in Lerarning Python

LearningPython Hi guys, here I am trying to include as many practice examples of Python Language, as i Myself learn, and hope these will help you in t

4 Feb 03, 2022
The code of paper "Block Modeling-Guided Graph Convolutional Neural Networks".

Block Modeling-Guided Graph Convolutional Neural Networks This repository contains the demo code of the paper: Block Modeling-Guided Graph Convolution

22 Dec 08, 2022
Minimal deep learning library written from scratch in Python, using NumPy/CuPy.

SmallPebble Project status: experimental, unstable. SmallPebble is a minimal/toy automatic differentiation/deep learning library written from scratch

Sidney Radcliffe 92 Dec 30, 2022