Search code examples
cdeep-learningdarknet

How to use darknet in my own project?


I have installed Darknet and I can run it from the command line for various tasks, for example:

./darknet classifier train cfg/cifar.data cfg/cifar_small.cfg

This will train a classifier CIFAR data using the network architecture specified in cfg/cifar_small.cfg.

OK, but how to use Darknet in my own C project? For example, I would like to call load_network(), train_network(), save_weights(), and network_predict() declared in darknet.h from within my own code.

Can I use Darknet as a static or a shared library for this? I don't see any instructions on how to do this on the website.

So far the only method I have is creating my own source file in the style of the examples in the examples folder, and modifying darknet.h, darknet.c and Makefile to give myself an entrypoint I can call from the commandline similar to the classifier example I posted above. But this doesn't feel ideal because I'd like to have my own project structure.


Solution

  • OK, it appears that the Makefile supports generating both a shared and a static library, and these are made by default when running the installation:

    git clone https://github.com/pjreddie/darknet.git
    cd darknet
    make
    

    Afterwards libdarknet.a and libdarknet.so appeared in my darknet directiory.

    So I could #include darknet.h in my own project, and then compile via:

    gcc -Wall -o myprog main.c -ldarknet