From 81223ac67df5b4afeb36ff1f655a8327dfeba998 Mon Sep 17 00:00:00 2001 From: Dimitrii Date: Thu, 28 Jan 2021 13:43:35 +0300 Subject: [PATCH 1/5] start solving issue --- Makefile | 2 +- network.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 69ddb80..74a5897 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ .PHONY: download build clean # Latest battletested AlexeyAB version of Darknet commit -LATEST_COMMIT?=d65909fbea471d06e52a2e4a41132380dc2edaa6 +LATEST_COMMIT?=f056fc3b6a11528fa0522a468eca1e909b7004b7 # Temporary folder for building Darknet TMP_DIR?=/tmp/ diff --git a/network.c b/network.c index d30e6ff..caf0847 100644 --- a/network.c +++ b/network.c @@ -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) { From 165e59aaf39adb42a12b19bb2b7612224856bd6c Mon Sep 17 00:00:00 2001 From: Dimitrii Date: Thu, 28 Jan 2021 14:20:08 +0300 Subject: [PATCH 2/5] remove defer for image --- detection.go | 6 ++++++ example/base_example/main.go | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/detection.go b/detection.go index 7c92453..46ba424 100644 --- a/detection.go +++ b/detection.go @@ -25,6 +25,12 @@ type DetectionResult struct { OverallTimeTaken time.Duration } +// func (dr *DetectionResult) Close() error { +// C.free_detections(dr.Detections, len(dr.Detections)) +// dr.Detections = nil +// return nil +// } + func makeDetection(img *DarknetImage, det *C.detection, threshold float32, classes int, classNames []string) *Detection { if det == nil { return &Detection{} diff --git a/example/base_example/main.go b/example/base_example/main.go index 69b2a4e..4f039a6 100644 --- a/example/base_example/main.go +++ b/example/base_example/main.go @@ -9,7 +9,7 @@ import ( "log" "math" "os" - +"time" darknet "github.com/LdDl/go-darknet" "github.com/disintegration/imaging" ) @@ -61,13 +61,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 +92,7 @@ func main() { // } } } + time.Sleep(100*time.Millisecond) } func imageToBytes(img image.Image) ([]byte, error) { From 29e4d0d8bba6dd0a3f61c05a36d11e464bdc8e04 Mon Sep 17 00:00:00 2001 From: Dimitrii Date: Thu, 28 Jan 2021 14:20:38 +0300 Subject: [PATCH 3/5] clean --- detection.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/detection.go b/detection.go index 46ba424..7c92453 100644 --- a/detection.go +++ b/detection.go @@ -25,12 +25,6 @@ type DetectionResult struct { OverallTimeTaken time.Duration } -// func (dr *DetectionResult) Close() error { -// C.free_detections(dr.Detections, len(dr.Detections)) -// dr.Detections = nil -// return nil -// } - func makeDetection(img *DarknetImage, det *C.detection, threshold float32, classes int, classNames []string) *Detection { if det == nil { return &Detection{} From 13a0697585d94a8f20edf22717fb03681ad94857 Mon Sep 17 00:00:00 2001 From: Dimitrii Date: Thu, 28 Jan 2021 14:26:52 +0300 Subject: [PATCH 4/5] remove sleep --- example/base_example/main.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/example/base_example/main.go b/example/base_example/main.go index 4f039a6..272eb72 100644 --- a/example/base_example/main.go +++ b/example/base_example/main.go @@ -9,7 +9,6 @@ import ( "log" "math" "os" -"time" darknet "github.com/LdDl/go-darknet" "github.com/disintegration/imaging" ) @@ -92,7 +91,6 @@ func main() { // } } } - time.Sleep(100*time.Millisecond) } func imageToBytes(img image.Image) ([]byte, error) { From 40df8cce9143f5f46d4ea82482c96dd4ca32168b Mon Sep 17 00:00:00 2001 From: Dimitrii Date: Sat, 30 Jan 2021 13:57:21 +0300 Subject: [PATCH 5/5] free_network_ptr instead of free_network --- example/base_example/main.go | 2 ++ network.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/example/base_example/main.go b/example/base_example/main.go index 272eb72..8738bc3 100644 --- a/example/base_example/main.go +++ b/example/base_example/main.go @@ -91,6 +91,8 @@ func main() { // } } } + + n.Close() } func imageToBytes(img image.Image) ([]byte, error) { diff --git a/network.go b/network.go index 31ef9fe..e55638b 100644 --- a/network.go +++ b/network.go @@ -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 -} +} \ No newline at end of file