Giter VIP home page Giter VIP logo

darknet-rust's Introduction

darknet-rust: A Rust bindings for AlexeyAB's Darknet

Crates.io

The crate is a Rust wrapper for AlexeyAB's Darknet.

It provides the following features:

  • Training and inference capabilities.
  • Load config files and model weights from upstream without modifications.
  • Safe type wrappers for C API. Includes network, detection and layer types.

Minimal rustc version: 1.43.0

Version 0.4 changes:

  • updated image to 0.24

Examples

The tiny_yolov3_inference example automatically downloads the YOLOv3 tiny weights, and produces inference results in output directory.

cargo run --release --example tiny_yolov3_inference

The run_inference example is an utility program that you can test a combination of model configs and weights on image files. For example, you can test the YOLOv4 mode.

cargo run --release --example run_inference -- \
    --label-file darknet/data/coco.names \
    --model-cfg darknet/cfg/yolov4.cfg \
    --weights yolov4.weights \
    darknet/data/*.jpg

Read the example code in examples/ to understand the actual usage. More model configs and weights can be found here: (https://pjreddie.com/darknet/yolo/).

Usage

API documentation

If you are using version 0.1, consider migrating to 0.3 or newer as several critical bugs and memory leakages were fixed.

Build

Terms used:

darknet-sys, darknet = Rust wrappers

libdarknet = C/C++ darknet implementation

By default, darknet will compile and link libdarknet statically. You can control the feature flags to change the behavior.

Before running tests:

git submodule init && git submodule update --recursive

Cargo Features

  • enable-cuda: Enable CUDA (expects CUDA 10.x and cuDNN 7.x).
  • enable-cudnn: Enable cuDNN
  • enable-opencv: Enable OpenCV.
  • enable-openmp: Enable OpenMP in darknet. Used for parallelization when running on the CPU. Enabled by default.
  • runtime: Link to libdarknet dynamic library. For example, libdark.so on Linux.
  • dylib: Build dynamic library instead of static
  • buildtime-bindgen: Generate bindings from libdarknet headers.

Method 1: Download and build from source (default)

[dependencies]
darknet = "0.4"

You can optionally enable CUDA and OpenCV features. Please read Build with CUDA for more info.

[dependencies]
darknet = {version = "0.4", features = ["enable-cuda", "enable-opencv"] }

Method 2: Build with custom source

If you want to build with custom libdarknet source, point DARKNET_SRC environment variable to your source path. It should contain CMakeLists.txt.

export DARKNET_SRC=/path/to/your/darknet/repo

Method 3: Link to libdarknet dynamic library

With runtime feature, darknet-sys will not compile libdarknet source code and instead links to libdarknet dynamically. If you are using Linux, make sure libdark.so is installed on your system.

[dependencies]
darknet = {version = "0.4", features = ["runtime"] }

Re-generate bindings

With buildtime-bindgen feature, darknet-sys re-generates bindings from headers. The option is necessary only when darkent is updated or modified.

[dependencies]
darknet = {version = "0.4", features = ["buildtime-bindgen"] }

If you want to use your (possibly modified) header files, point DARKNET_INCLUDE_PATH environment variable to your header dir.

Build with CUDA

Please check that both CUDA 10.x and cuDNN 7.x are installed.

Darknet reads CUDA_PATH environment variable (which defaults to /opt/cuda if not set) and assumes it can find cuda libraries at ${CUDA_PATH}/lib64.

export CUDA_PATH=/usr/local/cuda-10.1
[dependencies]
darknet = {version = "0.4", features = ["enable-cuda", "enable-opencv"] }

You can also set CUDA_ARCHITECTURES which is passed to libdarknet's cmake. It defaults to Auto, which auto-detects GPU architecture based on card present in the system during build.

License

The crate is licensed under MIT.

Credits

Huge thanks to all contributors!

darknet-rust's People

Contributors

alianse777 avatar jerry73204 avatar marcusdunn avatar strohel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.