Skip to content

Commit 5522102

Browse files
authored
Merge pull request #13 from LdDl/install-darknet
makefile and minor
2 parents c9bbd3e + e0a6735 commit 5522102

File tree

2 files changed

+148
-102
lines changed

2 files changed

+148
-102
lines changed

Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.ONESHELL:
2+
.PHONY: download build clean
3+
4+
# Latest battletested AlexeyAB version of Darknet commit
5+
LATEST_COMMIT?=d65909fbea471d06e52a2e4a41132380dc2edaa6
6+
7+
# Temporary folder for building Darknet
8+
TMP_DIR?=/tmp/
9+
10+
# Download AlexeyAB version of Darknet
11+
download:
12+
rm -rf $(TMP_DIR)install_darknet
13+
mkdir $(TMP_DIR)install_darknet
14+
git clone https://github.com/AlexeyAB/darknet.git $(TMP_DIR)install_darknet
15+
cd $(TMP_DIR)install_darknet
16+
git checkout $(LATEST_COMMIT)
17+
cd -
18+
19+
# Build AlexeyAB version of Darknet for usage with CPU only.
20+
build:
21+
cd $(TMP_DIR)install_darknet
22+
sed -i -e 's/GPU=1/GPU=0/g' Makefile
23+
sed -i -e 's/CUDNN=1/CUDNN=0/g' Makefile
24+
sed -i -e 's/LIBSO=0/LIBSO=1/g' Makefile
25+
$(MAKE) -j $(shell nproc --all)
26+
$(MAKE) preinstall
27+
cd -
28+
29+
# Build AlexeyAB version of Darknet for usage with both CPU and GPU (CUDA by NVIDIA).
30+
build_gpu:
31+
cd $(TMP_DIR)install_darknet
32+
sed -i -e 's/GPU=0/GPU=1/g' Makefile
33+
sed -i -e 's/CUDNN=0/CUDNN=1/g' Makefile
34+
sed -i -e 's/LIBSO=0/LIBSO=1/g' Makefile
35+
$(MAKE) -j $(shell nproc --all)
36+
$(MAKE) preinstall
37+
cd -
38+
39+
# Install system wide.
40+
sudo_install:
41+
cd $(TMP_DIR)install_darknet
42+
sudo cp libdarknet.so /usr/lib/libdarknet.so
43+
sudo cp include/darknet.h /usr/include/darknet.h
44+
sudo ldconfig
45+
cd -
46+
47+
# Cleanup temporary files for building process
48+
clean:
49+
rm -rf $(TMP_DIR)install_darknet
50+
51+
# Do every step for CPU-based only build.
52+
install: download build sudo_install clean
53+
54+
# Do every step for both CPU and GPU-based build.
55+
install_gpu: download build_gpu sudo_install clean

README.md

