mirror of
https://github.com/LdDl/go-darknet.git
synced 2025-10-05 07:36:53 +08:00
makefile and minor
This commit is contained in:
55
Makefile
Normal file
55
Makefile
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
.ONESHELL:
|
||||||
|
.PHONY: download build clean
|
||||||
|
|
||||||
|
# Latest battletested AlexeyAB version of Darknet commit
|
||||||
|
LATEST_COMMIT?=d65909fbea471d06e52a2e4a41132380dc2edaa6
|
||||||
|
|
||||||
|
# Temporary folder for building Darknet
|
||||||
|
TMP_DIR?=/tmp/
|
||||||
|
|
||||||
|
# Download AlexeyAB version of Darknet
|
||||||
|
download:
|
||||||
|
rm -rf $(TMP_DIR)install_darknet
|
||||||
|
mkdir $(TMP_DIR)install_darknet
|
||||||
|
git clone https://github.com/AlexeyAB/darknet.git $(TMP_DIR)install_darknet
|
||||||
|
cd $(TMP_DIR)install_darknet
|
||||||
|
git checkout $(LATEST_COMMIT)
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Build AlexeyAB version of Darknet for usage with CPU only.
|
||||||
|
build:
|
||||||
|
cd $(TMP_DIR)install_darknet
|
||||||
|
sed -i -e 's/GPU=1/GPU=0/g' Makefile
|
||||||
|
sed -i -e 's/CUDNN=1/CUDNN=0/g' Makefile
|
||||||
|
sed -i -e 's/LIBSO=0/LIBSO=1/g' Makefile
|
||||||
|
$(MAKE) -j $(shell nproc --all)
|
||||||
|
$(MAKE) preinstall
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Build AlexeyAB version of Darknet for usage with both CPU and GPU (CUDA by NVIDIA).
|
||||||
|
build_gpu:
|
||||||
|
cd $(TMP_DIR)install_darknet
|
||||||
|
sed -i -e 's/GPU=0/GPU=1/g' Makefile
|
||||||
|
sed -i -e 's/CUDNN=0/CUDNN=1/g' Makefile
|
||||||
|
sed -i -e 's/LIBSO=0/LIBSO=1/g' Makefile
|
||||||
|
$(MAKE) -j $(shell nproc --all)
|
||||||
|
$(MAKE) preinstall
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Install system wide.
|
||||||
|
sudo_install:
|
||||||
|
cd $(TMP_DIR)install_darknet
|
||||||
|
sudo cp libdarknet.so /usr/lib/libdarknet.so
|
||||||
|
sudo cp include/darknet.h /usr/include/darknet.h
|
||||||
|
sudo ldconfig
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Cleanup temporary files for building process
|
||||||
|
clean:
|
||||||
|
rm -rf $(TMP_DIR)install_darknet
|
||||||
|
|
||||||
|
# Do every step for CPU-based only build.
|
||||||
|
install: download build sudo_install clean
|
||||||
|
|
||||||
|
# Do every step for both CPU and GPU-based build.
|
||||||
|
install_gpu: download build_gpu sudo_install clean
|
39
README.md
39
README.md
@@ -3,7 +3,6 @@
|
|||||||
[](https://goreportcard.com/report/github.com/LdDl/go-darknet)
|
[](https://goreportcard.com/report/github.com/LdDl/go-darknet)
|
||||||
[](https://github.com/LdDl/go-darknet/releases)
|
[](https://github.com/LdDl/go-darknet/releases)
|
||||||
|
|
||||||
|
|
||||||
# go-darknet: Go bindings for Darknet (Yolo V4, Yolo V3)
|
# go-darknet: Go bindings for Darknet (Yolo V4, Yolo V3)
|
||||||
### go-darknet is a Go package, which uses Cgo to enable Go applications to use YOLO V4/V3 in [Darknet].
|
### go-darknet is a Go package, which uses Cgo to enable Go applications to use YOLO V4/V3 in [Darknet].
|
||||||
|
|
||||||
@@ -23,29 +22,20 @@
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
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)
|
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)
|
||||||
|
|
||||||
In order to use go-darknet, `libdarknet.so` should be available in one of
|
Use provided [Makefile](Makefile).
|
||||||
the following locations:
|
|
||||||
|
|
||||||
* /usr/lib
|
* For CPU-based instalattion:
|
||||||
* /usr/local/lib
|
|
||||||
|
|
||||||
Also, [darknet.h] should be available in one of the following locations:
|
|
||||||
|
|
||||||
* /usr/include
|
|
||||||
* /usr/local/include
|
|
||||||
|
|
||||||
To achieve it, after Darknet compilation (via make) execute following command:
|
|
||||||
```shell
|
```shell
|
||||||
# Copy *.so to /usr/lib + /usr/include (or /usr/local/lib + /usr/local/include)
|
make install
|
||||||
sudo cp libdarknet.so /usr/lib/libdarknet.so && sudo cp include/darknet.h /usr/include/darknet.h
|
|
||||||
# sudo cp libdarknet.so /usr/local/lib/libdarknet.so && sudo cp include/darknet.h /usr/local/include/darknet.h
|
|
||||||
```
|
```
|
||||||
Note: do not forget to set LIBSO=1 in Makefile before executing 'make':
|
* For both CPU and GPU-based instalattion:
|
||||||
```Makefile
|
```shell
|
||||||
LIBSO=1
|
make install_gpu
|
||||||
```
|
```
|
||||||
|
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))
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
@@ -58,19 +48,19 @@ Example Go program is provided in the [example] directory. Please refer to the c
|
|||||||
|
|
||||||
Building and running program:
|
Building and running program:
|
||||||
|
|
||||||
Navigate to [example] folder
|
* Navigate to [example] folder
|
||||||
```shell
|
```shell
|
||||||
cd $GOPATH/github.com/LdDl/go-darknet/example
|
cd $GOPATH/github.com/LdDl/go-darknet/example
|
||||||
```
|
```
|
||||||
|
|
||||||
Download dataset (sample of image, coco.names, yolov4.cfg (or v3), yolov4.weights(or v3)).
|
* Download dataset (sample of image, coco.names, yolov4.cfg (or v3), yolov4.weights(or v3)).
|
||||||
```shell
|
```shell
|
||||||
#for yolo v4
|
#for yolo v4
|
||||||
./download_data.sh
|
./download_data.sh
|
||||||
#for yolo v3
|
#for yolo v3
|
||||||
./download_data_v3.sh
|
./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)
|
* 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:
|
So last rows in yolov4.cfg file will look like:
|
||||||
```bash
|
```bash
|
||||||
......
|
......
|
||||||
@@ -82,7 +72,8 @@ beta_nms=0.6
|
|||||||
|
|
||||||
names = coco.names # this is path to coco.names file
|
names = coco.names # this is path to coco.names file
|
||||||
```
|
```
|
||||||
Also do not forget change batch and subdivisions sizes from:
|
|
||||||
|
* Also do not forget change batch and subdivisions sizes from:
|
||||||
```shell
|
```shell
|
||||||
batch=64
|
batch=64
|
||||||
subdivisions=8
|
subdivisions=8
|
||||||
@@ -95,7 +86,7 @@ subdivisions=1
|
|||||||
It will reduce amount of VRAM used for detector test.
|
It will reduce amount of VRAM used for detector test.
|
||||||
|
|
||||||
|
|
||||||
Build and run program
|
* Build and run program
|
||||||
Yolo V4:
|
Yolo V4:
|
||||||
```shell
|
```shell
|
||||||
go build main.go && ./main --configFile=yolov4.cfg --weightsFile=yolov4.weights --imageFile=sample.jpg
|
go build main.go && ./main --configFile=yolov4.cfg --weightsFile=yolov4.weights --imageFile=sample.jpg
|
||||||
|
Reference in New Issue
Block a user