Giter VIP home page Giter VIP logo

go-darknet's Introduction

GoDoc Sourcegraph Go Report Card GitHub tag

go-darknet: Go bindings for Darknet (Yolo V4, Yolo V7-tiny, Yolo V3)

go-darknet is a Go package, which uses Cgo to enable Go applications to use V4/V7-tiny/V3 in Darknet.

Since this repository https://github.com/gyonluks/go-darknet is no longer maintained I decided to move on and make little different bindings for Darknet.

This bindings aren't for official implementation but for AlexeyAB's fork.

Paper Yolo v7: https://arxiv.org/abs/2207.02696 (WARNING: Only 'tiny' variation works currently)

Table of Contents

Why

Why does this repository exist?

Because this repository https://github.com/gyonluks/go-darknet is no longer maintained.

What is purpose of this bindings when you can have GoCV (bindings to OpenCV) and it handle Darknet YOLO perfectly?

Well, you don't need bunch of OpenCV dependencies and OpenCV itself sometimes.

Example of such project here: https://github.com/LdDl/license_plate_recognition#license-plate-recognition-with-go-darknet---- .

Requirements

You need to install fork of darknet. Latest commit I've tested is here. It corresponds last official YOLOv4 release

Use provided Makefile.

  • For CPU-based instalattion:

    make install_darknet
  • For both CPU and GPU-based instalattion if you HAVE CUDA installed:

    make install_darknet_gpu

    Note: I've tested CUDA 10.2 and cuDNN is 7.6.5)

  • For both CPU and GPU-based instalattion if you HAVE NOT CUDA installed:

    make install_darknet_gpu_cuda

    Note: There is some struggle in Makefile for cuDNN, but I hope it works in Ubuntu atleast. Do not forget provide proper CUDA and cuDNN versions.

Installation

go get github.com/LdDl/go-darknet

Usage

Example Go program is provided in the examples directory. Please refer to the code on how to use this Go package.

