LdDl / go-darknet

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

[BUG] - `make install_darknet` task fails on macOS 12.1 #22

Closed brianhumphreys closed 2 years ago

brianhumphreys commented 2 years ago

Describe the bug First of all, thanks for this repo! You've done a lot of amazing work that I'm excited to use! I am not sure if this is a bug or a mismatch in system compatibilities. It could also just be some github hiccup and in that case, my apologies for posting this here but I would appreciate any help! The issue seems to be that the reference to darknet repo at commit f056fc3b6a11528fa0522a468eca1e909b7004b7 is not a tree.

Command:

make install_darknet

Result:

rm -rf /tmp/install_darknet
mkdir /tmp/install_darknet
git clone https://github.com/AlexeyAB/darknet.git /tmp/install_darknet
Cloning into '/tmp/install_darknet'...
remote: Enumerating objects: 15386, done.
remote: Total 15386 (delta 0), reused 0 (delta 0), pack-reused 15386
Receiving objects: 100% (15386/15386), 14.01 MiB | 2.00 MiB/s, done.
Resolving deltas: 100% (10345/10345), done.
cd /tmp/install_darknet
git checkout f056fc3b6a11528fa0522a468eca1e909b7004b7
fatal: reference is not a tree: f056fc3b6a11528fa0522a468eca1e909b7004b7
make: *** [download_darknet] Error 128

To Reproduce 1) git clone git@github.com:LdDl/go-darknet.git 2) cd go-darknet/ 3) make install_darknet

Expected behavior Darknet compiles correctly

Describe the solution you'd like and provide pseudocode examples if you can If there are any workarounds to this issue on my system or glaring git mishaps occurring, I would love to know more in hopes that this issue helps others encountering this issue.

EDIT: I just went back over the README and noticed a potential issue. It states that the most recent battle-tested commit of the forked darknet is what go-darknet is using to build but while taking a peek in the Makefile, the LATEST_COMMIT variable is set to f056fc3b6a11528fa0522a468eca1e909b7004b7 which is not the same hash as the commit in the README. That hash is d65909fbea471d06e52a2e4a41132380dc2edaa6 and when attempting to change the LATEST_COMMIT variable to this hash, I get the same issue.

EDIT: The trouble command is when the Makefile runs git checkout $(LATEST_COMMIT) but when navigating to the /tmp/install_darknet directory and running the command manually, it switches refs just fine.

brianhumphreys commented 2 years ago

As mentioned in the edits, I got passed this issue by running checkout manually and then running the next task in the install_darknet task group which is given the name build_darknet.

# Do every step for CPU-based only build.
install_darknet: download_darknet build_darknet sudo_install clean

After running make build_darknet, it seems to invoke the prepare_cuda task which doesn't seem right since I am only building for CPU usage. It fails with:

/Applications/Xcode.app/Contents/Developer/usr/bin/make -j 8
sudo apt-get install linux-headers-
sudo: apt-get: command not found
make[1]: *** [prepare_cuda] Error 1
make: *** [build_darknet] Error 2

This error makes sense because CUDA is not compatible with macs and apt-get is not a UNIX command. I am just curious why it's being invoked when building CPU on macs.

LdDl commented 2 years ago

Describe the bug First of all, thanks for this repo! You've done a lot of amazing work that I'm excited to use! I am not sure if this is a bug or a mismatch in system compatibilities. It could also just be some github hiccup and in that case, my apologies for posting this here but I would appreciate any help! The issue seems to be that the reference to darknet repo at commit f056fc3b6a11528fa0522a468eca1e909b7004b7 is not a tree.

Command:

make install_darknet

Result:

rm -rf /tmp/install_darknet
mkdir /tmp/install_darknet
git clone https://github.com/AlexeyAB/darknet.git /tmp/install_darknet
Cloning into '/tmp/install_darknet'...
remote: Enumerating objects: 15386, done.
remote: Total 15386 (delta 0), reused 0 (delta 0), pack-reused 15386
Receiving objects: 100% (15386/15386), 14.01 MiB | 2.00 MiB/s, done.
Resolving deltas: 100% (10345/10345), done.
cd /tmp/install_darknet
git checkout f056fc3b6a11528fa0522a468eca1e909b7004b7
fatal: reference is not a tree: f056fc3b6a11528fa0522a468eca1e909b7004b7
make: *** [download_darknet] Error 128

To Reproduce

  1. git clone git@github.com:LdDl/go-darknet.git
  2. cd go-darknet/
  3. make install_darknet

Expected behavior Darknet compiles correctly

Describe the solution you'd like and provide pseudocode examples if you can If there are any workarounds to this issue on my system or glaring git mishaps occurring, I would love to know more in hopes that this issue helps others encountering this issue.

EDIT: I just went back over the README and noticed a potential issue. It states that the most recent battle-tested commit of the forked darknet is what go-darknet is using to build but while taking a peek in the Makefile, the LATEST_COMMIT variable is set to f056fc3b6a11528fa0522a468eca1e909b7004b7 which is not the same hash as the commit in the README. That hash is d65909fbea471d06e52a2e4a41132380dc2edaa6 and when attempting to change the LATEST_COMMIT variable to this hash, I get the same issue.

EDIT: The trouble command is when the Makefile runs git checkout $(LATEST_COMMIT) but when navigating to the /tmp/install_darknet directory and running the command manually, it switches refs just fine.

Hello there!

  1. Thanks, I've changed commit in README to f056fc3b6a11528fa0522a468eca1e909b7004b7
  2. About 'make build_darknet'
    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 -

    According to

    /Applications/Xcode.app/Contents/Developer/usr/bin/make -j 8

    I guess problem is in here:

    $(MAKE) -j $(shell nproc --all)

Can you manually check if contents of 'build_darknet' work fine?

cd /tmp/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 8
make preinstall
cd -

p.s. Unfortunately, I haven't any macOS device :( So I'm 'blind' a bit.

brianhumphreys commented 2 years ago

Apologies for the delay!

From running manually, I get:

./src/yolo_layer.c:656:10: fatal error: use of undeclared identifier 'b'
    for (b = 0; b < l.batch; ++b) {

while the make -j 8 command is executing. Seems to be an issue with AlexeyAB's darknet implementation?

LdDl commented 2 years ago

Seems so. I'm trying to figure out stable commit of implementation: https://github.com/LdDl/go-darknet/pull/23

brianhumphreys commented 2 years ago

Apologies for delay. I ended up getting this to work by reinstalling Xcode. This was the main issue, however, the build scripts are currently incompatible with mac. I plan on making a PR in the future but I do not have a clean implementation yet. For those running into this issue in the mean time, when running the make install_darknet task, I had to git checkout manually. Not sure why this was an issue but the commit could not be found when using the task.

Next, instead of using the build_darknet task, I ran the following script:

export TMP_DIR=/tmp

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=1/LIBSO=1/g' Makefile
/Applications/Xcode.app/Contents/Developer/usr/bin/make -j $(sysctl -n hw.ncpu)
/Applications/Xcode.app/Contents/Developer/usr/bin/make preinstall
cd -

Finally, to download the model, I used the following script:

curl https://cdn-images-1.medium.com/max/800/1*EYFejGUjvjPcc4PZTwoufw.jpeg -o sample.jpg
curl https://raw.githubusercontent.com/AlexeyAB/darknet/master/data/coco.names -o coco.names
curl https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4.cfg -o yolov4.cfg
sed -i -e "\$anames = coco.names" yolov4.cfg
curl https://pjreddie.com/media/files/yolov4.weights -o yolov4.weights

I hope this helps others and as I said I will make a PR in the future.