Lines changed: 93 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
[![Go Report Card](https://goreportcard.com/badge/github.com/LdDl/go-darknet)](https://goreportcard.com/report/github.com/LdDl/go-darknet)
44
[![GitHub tag](https://img.shields.io/github/tag/LdDl/go-darknet.svg)](https://github.com/LdDl/go-darknet/releases)
55

6-
76
# go-darknet: Go bindings for Darknet (Yolo V4, Yolo V3)
87
### go-darknet is a Go package, which uses Cgo to enable Go applications to use YOLO V4/V3 in [Darknet].
98

@@ -23,29 +22,20 @@
2322

2423
## Requirements
2524

26-
For proper codebase please use fork of [darknet](https://github.com/AlexeyAB/darknet). Latest commit I've tested [here](https://github.com/AlexeyAB/darknet/commit/d65909fbea471d06e52a2e4a41132380dc2edaa6)
27-
28-
In order to use go-darknet, `libdarknet.so` should be available in one of
29-
the following locations:
25+
You need to install fork of [darknet](https://github.com/AlexeyAB/darknet). Latest commit I've tested is [here](https://github.com/AlexeyAB/darknet/commit/d65909fbea471d06e52a2e4a41132380dc2edaa6)
3026

31-
* /usr/lib
32-
* /usr/local/lib
27+
Use provided [Makefile](Makefile).
3328

34-
Also, [darknet.h] should be available in one of the following locations:
29+
* For CPU-based instalattion:
30+
```shell
31+
make install
32+
```
33+
* For both CPU and GPU-based instalattion:
34+
```shell
35+
make install_gpu
36+
```
37+
Note: If you want to have GPU-acceleration before running command above install [CUDA](https://developer.nvidia.com/cuda-downloads) and [cuDNN](https://developer.nvidia.com/cudnn) (Latest CUDA version I've tested is [10.2](https://developer.nvidia.com/cuda-10.2-download-archive) and cuDNN is [7.6.5](https://developer.nvidia.com/rdp/cudnn-archive#a-collapse765-102))
3538
36-
* /usr/include
37-
* /usr/local/include
38-
39-
To achieve it, after Darknet compilation (via make) execute following command:
40-
```shell
41-
# Copy *.so to /usr/lib + /usr/include (or /usr/local/lib + /usr/local/include)
42-
sudo cp libdarknet.so /usr/lib/libdarknet.so && sudo cp include/darknet.h /usr/include/darknet.h
43-
# sudo cp libdarknet.so /usr/local/lib/libdarknet.so && sudo cp include/darknet.h /usr/local/include/darknet.h
44-
```
45-
Note: do not forget to set LIBSO=1 in Makefile before executing 'make':
46-
```Makefile
47-
LIBSO=1
48-
```
4939
## Installation
5040
5141
```shell
@@ -58,87 +48,88 @@ Example Go program is provided in the [example] directory. Please refer to the c
5848
5949
Building and running program:
6050
61-
Navigate to [example] folder
62-
```shell
63-
cd $GOPATH/github.com/LdDl/go-darknet/example
64-
```
65-
66-
Download dataset (sample of image, coco.names, yolov4.cfg (or v3), yolov4.weights(or v3)).
67-
```shell
68-
#for yolo v4
69-
./download_data.sh
70-
#for yolo v3
71-
./download_data_v3.sh
72-
```
73-
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)
74-
So last rows in yolov4.cfg file will look like:
75-
```bash
76-
......
77-
[yolo]
78-
.....
79-
iou_loss=ciou
80-
nms_kind=greedynms
81-
beta_nms=0.6
82-
83-
names = coco.names # this is path to coco.names file
84-
```
85-
Also do not forget change batch and subdivisions sizes from:
86-
```shell
87-
batch=64
88-
subdivisions=8
89-
```
90-
to
91-
```shell
92-
batch=1
93-
subdivisions=1
94-
```
95-
It will reduce amount of VRAM used for detector test.
96-
97-
98-
Build and run program
99-
Yolo V4:
100-
```shell
101-
go build main.go && ./main --configFile=yolov4.cfg --weightsFile=yolov4.weights --imageFile=sample.jpg
102-
```
103-
104-
Output should be something like this:
105-
```shell
106-
traffic light (9): 73.5039% | start point: (238,73) | end point: (251, 106)
107-
truck (7): 96.6401% | start point: (95,79) | end point: (233, 287)
108-
truck (7): 96.4774% | start point: (662,158) | end point: (800, 321)
109-
truck (7): 96.1841% | start point: (0,77) | end point: (86, 333)
110-
truck (7): 46.8695% | start point: (434,173) | end point: (559, 216)
111-
car (2): 99.7370% | start point: (512,188) | end point: (741, 329)
112-
car (2): 99.2533% | start point: (260,191) | end point: (422, 322)
113-
car (2): 99.0333% | start point: (425,201) | end point: (547, 309)
114-
car (2): 83.3919% | start point: (386,210) | end point: (437, 287)
115-
car (2): 75.8621% | start point: (73,199) | end point: (102, 274)
116-
car (2): 39.1925% | start point: (386,206) | end point: (442, 240)
117-
bicycle (1): 76.3121% | start point: (189,298) | end point: (253, 402)
118-
person (0): 97.7213% | start point: (141,129) | end point: (283, 362)
119-
```
120-
121-
Yolo V3:
122-
```
123-
go build main.go && ./main --configFile=yolov3.cfg --weightsFile=yolov3.weights --imageFile=sample.jpg
124-
```
125-
126-
Output should be something like this:
127-
```shell
128-
truck (7): 49.5197% | start point: (0,136) | end point: (85, 311)
129-
car (2): 36.3747% | start point: (95,152) | end point: (186, 283)
130-
truck (7): 48.4384% | start point: (95,152) | end point: (186, 283)
131-
truck (7): 45.6590% | start point: (694,178) | end point: (798, 310)
132-
car (2): 76.8379% | start point: (1,145) | end point: (84, 324)
133-
truck (7): 25.5731% | start point: (107,89) | end point: (215, 263)
134-
car (2): 99.8783% | start point: (511,185) | end point: (748, 328)
135-
car (2): 99.8194% | start point: (261,189) | end point: (427, 322)
136-
car (2): 99.6408% | start point: (426,197) | end point: (539, 311)
137-
car (2): 74.5610% | start point: (692,186) | end point: (796, 316)
138-
car (2): 72.8053% | start point: (388,206) | end point: (437, 276)
139-
bicycle (1): 72.2932% | start point: (178,270) | end point: (268, 406)
140-
person (0): 97.3026% | start point: (143,135) | end point: (268, 343)
141-
```
51+
* Navigate to [example] folder
52+
```shell
53+
cd $GOPATH/github.com/LdDl/go-darknet/example
54+
```
55+
56+
* Download dataset (sample of image, coco.names, yolov4.cfg (or v3), yolov4.weights(or v3)).
57+
```shell
58+
#for yolo v4
59+
./download_data.sh
60+
#for yolo v3
61+
./download_data_v3.sh
62+
```
63+
* 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)
64+
So last rows in yolov4.cfg file will look like:
65+
```bash
66+
......
67+
[yolo]
68+
.....
69+
iou_loss=ciou
70+
nms_kind=greedynms
71+
beta_nms=0.6
72+
73+
names = coco.names # this is path to coco.names file
74+
```
75+
76+
* Also do not forget change batch and subdivisions sizes from:
77+
```shell
78+
batch=64
79+
subdivisions=8
80+
```
81+
to
82+
```shell
83+
batch=1
84+
subdivisions=1
85+
```
86+
It will reduce amount of VRAM used for detector test.
87+
88+
89+
* Build and run program
90+
Yolo V4:
91+
```shell
92+
go build main.go && ./main --configFile=yolov4.cfg --weightsFile=yolov4.weights --imageFile=sample.jpg
93+
```
94+
95+
Output should be something like this:
96+
```shell
97+
traffic light (9): 73.5039% | start point: (238,73) | end point: (251, 106)
98+
truck (7): 96.6401% | start point: (95,79) | end point: (233, 287)
99+
truck (7): 96.4774% | start point: (662,158) | end point: (800, 321)
100+
truck (7): 96.1841% | start point: (0,77) | end point: (86, 333)
101+
truck (7): 46.8695% | start point: (434,173) | end point: (559, 216)
102+
car (2): 99.7370% | start point: (512,188) | end point: (741, 329)
103+
car (2): 99.2533% | start point: (260,191) | end point: (422, 322)
104+
car (2): 99.0333% | start point: (425,201) | end point: (547, 309)
105+
car (2): 83.3919% | start point: (386,210) | end point: (437, 287)
106+
car (2): 75.8621% | start point: (73,199) | end point: (102, 274)
107+
car (2): 39.1925% | start point: (386,206) | end point: (442, 240)
108+
bicycle (1): 76.3121% | start point: (189,298) | end point: (253, 402)
109+
person (0): 97.7213% | start point: (141,129) | end point: (283, 362)
110+
```
111+
112+
Yolo V3:
113+
```
114+
go build main.go && ./main --configFile=yolov3.cfg --weightsFile=yolov3.weights --imageFile=sample.jpg
115+
```
116+
117+
Output should be something like this:
118+
```shell
119+
truck (7): 49.5197% | start point: (0,136) | end point: (85, 311)
120+
car (2): 36.3747% | start point: (95,152) | end point: (186, 283)
121+
truck (7): 48.4384% | start point: (95,152) | end point: (186, 283)
122+
truck (7): 45.6590% | start point: (694,178) | end point: (798, 310)
123+
car (2): 76.8379% | start point: (1,145) | end point: (84, 324)
124+
truck (7): 25.5731% | start point: (107,89) | end point: (215, 263)
125+
car (2): 99.8783% | start point: (511,185) | end point: (748, 328)
126+
car (2): 99.8194% | start point: (261,189) | end point: (427, 322)
127+
car (2): 99.6408% | start point: (426,197) | end point: (539, 311)
128+
car (2): 74.5610% | start point: (692,186) | end point: (796, 316)
129+
car (2): 72.8053% | start point: (388,206) | end point: (437, 276)
130+
bicycle (1): 72.2932% | start point: (178,270) | end point: (268, 406)
131+
person (0): 97.3026% | start point: (143,135) | end point: (268, 343)
132+
```
142133
143134
## Documentation
144135

0 commit comments

Comments
 (0)