24 Commits

Author SHA1 Message Date
Dimitrii
8213e6e9ac update makefile 2021-08-18 13:08:37 +03:00
Dimitrii
7ed6d2e7c9 extend install 2021-08-18 13:02:20 +03:00
Dimitrii
4c748e7ba4 minor renames 2021-08-18 12:08:00 +03:00
Dimitrii
b27d031c92 rm docker temporary 2021-08-18 12:03:02 +03:00
Dimitrii Lopanov
fb66efa419 Update README.md 2021-02-19 14:25:47 +03:00
Dimitrii Lopanov
25fd9865dd Update README.md 2021-02-19 14:25:23 +03:00
Dimitrii Lopanov
687c472ea9 Update README.md 2021-02-19 14:25:12 +03:00
Dimitrii Lopanov
b8f4ad6d57 Merge pull request #16 from LdDl/issue-15
Issue 15
2021-02-01 08:07:24 +03:00
Dimitrii
40df8cce91 free_network_ptr instead of free_network 2021-01-30 13:57:21 +03:00
Dimitrii
13a0697585 remove sleep 2021-01-28 14:26:52 +03:00
Dimitrii
29e4d0d8bb clean 2021-01-28 14:20:38 +03:00
Dimitrii
165e59aaf3 remove defer for image 2021-01-28 14:20:08 +03:00
Dimitrii
81223ac67d start solving issue 2021-01-28 13:43:35 +03:00
Dimitrii Lopanov
7cbe2f50a7 load file 2020-10-16 13:20:22 +03:00
Dimitrii Lopanov
6a381223fa provide example picture 2020-10-16 13:18:39 +03:00
Dimitrii Lopanov
a039e75b22 Merge pull request #14 from LdDl/examples
Examples
2020-10-16 12:55:53 +03:00
Dimitrii Lopanov
7f94c3bdcc readme and minor 2020-10-16 12:52:56 +03:00
Dimitrii Lopanov
e5d170ef8b inital rest example 2020-10-16 12:14:06 +03:00
Dimitrii Lopanov
85730b925c move base example to its own folder 2020-10-16 11:02:59 +03:00
Dimitrii Lopanov
55221029de Merge pull request #13 from LdDl/install-darknet
makefile and minor
2020-10-16 10:58:46 +03:00
Dimitrii Lopanov
e0a6735667 makefile and minor 2020-10-16 10:15:18 +03:00
Dimitrii
c9bbd3eee4 update darknet latest commit 2020-10-15 19:58:08 +03:00
Dimitrii Lopanov
5539377f1c Merge pull request #11 from LdDl/add-license-2
Create LICENSE
2020-10-15 17:22:26 +03:00
Dimitrii Lopanov
10cd5f6e1a Update issue templates 2020-10-15 17:22:14 +03:00
20 changed files with 625 additions and 611 deletions

26
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,26 @@
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: bug, help wanted
assignees: LdDl
---
**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.

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: "[FEATURE REQUEST]"
labels: enhancement
assignees: LdDl
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is.
**Describe the solution you'd like and provide pseudocode examples if you can**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered and provide pseudocode examples if you can**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

1
.gitignore vendored
View File

@@ -1,5 +1,4 @@
example/main
example/sample.jpg
example/coco.names
example/yolov3.cfg
example/yolov3.weights

103
Makefile Normal file
View File

@@ -0,0 +1,103 @@
.ONESHELL:
.PHONY: prepare_cuda prepare_cudnn download_darknet build_darknet build_darknet_gpu clean clean_cuda clean_cudnn
# Latest battletested AlexeyAB version of Darknet commit
LATEST_COMMIT?=f056fc3b6a11528fa0522a468eca1e909b7004b7
# Temporary folder for building Darknet
TMP_DIR?=/tmp/
# Manage cuda version
CUDA_VERSION = 10.2
CUDNN_VERSION = 7.6.5
CUDNN_FULL_VERSION = 7.6.5.32
OS_NAME_LOW_CASE = ubuntu
OS_VERSION_CONCATENATED = 1804
OS_ARCH = x86_64
OS_ALTER_ARCH = linux-x64
OS_FULLNAME = $(OS_NAME_LOW_CASE)$(OS_VERSION_CONCATENATED)
# I guess *.pub is static for most of systems
PUBNAME = 7fa2af80
# Install CUDA
prepare_cuda:
sudo apt-get install linux-headers-$(uname -r)
rm -rf $(TMP_DIR)install_cuda
mkdir $(TMP_DIR)install_cuda
wget -P $(TMP_DIR)install_cuda https://developer.download.nvidia.com/compute/cuda/repos/$(OS_FULLNAME)/$(OS_ARCH)/cuda-$(OS_FULLNAME).pin
cd $(TMP_DIR)install_cuda
sudo mv cuda-$(OS_FULLNAME).pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/$(OS_FULLNAME)/$(OS_ARCH)/$(PUBNAME).pub
sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/$(OS_FULLNAME)/$(OS_ARCH)/ /"
sudo apt-get update
sudo apt-get -y install cuda-$(subst .,-,$(CUDA_VERSION))
cd -
# Install cuDNN
# Notice: this valid instruction for cuDNN version from v7.2.1 up to 8.1.0.77
prepare_cudnn:
rm -rf $(TMP_DIR)install_cudnn
mkdir $(TMP_DIR)install_cudnn
wget -P $(TMP_DIR)install_cudnn https://developer.download.nvidia.com/compute/redist/cudnn/v${CUDNN_VERSION}/cudnn-${CUDA_VERSION}-${OS_ALTER_ARCH}-v${CUDNN_FULL_VERSION}.tgz
cd $(TMP_DIR)install_cudnn
tar -xzvf cudnn-${CUDA_VERSION}-${OS_ALTER_ARCH}-v${CUDNN_FULL_VERSION}.tgz
sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
cd -
# Download AlexeyAB version of Darknet
download_darknet:
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_darknet:
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_darknet_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
clean_cuda:
rm -rf $(TMP_DIR)install_cuda
clean_cudnn:
rm -rf $(TMP_DIR)install_cudnn
# Do every step for CPU-based only build.
install_darknet: download_darknet build_darknet sudo_install clean
# Do every step for both CPU and GPU-based build.
install_darknet_gpu: download_darknet build_darknet_gpu sudo_install clean
# Do every step for both CPU and GPU-based build if you haven't installed CUDA.
install_darknet_gpu_cuda: prepare_cuda prepare_cudnn download_darknet build_darknet_gpu sudo_install clean clean_cuda clean_cudnn

