LdDl / go-darknet

Go bindings for Darknet (YOLO v4 / v7-tiny / v3)
Apache License 2.0
82 stars 19 forks source link

Checkout to stable YOLO v4 #23

Closed LdDl closed 2 years ago

LdDl commented 2 years ago

Trying to checkout stable'ish YOLO v4: https://github.com/AlexeyAB/darknet/releases/tag/yolov4

Current state for GPU:

Failed to calloc 17179869184.0 GiB
Darknet error location: ./src/image.c, make_image, line #797
Calloc error - possibly out of CPU RAM: Cannot allocate memory

Need to dig into (Darknet's source code)

image make_image(int w, int h, int c)
{
    image out = make_empty_image(w,h,c);
    out.data = (float*)xcalloc(h * w * c, sizeof(float));
    return out;
}

Current state for CPU:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x2 addr=0x7f10b4021000 pc=0x7f11d3cf6f23]

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

goroutine 1 [syscall]:
runtime.cgocall(0x4ecc10, 0xc000075bc8, 0xc000012068)
        /usr/local/go/src/runtime/cgocall.go:133 +0x5b fp=0xc000075b98 sp=0xc000075b60 pc=0x404f8b
github.com/LdDl/go-darknet._Cfunc_perform_network_detect(0xd38880, 0xc000012068, 0x3e80000000000050, 0x3ee666663f000000, 0x0, 0x0, 0x0)
        _cgo_gotypes.go:869 +0x4d fp=0xc000075bc8 sp=0xc000075b98 pc=0x4cc51d
github.com/LdDl/go-darknet.(*YOLONetwork).Detect.func1(0xc000075e88, 0xc000012040, 0x0, 0x0)
        /home/dimitrii/work/src/github.com/LdDl/go-darknet/network.go:72 +0x117 fp=0xc000075c38 sp=0xc000075bc8 pc=0x4ce737
github.com/LdDl/go-darknet.(*YOLONetwork).Detect(0xc000075e88, 0xc000012040, 0xc000012040, 0x0, 0x0)
        /home/dimitrii/work/src/github.com/LdDl/go-darknet/network.go:72 +0x8e fp=0xc000075d48 sp=0xc000075c38 pc=0x4cde5e
main.main()
        /home/dimitrii/work/src/github.com/LdDl/go-darknet/example/base_example/main.go:64 +0x31d fp=0xc000075f88 sp=0xc000075d48 pc=0x4ec09d
runtime.main()
        /usr/local/go/src/runtime/proc.go:203 +0x212 fp=0xc000075fe0 sp=0xc000075f88 pc=0x4347f2
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1373 +0x1 fp=0xc000075fe8 sp=0xc000075fe0 pc=0x45ee11

When make switch from network_predict_ptr() to network_predict()

    // replace network_predict_ptr(n, sized.data); with 
    network_predict(*n, sized.data);

I got same error, but for 'CPU' RAM:

Failed to calloc 17179869184.0 GiB
Darknet error location: ./src/image.c, make_image, line #797
Calloc error - possibly out of CPU RAM: Cannot allocate memory
LdDl commented 2 years ago

I guess the problem is in this call:

sized = resize_image(*img, n->w, n->h);

both n->w and n->h give strange output (neither 416 or 608, which depends on *.cfg file): something like 20127904x0

When use

LATEST_COMMIT?=d65909fbea471d06e52a2e4a41132380dc2edaa6

I've got 608x608 for YOLOv4

So, I assume something went wrong on setting networks parameters when use 'stable'-ish release.

LdDl commented 2 years ago

Changes between current working commit and stable one: https://github.com/AlexeyAB/darknet/compare/d65909fbea471d06e52a2e4a41132380dc2edaa6...AlexeyAB:9d40b619756be9521bc2ccd81808f502daaa3e9a

LdDl commented 2 years ago

Addition: manual setup of width/height in resize_image leads to expected ('good') results without any errors (checked CPU)

brianhumphreys commented 2 years ago

I have tried every commit for the last 2 years (starting from commit f056fc3b6a11528fa0522a468eca1e909b7004b7) and I get a compilation error for every single one.

ld: library not found for -l:libdarknet.so
clang: fatal error: linker command failed with exit code 1 (use -v to see invocation)

I am a mac user running make install_darknet for CPU usage of darknet

LdDl commented 2 years ago

I guess you need to make libdarknet.so 'visible' for compiler (also do not forget to make LIBSO=1 in Makefile)