Building and running program:

  • Navigate to examples folder

    cd ${YOUR PATH}/github.com/LdDl/go-darknet/cmd/examples
  • Download dataset (sample of image, coco.names, yolov4.cfg (or v3), yolov4.weights(or v3)).

    #for yolo v4
    ./download_data.sh
    #for yolo v4 tiny
    ./download_data_v4_tiny.sh
    #for yolo v7 tiny
    ./download_data_v7_tiny.sh
    #for yolo v3
    ./download_data_v3.sh
  • Note: you don't need coco.data file anymore, because sh-script above does insert coco.names into 'names' field in yolov4.cfg file (so AlexeyAB's fork can deal with it properly) So last rows in yolov4.cfg file will look like:

    ......
    [yolo]
    .....
    iou_loss=ciou
    nms_kind=greedynms
    beta_nms=0.6
    
    names = coco.names # this is path to coco.names file
  • Also do not forget change batch and subdivisions sizes from:

    batch=64
    subdivisions=8

    to

    batch=1
    subdivisions=1

    It will reduce amount of VRAM used for detector test.

  • Build and run example program

    Yolo v7 tiny:

    go build -o base_example/main base_example/main.go && ./base_example/main --configFile=yolov7-tiny.cfg --weightsFile=yolov7-tiny.weights --imageFile=sample.jpg

    Output should be something like this:

    truck (7): 53.2890% | start point: (0,143) | end point: (89, 328)
    truck (7): 42.1364% | start point: (685,182) | end point: (800, 318)
    truck (7): 26.9703% | start point: (437,170) | end point: (560, 217)
    car (2): 87.7818% | start point: (509,189) | end point: (742, 329)
    car (2): 87.5633% | start point: (262,191) | end point: (423, 322)
    car (2): 85.4743% | start point: (427,198) | end point: (549, 309)
    car (2): 71.3772% | start point: (0,147) | end point: (87, 327)
    car (2): 62.5698% | start point: (98,151) | end point: (197, 286)
    car (2): 61.5811% | start point: (693,186) | end point: (799, 316)
    car (2): 49.6343% | start point: (386,206) | end point: (441, 286)
    car (2): 28.2012% | start point: (386,205) | end point: (440, 236)
    bicycle (1): 71.9609% | start point: (179,294) | end point: (249, 405)
    person (0): 85.4390% | start point: (146,130) | end point: (269, 351)

    Yolo v4:

    go build -o base_example/main base_example/main.go && ./base_example/main --configFile=yolov4.cfg --weightsFile=yolov4.weights --imageFile=sample.jpg

    Output should be something like this:

    traffic light (9): 73.5040% | start point: (238,73) | end point: (251, 106)
    truck (7): 96.6401% | start point: (95,79) | end point: (233, 287)
    truck (7): 96.4774% | start point: (662,158) | end point: (800, 321)
    truck (7): 96.1841% | start point: (0,77) | end point: (86, 333)
    truck (7): 46.8694% | start point: (434,173) | end point: (559, 216)
    car (2): 99.7370% | start point: (512,188) | end point: (741, 329)
    car (2): 99.2532% | start point: (260,191) | end point: (422, 322)
    car (2): 99.0333% | start point: (425,201) | end point: (547, 309)
    car (2): 83.3920% | start point: (386,210) | end point: (437, 287)
    car (2): 75.8621% | start point: (73,199) | end point: (102, 274)
    car (2): 39.1925% | start point: (386,206) | end point: (442, 240)
    bicycle (1): 76.3121% | start point: (189,298) | end point: (253, 402)
    person (0): 97.7213% | start point: (141,129) | end point: (283, 362)

    Yolo v4 tiny:

    go build -o base_example/main base_example/main.go && ./base_example/main --configFile=yolov4-tiny.cfg --weightsFile=yolov4-tiny.weights --imageFile=sample.jpg

    Output should be something like this:

    truck (7): 77.7936% | start point: (0,138) | end point: (90, 332)
    truck (7): 55.9773% | start point: (696,174) | end point: (799, 314)
    car (2): 53.1286% | start point: (696,184) | end point: (799, 319)
    car (2): 98.0222% | start point: (262,189) | end point: (424, 330)
    car (2): 97.8773% | start point: (430,190) | end point: (542, 313)
    car (2): 81.4099% | start point: (510,190) | end point: (743, 325)
    car (2): 43.3935% | start point: (391,207) | end point: (435, 299)
    car (2): 37.4221% | start point: (386,206) | end point: (429, 239)
    car (2): 32.0724% | start point: (109,196) | end point: (157, 289)
    person (0): 73.0868% | start point: (154,132) | end point: (284, 382)

    Yolo V3:

    go build main.go && ./main --configFile=yolov3.cfg --weightsFile=yolov3.weights --imageFile=sample.jpg
    

    Output should be something like this:

    truck (7): 49.5123% | start point: (0,136) | end point: (85, 311)
    car (2): 36.3694% | start point: (95,152) | end point: (186, 283)
    truck (7): 48.4177% | start point: (95,152) | end point: (186, 283)
    truck (7): 45.6520% | start point: (694,178) | end point: (798, 310)
    car (2): 76.8402% | start point: (1,145) | end point: (84, 324)
    truck (7): 25.5920% | start point: (107,89) | end point: (215, 263)
    car (2): 99.8782% | start point: (511,185) | end point: (748, 328)
    car (2): 99.8193% | start point: (261,189) | end point: (427, 322)
    car (2): 99.6405% | start point: (426,197) | end point: (539, 311)
    car (2): 74.5627% | start point: (692,186) | end point: (796, 316)
    car (2): 72.7975% | start point: (388,206) | end point: (437, 276)
    bicycle (1): 72.2760% | start point: (178,270) | end point: (268, 406)
    person (0): 97.3007% | start point: (143,135) | end point: (268, 343)

Documentation

See go-darknet's API documentation at GoDoc.

License

go-darknet follows Darknet's license.

go-darknet's People

Contributors

lddl avatar lucmski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-darknet's Issues

[BUG] - `make install_darknet` task fails on macOS 12.1

Describe the bug
First of all, thanks for this repo! You've done a lot of amazing work that I'm excited to use!
I am not sure if this is a bug or a mismatch in system compatibilities. It could also just be some github hiccup and in that case, my apologies for posting this here but I would appreciate any help! The issue seems to be that the reference to darknet repo at commit f056fc3b6a11528fa0522a468eca1e909b7004b7 is not a tree.

Command:

make install_darknet

Result:

rm -rf /tmp/install_darknet
mkdir /tmp/install_darknet
git clone https://github.com/AlexeyAB/darknet.git /tmp/install_darknet
Cloning into '/tmp/install_darknet'...
remote: Enumerating objects: 15386, done.
remote: Total 15386 (delta 0), reused 0 (delta 0), pack-reused 15386
Receiving objects: 100% (15386/15386), 14.01 MiB | 2.00 MiB/s, done.
Resolving deltas: 100% (10345/10345), done.
cd /tmp/install_darknet
git checkout f056fc3b6a11528fa0522a468eca1e909b7004b7
fatal: reference is not a tree: f056fc3b6a11528fa0522a468eca1e909b7004b7
make: *** [download_darknet] Error 128