199
README.md
View File

@@ -3,7 +3,6 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/LdDl/go-darknet)](https://goreportcard.com/report/github.com/LdDl/go-darknet)
[![GitHub tag](https://img.shields.io/github/tag/LdDl/go-darknet.svg)](https://github.com/LdDl/go-darknet/releases)
# 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].
@@ -15,37 +14,48 @@
## Table of Contents
- [Why](#why)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Documentation](#documentation)
- [License](#license)
## 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](https://github.com/hybridgroup/gocv#gocv) (bindings to OpenCV) and it handle Darnet 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
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/9dc897d2c77d5ef43a6b237b717437375765b527)
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
the following locations:
Use provided [Makefile](Makefile).
* /usr/lib
* /usr/local/lib
* For CPU-based instalattion:
```shell
make install_darknet
```
* For both CPU and GPU-based instalattion if you HAVE CUDA installed:
```shell
make install_darknet_gpu
```
Note: I've tested CUDA [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))
Also, [darknet.h] should be available in one of the following locations:
* For both CPU and GPU-based instalattion if you HAVE NOT CUDA installed:
```shell
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.
* /usr/include
* /usr/local/include
To achieve it, after Darknet compilation (via make) execute following command:
```shell
# Copy *.so to /usr/lib + /usr/include (or /usr/local/lib + /usr/local/include)
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':
```Makefile
LIBSO=1
```
## Installation
```shell
@@ -58,87 +68,88 @@ Example Go program is provided in the [example] directory. Please refer to the c
Building and running program:
Navigate to [example] folder
```shell
cd $GOPATH/github.com/LdDl/go-darknet/example
```
* Navigate to [example] folder
```shell
cd $GOPATH/github.com/LdDl/go-darknet/example/base_example
```
Download dataset (sample of image, coco.names, yolov4.cfg (or v3), yolov4.weights(or v3)).
```shell
#for yolo v4
./download_data.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:
```bash
......
[yolo]
.....
iou_loss=ciou
nms_kind=greedynms
beta_nms=0.6
* Download dataset (sample of image, coco.names, yolov4.cfg (or v3), yolov4.weights(or v3)).
```shell
#for yolo v4
./download_data.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:
```bash
......
[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:
```shell
batch=64
subdivisions=8
```
to
```shell
batch=1
subdivisions=1
```
It will reduce amount of VRAM used for detector test.
names = coco.names # this is path to coco.names file
```
* Also do not forget change batch and subdivisions sizes from:
```shell
batch=64
subdivisions=8
```
to
```shell
batch=1
subdivisions=1
```
It will reduce amount of VRAM used for detector test.
Build and run program
Yolo V4:
```shell
go build main.go && ./main --configFile=yolov4.cfg --weightsFile=yolov4.weights --imageFile=sample.jpg
```
* Build and run program
Yolo V4:
```shell
go build main.go && ./main --configFile=yolov4.cfg --weightsFile=yolov4.weights --imageFile=sample.jpg
```
Output should be something like this:
```shell
traffic light (9): 73.5039% | 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.8695% | start point: (434,173) | end point: (559, 216)
car (2): 99.7370% | start point: (512,188) | end point: (741, 329)
car (2): 99.2533% | start point: (260,191) | end point: (422, 322)
car (2): 99.0333% | start point: (425,201) | end point: (547, 309)
car (2): 83.3919% | 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)
```
Output should be something like this:
```shell
traffic light (9): 73.5039% | 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.8695% | start point: (434,173) | end point: (559, 216)
car (2): 99.7370% | start point: (512,188) | end point: (741, 329)
car (2): 99.2533% | start point: (260,191) | end point: (422, 322)
car (2): 99.0333% | start point: (425,201) | end point: (547, 309)
car (2): 83.3919% | 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 V3:
```
go build main.go && ./main --configFile=yolov3.cfg --weightsFile=yolov3.weights --imageFile=sample.jpg
```
Yolo V3:
```
go build main.go && ./main --configFile=yolov3.cfg --weightsFile=yolov3.weights --imageFile=sample.jpg
```
Output should be something like this:
```shell
truck (7): 49.5197% | start point: (0,136) | end point: (85, 311)
car (2): 36.3747% | start point: (95,152) | end point: (186, 283)
truck (7): 48.4384% | start point: (95,152) | end point: (186, 283)
truck (7): 45.6590% | start point: (694,178) | end point: (798, 310)
car (2): 76.8379% | start point: (1,145) | end point: (84, 324)
truck (7): 25.5731% | start point: (107,89) | end point: (215, 263)
car (2): 99.8783% | start point: (511,185) | end point: (748, 328)
car (2): 99.8194% | start point: (261,189) | end point: (427, 322)
car (2): 99.6408% | start point: (426,197) | end point: (539, 311)
car (2): 74.5610% | start point: (692,186) | end point: (796, 316)
car (2): 72.8053% | start point: (388,206) | end point: (437, 276)
bicycle (1): 72.2932% | start point: (178,270) | end point: (268, 406)
person (0): 97.3026% | start point: (143,135) | end point: (268, 343)
```
Output should be something like this:
```shell
truck (7): 49.5197% | start point: (0,136) | end point: (85, 311)
car (2): 36.3747% | start point: (95,152) | end point: (186, 283)
truck (7): 48.4384% | start point: (95,152) | end point: (186, 283)
truck (7): 45.6590% | start point: (694,178) | end point: (798, 310)
car (2): 76.8379% | start point: (1,145) | end point: (84, 324)
truck (7): 25.5731% | start point: (107,89) | end point: (215, 263)
car (2): 99.8783% | start point: (511,185) | end point: (748, 328)
car (2): 99.8194% | start point: (261,189) | end point: (427, 322)
car (2): 99.6408% | start point: (426,197) | end point: (539, 311)
car (2): 74.5610% | start point: (692,186) | end point: (796, 316)
car (2): 72.8053% | start point: (388,206) | end point: (437, 276)
bicycle (1): 72.2932% | start point: (178,270) | end point: (268, 406)
person (0): 97.3026% | start point: (143,135) | end point: (268, 343)
```
## Documentation
@@ -154,5 +165,5 @@ go-darknet follows [Darknet]'s [license].
[darknet.h]: https://github.com/AlexeyAB/darknet/blob/master/include/darknet.h
[include/darknet.h]: https://github.com/AlexeyAB/darknet/blob/master/include/darknet.h
[Makefile]: https://github.com/alexeyab/darknet/blob/master/Makefile
[example]: /example
[example]: /example/base_example
[GoDoc]: https://godoc.org/github.com/LdDl/go-darknet

View File

@@ -1 +0,0 @@
NAMESPACE=darknet

View File

@@ -1,40 +0,0 @@
# Build phase
FROM ubuntu:18.04 as builder
ENV darknet_commit=a234a5022333c930de08f2470184ef4e0c68356e
WORKDIR /root/build
COPY Makefile.cpu .
RUN apt-get -y update && \
apt-get -y install --no-install-recommends git build-essential ca-certificates && \
git clone https://github.com/AlexeyAB/darknet && \
cd darknet && \
git checkout $darknet_commit && \
cp -f /root/build/Makefile.cpu Makefile && \
make
# Final Image
FROM golang:1.14
RUN apt-get -y update && \
apt-get -y install --no-install-recommends nano bash jq
WORKDIR /root
COPY --from=builder /root/build/darknet/darknet \
/root/build/darknet/libdarknet.so \
/root/build/darknet/include/darknet.h \
./staging/
RUN mv staging/darknet /usr/local/bin && \
mv staging/darknet.h /usr/include && \
mv staging/libdarknet.so /usr/lib && \
rm -rf staging
RUN go get -u github.com/LdDl/go-darknet \
&& go get -u github.com/disintegration/imaging
WORKDIR /darknet
COPY download_data.sh .
CMD ["/bin/bash"]

View File

@@ -1,52 +0,0 @@
# Build phase
FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04 as builder
ENV darknet_commit=a234a5022333c930de08f2470184ef4e0c68356e
WORKDIR /root/build
COPY Makefile.gpu .
RUN apt-get -y update && \
apt-get -y install git build-essential && \
git clone https://github.com/AlexeyAB/darknet.git && \
cd darknet && \
git checkout $darknet_commit && \
cp -f /root/build/Makefile.gpu Makefile && \
make
# Final Image
FROM nvidia/cuda:10.0-cudnn7-runtime-ubuntu18.04
WORKDIR /root
COPY --from=builder /root/build/darknet/darknet \
/root/build/darknet/libdarknet.so \
/root/build/darknet/include/darknet.h \
./staging/
RUN mv staging/darknet /usr/local/bin && \
mv staging/darknet.h /usr/include && \
mv staging/libdarknet.so /usr/lib && \
rm -rf staging
WORKDIR /tmp
RUN cd /tmp \
&& apt-get -y update \
&& apt-get install -y wget git gcc \
&& wget https://dl.google.com/go/go1.14.linux-amd64.tar.gz \
&& tar -xvf go1.14.linux-amd64.tar.gz \
&& mv go /usr/local
RUN cp /usr/local/cuda-10.0/compat/* /usr/local/cuda-10.0/targets/x86_64-linux/lib/
ENV GOROOT=/usr/local/go
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH
ENV LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda-10.0/compat/
RUN go get -u github.com/LdDl/go-darknet \
&& go get -u github.com/disintegration/imaging
WORKDIR /darknet
COPY download_data.sh .
CMD ["/bin/bash"]

View File

@@ -1,185 +0,0 @@
GPU=0
CUDNN=0
CUDNN_HALF=0
OPENCV=0
AVX=1
OPENMP=1
LIBSO=1
ZED_CAMERA=0 # ZED SDK 3.0 and above
ZED_CAMERA_v2_8=0 # ZED SDK 2.X
# set GPU=1 and CUDNN=1 to speedup on GPU
# set CUDNN_HALF=1 to further speedup 3 x times (Mixed-precision on Tensor Cores) GPU: Volta, Xavier, Turing and higher
# set AVX=1 and OPENMP=1 to speedup on CPU (if error occurs then set AVX=0)
USE_CPP=0
DEBUG=0
ARCH= -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=[sm_50,compute_50] \
-gencode arch=compute_52,code=[sm_52,compute_52] \
-gencode arch=compute_61,code=[sm_61,compute_61]
OS := $(shell uname)
# Tesla V100
# ARCH= -gencode arch=compute_70,code=[sm_70,compute_70]
# GeForce RTX 2080 Ti, RTX 2080, RTX 2070, Quadro RTX 8000, Quadro RTX 6000, Quadro RTX 5000, Tesla T4, XNOR Tensor Cores
# ARCH= -gencode arch=compute_75,code=[sm_75,compute_75]
# Jetson XAVIER
# ARCH= -gencode arch=compute_72,code=[sm_72,compute_72]
# GTX 1080, GTX 1070, GTX 1060, GTX 1050, GTX 1030, Titan Xp, Tesla P40, Tesla P4
# ARCH= -gencode arch=compute_61,code=sm_61 -gencode arch=compute_61,code=compute_61
# GP100/Tesla P100 - DGX-1
# ARCH= -gencode arch=compute_60,code=sm_60
# For Jetson TX1, Tegra X1, DRIVE CX, DRIVE PX - uncomment:
# ARCH= -gencode arch=compute_53,code=[sm_53,compute_53]
# For Jetson Tx2 or Drive-PX2 uncomment:
# ARCH= -gencode arch=compute_62,code=[sm_62,compute_62]
# VPATH=./src/
VPATH=./src/:./examples
SLIB=libdarknet.so
EXEC=darknet
OBJDIR=./obj/
ifeq ($(LIBSO), 1)
LIBNAMESO=libdarknet.so
APPNAMESO=uselib
endif
ifeq ($(USE_CPP), 1)
CC=g++
else
CC=gcc
endif
CPP=g++ -std=c++11
NVCC=nvcc
OPTS=-Ofast
LDFLAGS= -lm -pthread
COMMON= -Iinclude/ -I3rdparty/stb/include
CFLAGS=-Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC
ifeq ($(DEBUG), 1)
#OPTS= -O0 -g
#OPTS= -Og -g
COMMON+= -DDEBUG
CFLAGS+= -DDEBUG
else
ifeq ($(AVX), 1)
CFLAGS+= -ffp-contract=fast -mavx -mavx2 -msse3 -msse4.1 -msse4.2 -msse4a
endif
endif
CFLAGS+=$(OPTS)
ifneq (,$(findstring MSYS_NT,$(OS)))
LDFLAGS+=-lws2_32
endif
ifeq ($(OPENCV), 1)
COMMON+= -DOPENCV
CFLAGS+= -DOPENCV
LDFLAGS+= `pkg-config --libs opencv4 2> /dev/null || pkg-config --libs opencv`
COMMON+= `pkg-config --cflags opencv4 2> /dev/null || pkg-config --cflags opencv`
endif
ifeq ($(OPENMP), 1)
CFLAGS+= -fopenmp
LDFLAGS+= -lgomp
endif
ifeq ($(GPU), 1)
COMMON+= -DGPU -I/usr/local/cuda/include/
CFLAGS+= -DGPU
ifeq ($(OS),Darwin) #MAC
LDFLAGS+= -L/usr/local/cuda/lib -lcuda -lcudart -lcublas -lcurand
else
LDFLAGS+= -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand
endif
endif
ifeq ($(CUDNN), 1)
COMMON+= -DCUDNN
ifeq ($(OS),Darwin) #MAC
CFLAGS+= -DCUDNN -I/usr/local/cuda/include
LDFLAGS+= -L/usr/local/cuda/lib -lcudnn
else
CFLAGS+= -DCUDNN -I/usr/local/cudnn/include
LDFLAGS+= -L/usr/local/cudnn/lib64 -lcudnn
endif
endif
ifeq ($(CUDNN_HALF), 1)
COMMON+= -DCUDNN_HALF
CFLAGS+= -DCUDNN_HALF
ARCH+= -gencode arch=compute_70,code=[sm_70,compute_70]
endif
ifeq ($(ZED_CAMERA), 1)
CFLAGS+= -DZED_STEREO -I/usr/local/zed/include
ifeq ($(ZED_CAMERA_v2_8), 1)
LDFLAGS+= -L/usr/local/zed/lib -lsl_core -lsl_input -lsl_zed
#-lstdc++ -D_GLIBCXX_USE_CXX11_ABI=0
else
LDFLAGS+= -L/usr/local/zed/lib -lsl_zed
#-lstdc++ -D_GLIBCXX_USE_CXX11_ABI=0
endif
endif
OBJ=image_opencv.o http_stream.o gemm.o utils.o dark_cuda.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o reorg_layer.o reorg_old_layer.o super.o voxel.o tree.o yolo_layer.o gaussian_yolo_layer.o upsample_layer.o lstm_layer.o conv_lstm_layer.o scale_channels_layer.o sam_layer.o
ifeq ($(GPU), 1)
LDFLAGS+= -lstdc++
OBJ+=convolutional_kernels.o activation_kernels.o im2col_kernels.o col2im_kernels.o blas_kernels.o crop_layer_kernels.o dropout_layer_kernels.o maxpool_layer_kernels.o network_kernels.o avgpool_layer_kernels.o
endif
OBJS = $(addprefix $(OBJDIR), $(OBJ))
DEPS = $(wildcard src/*.h) Makefile include/darknet.h
all: $(OBJDIR) backup results setchmod $(EXEC) $(LIBNAMESO) $(APPNAMESO)
ifeq ($(LIBSO), 1)
CFLAGS+= -fPIC
$(LIBNAMESO): $(OBJDIR) $(OBJS) include/yolo_v2_class.hpp src/yolo_v2_class.cpp
$(CPP) -shared -std=c++11 -fvisibility=hidden -DLIB_EXPORTS $(COMMON) $(CFLAGS) $(OBJS) src/yolo_v2_class.cpp -o $@ $(LDFLAGS)
$(APPNAMESO): $(LIBNAMESO) include/yolo_v2_class.hpp src/yolo_console_dll.cpp
$(CPP) -std=c++11 $(COMMON) $(CFLAGS) -o $@ src/yolo_console_dll.cpp $(LDFLAGS) -L ./ -l:$(LIBNAMESO)
endif
$(EXEC): $(OBJS)
$(CPP) -std=c++11 $(COMMON) $(CFLAGS) $^ -o $@ $(LDFLAGS)
$(OBJDIR)%.o: %.c $(DEPS)
$(CC) $(COMMON) $(CFLAGS) -c $< -o $@
$(OBJDIR)%.o: %.cpp $(DEPS)
$(CPP) -std=c++11 $(COMMON) $(CFLAGS) -c $< -o $@
$(OBJDIR)%.o: %.cu $(DEPS)
$(NVCC) $(ARCH) $(COMMON) --compiler-options "$(CFLAGS)" -c $< -o $@
$(OBJDIR):
mkdir -p $(OBJDIR)
backup:
mkdir -p backup
results:
mkdir -p results
setchmod:
chmod +x *.sh
.PHONY: clean
clean:
rm -rf $(OBJS) $(EXEC) $(LIBNAMESO) $(APPNAMESO)

View File

@@ -1,186 +0,0 @@
GPU=1
CUDNN=1
CUDNN_HALF=0
OPENCV=0
AVX=0
OPENMP=0
LIBSO=1
ZED_CAMERA=0 # ZED SDK 3.0 and above
ZED_CAMERA_v2_8=0 # ZED SDK 2.X
# set GPU=1 and CUDNN=1 to speedup on GPU
# set CUDNN_HALF=1 to further speedup 3 x times (Mixed-precision on Tensor Cores) GPU: Volta, Xavier, Turing and higher
# set AVX=1 and OPENMP=1 to speedup on CPU (if error occurs then set AVX=0)
USE_CPP=0
DEBUG=0
ARCH= -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=[sm_50,compute_50] \
-gencode arch=compute_52,code=[sm_52,compute_52] \
-gencode arch=compute_61,code=[sm_61,compute_61]
OS := $(shell uname)
# Tesla V100
# ARCH= -gencode arch=compute_70,code=[sm_70,compute_70]
# GeForce RTX 2080 Ti, RTX 2080, RTX 2070, Quadro RTX 8000, Quadro RTX 6000, Quadro RTX 5000, Tesla T4, XNOR Tensor Cores
# ARCH= -gencode arch=compute_75,code=[sm_75,compute_75]
# Jetson XAVIER
# ARCH= -gencode arch=compute_72,code=[sm_72,compute_72]
# GTX 1080, GTX 1070, GTX 1060, GTX 1050, GTX 1030, Titan Xp, Tesla P40, Tesla P4
# ARCH= -gencode arch=compute_61,code=sm_61 -gencode arch=compute_61,code=compute_61
# GP100/Tesla P100 - DGX-1
# ARCH= -gencode arch=compute_60,code=sm_60
# For Jetson TX1, Tegra X1, DRIVE CX, DRIVE PX - uncomment:
# ARCH= -gencode arch=compute_53,code=[sm_53,compute_53]
# For Jetson Tx2 or Drive-PX2 uncomment:
# ARCH= -gencode arch=compute_62,code=[sm_62,compute_62]
# VPATH=./src/
VPATH=./src/:./examples
SLIB=libdarknet.so
EXEC=darknet
OBJDIR=./obj/
ifeq ($(LIBSO), 1)
LIBNAMESO=libdarknet.so
APPNAMESO=uselib
endif
ifeq ($(USE_CPP), 1)
CC=g++
else
CC=gcc
endif
CPP=g++ -std=c++11
NVCC=nvcc
OPTS=-Ofast
LDFLAGS= -lm -pthread
COMMON= -Iinclude/ -I3rdparty/stb/include
CFLAGS=-Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC
ifeq ($(DEBUG), 1)
#OPTS= -O0 -g
#OPTS= -Og -g
COMMON+= -DDEBUG
CFLAGS+= -DDEBUG
else
ifeq ($(AVX), 1)
CFLAGS+= -ffp-contract=fast -mavx -mavx2 -msse3 -msse4.1 -msse4.2 -msse4a
endif
endif
CFLAGS+=$(OPTS)
ifneq (,$(findstring MSYS_NT,$(OS)))
LDFLAGS+=-lws2_32
endif
ifeq ($(OPENCV), 1)
COMMON+= -DOPENCV
CFLAGS+= -DOPENCV
LDFLAGS+= `pkg-config --libs opencv4 2> /dev/null || pkg-config --libs opencv`
COMMON+= `pkg-config --cflags opencv4 2> /dev/null || pkg-config --cflags opencv`
endif
ifeq ($(OPENMP), 1)
CFLAGS+= -fopenmp
LDFLAGS+= -lgomp
endif
ifeq ($(GPU), 1)
COMMON+= -DGPU -I/usr/local/cuda/include/
CFLAGS+= -DGPU
ifeq ($(OS),Darwin) #MAC
LDFLAGS+= -L/usr/local/cuda/lib -lcuda -lcudart -lcublas -lcurand
else
LDFLAGS+= -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand
endif
endif
ifeq ($(CUDNN), 1)
COMMON+= -DCUDNN
ifeq ($(OS),Darwin) #MAC
CFLAGS+= -DCUDNN -I/usr/local/cuda/include
LDFLAGS+= -L/usr/local/cuda/lib -lcudnn
else
CFLAGS+= -DCUDNN -I/usr/local/cudnn/include
LDFLAGS+= -L/usr/local/cudnn/lib64 -lcudnn
endif
endif
ifeq ($(CUDNN_HALF), 1)
COMMON+= -DCUDNN_HALF
CFLAGS+= -DCUDNN_HALF
ARCH+= -gencode arch=compute_70,code=[sm_70,compute_70]
endif
ifeq ($(ZED_CAMERA), 1)
CFLAGS+= -DZED_STEREO -I/usr/local/zed/include
ifeq ($(ZED_CAMERA_v2_8), 1)
LDFLAGS+= -L/usr/local/zed/lib -lsl_core -lsl_input -lsl_zed
#-lstdc++ -D_GLIBCXX_USE_CXX11_ABI=0
else
LDFLAGS+= -L/usr/local/zed/lib -lsl_zed
#-lstdc++ -D_GLIBCXX_USE_CXX11_ABI=0
endif
endif
OBJ=image_opencv.o http_stream.o gemm.o utils.o dark_cuda.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o reorg_layer.o reorg_old_layer.o super.o voxel.o tree.o yolo_layer.o gaussian_yolo_layer.o upsample_layer.o lstm_layer.o conv_lstm_layer.o scale_channels_layer.o sam_layer.o
ifeq ($(GPU), 1)
LDFLAGS+= -lstdc++
OBJ+=convolutional_kernels.o activation_kernels.o im2col_kernels.o col2im_kernels.o blas_kernels.o crop_layer_kernels.o dropout_layer_kernels.o maxpool_layer_kernels.o network_kernels.o avgpool_layer_kernels.o
endif
OBJS = $(addprefix $(OBJDIR), $(OBJ))
DEPS = $(wildcard src/*.h) Makefile include/darknet.h
all: $(OBJDIR) backup results setchmod $(EXEC) $(LIBNAMESO) $(APPNAMESO)
ifeq ($(LIBSO), 1)
CFLAGS+= -fPIC
$(LIBNAMESO): $(OBJDIR) $(OBJS) include/yolo_v2_class.hpp src/yolo_v2_class.cpp
$(CPP) -shared -std=c++11 -fvisibility=hidden -DLIB_EXPORTS $(COMMON) $(CFLAGS) $(OBJS) src/yolo_v2_class.cpp -o $@ $(LDFLAGS)
$(APPNAMESO): $(LIBNAMESO) include/yolo_v2_class.hpp src/yolo_console_dll.cpp
$(CPP) -std=c++11 $(COMMON) $(CFLAGS) -o $@ src/yolo_console_dll.cpp $(LDFLAGS) -L ./ -l:$(LIBNAMESO)
endif
$(EXEC): $(OBJS)
$(CPP) -std=c++11 $(COMMON) $(CFLAGS) $^ -o $@ $(LDFLAGS)
$(OBJDIR)%.o: %.c $(DEPS)
$(CC) $(COMMON) $(CFLAGS) -c $< -o $@
$(OBJDIR)%.o: %.cpp $(DEPS)
$(CPP) -std=c++11 $(COMMON) $(CFLAGS) -c $< -o $@
$(OBJDIR)%.o: %.cu $(DEPS)
$(NVCC) $(ARCH) $(COMMON) --compiler-options "$(CFLAGS)" -c $< -o $@
$(OBJDIR):
mkdir -p $(OBJDIR)
backup:
mkdir -p backup
results:
mkdir -p results
setchmod:
chmod +x *.sh
.PHONY: clean
clean:
rm -rf $(OBJS) $(EXEC) $(LIBNAMESO) $(APPNAMESO)

View File

@@ -1,32 +0,0 @@
---
version: '3.7'
services:
sidekiq: &darknet_base
container_name: ${NAMESPACE}-sidekiq
build:
context: .
dockerfile: Dockerfile
image: go-darknet:latest
working_dir: /darknet
volumes:
- darknet-data:/darknet/models
command: /darknet/download_data.sh
darknet:
<<: *darknet_base
container_name: ${NAMESPACE}-api
ports:
- "9003:9003"
restart: unless-stopped
depends_on:
- sidekiq
command: ["/bin/bash"]
# command: ["darknet-server"]
volumes:
darknet-data:
driver_opts:
type: none
o: bind
device: ${PWD}/models

View File

@@ -1,10 +0,0 @@
#!/bin/sh
# set -x
# set -e
wget -nc --output-document=sample.jpg https://cdn-images-1.medium.com/max/800/1*EYFejGUjvjPcc4PZTwoufw.jpeg
wget -nc --output-document=./models/coco.names https://raw.githubusercontent.com/AlexeyAB/darknet/master/data/coco.names
wget -nc --output-document=./models/yolov3.cfg https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov3.cfg
sed -i -e "\$anames = coco.names" ./models/yolov3.cfg
wget -nc --output-document=./models/yolov3.weights https://pjreddie.com/media/files/yolov3.weights

View File

@@ -1,2 +0,0 @@
*
!.gitignore

View File

@@ -8,12 +8,12 @@ This is an example Go application which uses go-darknet.
Navigate to example folder:
```shell
cd $GOPATH/github.com/LdDl/go-darknet/example
cd $GOPATH/github.com/LdDl/go-darknet/example/base_example
```
Download dataset (sample of image, coco.names, yolov3.cfg, yolov3.weights).
```shell
./download_data.sh
./download_data_v3.sh
```
Note: you don't need *coco.data* file anymore, because script below does insert *coco.names* into 'names' filed in *yolov3.cfg* file (so AlexeyAB's fork can deal with it properly)
So last rows in yolov3.cfg file will look like:

View File

@@ -9,7 +9,6 @@ import (
"log"
"math"
"os"
darknet "github.com/LdDl/go-darknet"
"github.com/disintegration/imaging"
)
@@ -61,13 +60,13 @@ func main() {
if err != nil {
panic(err.Error())
}
defer imgDarknet.Close()
dr, err := n.Detect(imgDarknet)
if err != nil {
printError(err)
return
}
imgDarknet.Close()
log.Println("Network-only time taken:", dr.NetworkOnlyTimeTaken)
log.Println("Overall time taken:", dr.OverallTimeTaken, len(dr.Detections))
@@ -92,6 +91,8 @@ func main() {
// }
}
}
n.Close()
}
func imageToBytes(img image.Image) ([]byte, error) {

View File

@@ -0,0 +1,221 @@
# Example Go application using go-darknet and REST
This is an example Go server application (in terms of REST) which uses go-darknet.
## Run
Navigate to example folder:
```shell
cd $GOPATH/github.com/LdDl/go-darknet/example/rest_example
```
Download dataset (sample of image, coco.names, yolov3.cfg, yolov3.weights).
```shell
./download_data_v3.sh
```
Note: you don't need *coco.data* file anymore, because script below does insert *coco.names* into 'names' filed in *yolov3.cfg* file (so AlexeyAB's fork can deal with it properly)
So last rows in yolov3.cfg file will look like:
```bash
......
[yolo]
mask = 0,1,2
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
names = coco.names # this is path to coco.names file
```
Build and run program
```
go build main.go && ./main --configFile=yolov3.cfg --weightsFile=yolov3.weights --port 8090
```
After server started check if REST-requests works. We provide cURL-based example
```shell
curl -F 'image=@sample.jpg' 'http://localhost:8090/detect_objects'
```
Servers response should be something like this:
```json
{
"net_time": "43.269289ms",
"overall_time": "43.551604ms",
"num_detections": 44,
"detections": [
{
"class_id": 7,
"class_name": "truck",
"probability": 49.51231,
"start_point": {
"x": 0,
"y": 136
},
"end_point": {
"x": 85,
"y": 311
}
},
{
"class_id": 2,
"class_name": "car",
"probability": 36.36933,
"start_point": {
"x": 95,
"y": 152
},
"end_point": {
"x": 186,
"y": 283
}
},
{
"class_id": 7,
"class_name": "truck",
"probability": 48.417683,
"start_point": {
"x": 95,
"y": 152
},
"end_point": {
"x": 186,
"y": 283
}
},
{
"class_id": 7,
"class_name": "truck",
"probability": 45.652023,
"start_point": {
"x": 694,
"y": 178
},
"end_point": {
"x": 798,
"y": 310
}
},
{
"class_id": 2,
"class_name": "car",
"probability": 76.8402,
"start_point": {
"x": 1,
"y": 145
},
"end_point": {
"x": 84,
"y": 324
}
},
{
"class_id": 7,
"class_name": "truck",
"probability": 25.592052,
"start_point": {
"x": 107,
"y": 89
},
"end_point": {
"x": 215,
"y": 263
}
},
{
"class_id": 2,
"class_name": "car",
"probability": 99.87823,
"start_point": {
"x": 511,
"y": 185
},
"end_point": {
"x": 748,
"y": 328
}
},
{
"class_id": 2,
"class_name": "car",
"probability": 99.819336,
"start_point": {
"x": 261,
"y": 189
},
"end_point": {
"x": 427,
"y": 322
}
},
{
"class_id": 2,
"class_name": "car",
"probability": 99.64055,
"start_point": {
"x": 426,
"y": 197
},
"end_point": {
"x": 539,
"y": 311
}
},
{
"class_id": 2,
"class_name": "car",
"probability": 74.56263,
"start_point": {
"x": 692,
"y": 186
},
"end_point": {
"x": 796,
"y": 316
}
},
{
"class_id": 2,
"class_name": "car",
"probability": 72.79756,
"start_point": {
"x": 388,
"y": 206
},
"end_point": {
"x": 437,
"y": 276
}
},
{
"class_id": 1,
"class_name": "bicycle",
"probability": 72.27595,
"start_point": {
"x": 178,
"y": 270
},
"end_point": {
"x": 268,
"y": 406
}
},
{
"class_id": 0,
"class_name": "person",
"probability": 97.30075,
"start_point": {
"x": 143,
"y": 135
},
"end_point": {
"x": 268,
"y": 343
}
}
]
}
```

View File

@@ -0,0 +1,140 @@
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"image"
_ "image/jpeg"
"io/ioutil"
"log"
"net/http"
"github.com/LdDl/go-darknet"
)
var configFile = flag.String("configFile", "",
"Path to network layer configuration file. Example: cfg/yolov3.cfg")
var weightsFile = flag.String("weightsFile", "",
"Path to weights file. Example: yolov3.weights")
var serverPort = flag.Int("port", 8090,
"Listening port")
func main() {
flag.Parse()
if *configFile == "" || *weightsFile == "" {
flag.Usage()
return
}
n := darknet.YOLONetwork{
GPUDeviceIndex: 0,
NetworkConfigurationFile: *configFile,
WeightsFile: *weightsFile,
Threshold: .25,
}
if err := n.Init(); err != nil {
log.Println(err)
return
}
defer n.Close()
http.HandleFunc("/detect_objects", detectObjects(&n))
http.ListenAndServe(fmt.Sprintf(":%d", *serverPort), nil)
}
// DarknetResp Response
type DarknetResp struct {
NetTime string `json:"net_time"`
OverallTime string `json:"overall_time"`
Detections []*DarknetDetection `json:"detections"`
}
// DarknetDetection Information about single detection
type DarknetDetection struct {
ClassID int `json:"class_id"`
ClassName string `json:"class_name"`
Probability float32 `json:"probability"`
StartPoint *DarknetPoint `json:"start_point"`
EndPoint *DarknetPoint `json:"end_point"`
}
// DarknetPoint image.Image point
type DarknetPoint struct {
X int `json:"x"`
Y int `json:"y"`
}
func detectObjects(n *darknet.YOLONetwork) func(w http.ResponseWriter, req *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
// Restrict file size up to 10mb
req.ParseMultipartForm(10 << 20)
file, _, err := req.FormFile("image")
if err != nil {
fmt.Fprintf(w, fmt.Sprintf("Error reading FormFile: %s", err.Error()))
return
}
defer file.Close()
fileBytes, err := ioutil.ReadAll(file)
if err != nil {
fmt.Fprintf(w, fmt.Sprintf("Error reading bytes: %s", err.Error()))
return
}
imgSrc, _, err := image.Decode(bytes.NewReader(fileBytes))
if err != nil {
fmt.Fprintf(w, fmt.Sprintf("Error decoding bytes to image: %s", err.Error()))
return
}
imgDarknet, err := darknet.Image2Float32(imgSrc)
if err != nil {
fmt.Fprintf(w, fmt.Sprintf("Error converting image.Image to darknet.DarknetImage: %s", err.Error()))
return
}
defer imgDarknet.Close()
dr, err := n.Detect(imgDarknet)
if err != nil {
fmt.Fprintf(w, fmt.Sprintf("Error detecting objects: %s", err.Error()))
return
}
resp := DarknetResp{
NetTime: fmt.Sprintf("%v", dr.NetworkOnlyTimeTaken),
OverallTime: fmt.Sprintf("%v", dr.OverallTimeTaken),
Detections: []*DarknetDetection{},
}
for _, d := range dr.Detections {
for i := range d.ClassIDs {
bBox := d.BoundingBox
resp.Detections = append(resp.Detections, &DarknetDetection{
ClassID: d.ClassIDs[i],
ClassName: d.ClassNames[i],
Probability: d.Probabilities[i],
StartPoint: &DarknetPoint{
X: bBox.StartPoint.X,
Y: bBox.StartPoint.Y,
},
EndPoint: &DarknetPoint{
X: bBox.EndPoint.X,
Y: bBox.EndPoint.Y,
},
})
}
}
respBytes, err := json.Marshal(resp)
if err != nil {
fmt.Fprintf(w, fmt.Sprintf("Error encoding response: %s", err.Error()))
return
}
fmt.Fprintf(w, string(respBytes))
}
}

BIN
example/sample.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@@ -14,7 +14,8 @@ struct network_box_result perform_network_detect(network *n, image *img, int cla
sized = resize_image(*img, n->w, n->h);
}
struct network_box_result result = { NULL };
network_predict(*n, sized.data);
// mleak at network_predict(), get_network_boxes() and network_predict_ptr()?
network_predict_ptr(n, sized.data);
int nboxes = 0;
result.detections = get_network_boxes(n, img->w, img->h, thresh, hier_thresh, 0, 1, &result.detections_len, letter_box);
if (nms) {

View File

@@ -58,7 +58,7 @@ func (n *YOLONetwork) Close() error {
if n.cNet == nil {
return errNetworkNotInit
}
C.free_network(*n.cNet)
C.free_network_ptr(n.cNet)
n.cNet = nil
return nil
}
@@ -80,4 +80,4 @@ func (n *YOLONetwork) Detect(img *DarknetImage) (*DetectionResult, error) {
OverallTimeTaken: endTimeOverall.Sub(startTime),
}
return &out, nil
}
}