To Reproduce

  1. git clone [email protected]:LdDl/go-darknet.git
  2. cd go-darknet/
  3. make install_darknet

Expected behavior
Darknet compiles correctly

Describe the solution you'd like and provide pseudocode examples if you can
If there are any workarounds to this issue on my system or glaring git mishaps occurring, I would love to know more in hopes that this issue helps others encountering this issue.

EDIT:
I just went back over the README and noticed a potential issue. It states that the most recent battle-tested commit of the forked darknet is what go-darknet is using to build but while taking a peek in the Makefile, the LATEST_COMMIT variable is set to f056fc3b6a11528fa0522a468eca1e909b7004b7 which is not the same hash as the commit in the README. That hash is d65909fbea471d06e52a2e4a41132380dc2edaa6 and when attempting to change the LATEST_COMMIT variable to this hash, I get the same issue.

EDIT:
The trouble command is when the Makefile runs git checkout $(LATEST_COMMIT) but when navigating to the /tmp/install_darknet directory and running the command manually, it switches refs just fine.

rest api example

Hi,

Hope you are all well !

Is it possible to provide an example of rest api receiving either url or body image ? That would be awesome addition.

Cheers,
X

[BUG] 为什么检测一次很慢,大概再6-10秒左右,yolov5大概再20ms左右

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior

Expected behavior
A clear and concise description of what you expected to happen.

Expected behavior
A clear and concise description of what you expected to happen.

Describe the solution you'd like and provide pseudocode examples if you can
A clear and concise description of what you want to happen.

Additional context
Add any other context about the problem here.

Segmentation Violation

I went into segmentation violation while running detection.

then I located it happened in following line:

network_predict_ptr(n, sized.data); in line 17, network.c

I simply switch it to network_predict_image(n, sized); and it works fine

here's the segmentation error that I got before the change

`fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x2 addr=0x7f87d443c000 pc=0x7f8a45518d8f]

runtime stack:
runtime.throw(0x53d64e, 0x2a)
/usr/local/go/src/runtime/panic.go:1116 +0x72
runtime.sigpanic()
/usr/local/go/src/runtime/signal_unix.go:679 +0x46a

goroutine 1 [syscall]:
runtime.cgocall(0x4f04f0, 0xc00006dbc0, 0xc00007a028)
/usr/local/go/src/runtime/cgocall.go:133 +0x5b fp=0xc00006db90 sp=0xc00006db58 pc=0x405b3b
github.com/LdDl/go-darknet._Cfunc_perform_network_detect(0x116e1f0, 0xc00007a028, 0x3e80000000000001, 0x3ee666663f000000, 0x0, 0x0, 0x0)
_cgo_gotypes.go:869 +0x4d fp=0xc00006dbc0 sp=0xc00006db90 pc=0x4cd2dd
github.com/LdDl/go-darknet.(*YOLONetwork).Detect.func1(0xc00006de78, 0xc00007a000, 0x0, 0x0)
/home/idx/go/src/github.com/LdDl/go-darknet/network.go:72 +0x117 fp=0xc00006dc30 sp=0xc00006dbc0 pc=0x4cf5b7
github.com/LdDl/go-darknet.(*YOLONetwork).Detect(0xc00006de78, 0xc00007a000, 0xc00007a000, 0x0, 0x0)
/home/idx/go/src/github.com/LdDl/go-darknet/network.go:72 +0x8e fp=0xc00006dd40 sp=0xc00006dc30 pc=0x4cec1e
main.main()
/home/idx/go/src/github.com/LdDl/go-darknet/example/main.go:66 +0x339 fp=0xc00006df88 sp=0xc00006dd40 pc=0x4ef9a9
runtime.main()
/usr/local/go/src/runtime/proc.go:203 +0x1fa fp=0xc00006dfe0 sp=0xc00006df88 pc=0x4353ea
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1373 +0x1 fp=0xc00006dfe8 sp=0xc00006dfe0 pc=0x45fb71
exit status 2`

[FEATURE REQUEST] Update to stable YOLO v4

Is your feature request related to a problem? Please describe.
Latest commit I've used: f056fc3b6a11528fa0522a468eca1e909b7004b7

But there is a new stable release of YOLO v4 (29th October 2021):
https://github.com/AlexeyAB/darknet/releases/tag/yolov4

Describe the solution you'd like and provide pseudocode examples if you can
Need to:

  • change Makefile to latest stable commit of AlexeyAB's repository.
  • check examples work
  • check CGO code (refactor if needed)
  • check for memory leaks (I can use valgrind)

Describe alternatives you've considered and provide pseudocode examples if you can
nope

Additional context
nope

Custom yolov7 pytorch

Hello!
Is there any way to use custom yolov7-tiny models trained with the official PyTorch repo?
I imagine I need to translate from .pt to .weights format, any hint on how to do that?

[QUESTION] Go-Darknet for Windows

Hey!
Did you also test this on Windows? I just tried implementing this into my Go-Project but it doesn't seem to work. First problem was that he couldn't find the <darknet.h> file. I think I solved this by changing the cgo include paths to the path where the darknet repository is located. on my Windows PC. However when I'm trying to run it, it always exits with status code 3221225781. According to my research this means that some form of dll is missing?
I can't really debug or find out what really causes this issue.

Do you maybe have an idea on how to fix the issue?
Kind regards :)

[BUG] Build error on golang:1.15.7-alpine3.13 docker image

Describe the bug
#20 4.538 vendor/github.com/LdDl/go-darknet/network.go:61:2: could not determine kind of name for C.free_network_ptr

To Reproduce
Docker: golang:1.15.7-alpine3.13
Run: CGO_ENABLED=1 go install -v -a --installsuffix --ldflags="-s"

Expected behavior
#20 4.538 vendor/github.com/LdDl/go-darknet/network.go:61:2: could not determine kind of name for C.free_network_ptr

[BUG] - when running example code on Mac 12.1 - fatal error: unexpected signal during runtime execution

Describe the bug
Darknet built successfully.
The issue occurs when testing the repo with the sample:

go build main.go && ./main --configFile=../yolov4.cfg --weightsFile=../yolov4.weights --imageFile=../sample.jpg

The net builds but fails on the detection step in the network.c file with the following error:

atal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x537750000 pc=0x442fccd]

Specifically, the code fails on network_predict_ptr(n, sized.data);.

To Reproduce
Run the example code on mac.

Expected behavior
An image with bounding boxes is generated

Describe the solution you'd like and provide pseudocode examples if you can
It would be nice to know if this is mac related or an OS-agnostic issue. If mac-related, I will perform additional diagnostics. If not then direction towards a solution would be greatly appreciated.

[FEATURE REQUEST] Installation script

Is your feature request related to a problem? Please describe.
It would be good to have bash/makefile script for installation of darknet.

Describe the solution you'd like and provide pseudocode examples if you can
Prepare build-file (for cpu-only/ cpu+gpu).

Describe alternatives you've considered and provide pseudocode examples if you can

Additional context
I prefer Makefile
Sure this would be good for Linux users.
Additionally we can have *.bat file for Windows users.

[BUG] memory leak on perform_network_detect C function

Describe the bug
Memory doesn't free at the perform_network_detect function. Precisely at the network_predict and get_network_boxes calls.

To Reproduce

Software Versions:

go version 1.15.6
go-darknet v1.3.0

Model:

yolov4-tiny.cfg
yolov4_tiny.weights
https://github.com/AlexeyAB/darknet/archive/darknet_yolo_v4_pre.zip 

Snnipet:

imgDarknet, err := darknet.Image2Float32(src)
if err != nil {
    return nil, err
}
	
dr, err := Network.Detect(imgDarknet)
if err != nil {
     return nil, err
}

docker container [feature request]

Hi,

Hope you are all well !

It would be interesting to have a docker container for building and linking darknet. Isn't it ?

Cheers,
X

crop the bounding box content

Hi,

Again ! :-)

I was wondering if there is a function to crop the content of the bounding box in separate pictures ?

Cheers,
X.

[BUG] yolov4 tiny example produces fatal error: unexpected signal during runtime execution

Running the example like stated in the readme will produce a "fatal error: unexpected signal during runtime execution.

To Reproduce
cd cmd/examples
./download_data_v4_tiny.sh
go build -o base_example/main base_example/main.go && ./base_example/main --configFile=yolov4-tiny.cfg --weightsFile=yolov4-tiny.weights --imageFile=sample.jpg

go version: go version go1.19 linux/amd64
Expected behavior
Output as expected

Describe the solution you'd like and provide pseudocode examples if you can
Would love to see it working again, a lot of love for this project.

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.