16/10/2021

Install Darknet to use with AMD Radeon GPU

By snorlaxprime

So I have upgraded my Hackintosh with a new CPU and GPU with the following specs:

  • Intel Core i5-10400F 4.3 GHz LGA1200 CPU
  • AMD Sapphire Pulse Radeon RX 580 G5, 8GB GDDR5

Now previously I am using CUDA in my older Hackintosh which only support the NVidia graphics card in the post about Installing Darknet and CUDA.

So I have been searching for the Darknet version that will work with my Radeon graphics card and I stumble across Piotr Sowa’s post. He have forked the original Darknet and make lots of modification to work with Radeon and other processors as well. You can read about it in his blog.

I am using the following steps to install his version of Darknet. Here are the step by step instructions. If you have not installed Homebrew you will need to install the following first:

Step 1. Install Homebrew

Type the following command in terminal:

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

Step 2. Install OpenCV3

Using the following command in terminal

brew install opencv@3
brew link ——force opencv@3

Step 3. Install the rest of the library

install the following one at a time

brew install libomp
brew install clblas
brew install clfft
brew install cmake

Step 4. Download the Piotr’s Darknet version

 git clone https://github.com/sowson/darknet.git

Step 5. Build darknet

Before you build darknet make sure that you change the Makefile configuration to enable to AMD GPU as below:

vi darknet/Makefile

Search and change the following lines

GPU=1
NVIDIA=0
AMD=1

Make sure you save the Makefile before building with the following command.

cd darknet
mkdir build
cmake -Bbuild -H.
cd build
make

If all goes well you should have a darknet executable in the build directory under darknet folder. You can now copy the darknet from the build directory to the darknet directory using the following command

cd ..
cp build/darknet .
rm -r build

Now that you have the darknet executable, you can do the realtime object recognition using the pre-trained yolov3.weights file

wget https://pjreddie.com/media/files/yolov3.weights

Step 6. Enjoy the realtime object detection

Test the image dectection first using the following command

./darknet detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights data/dog.jpg

You should get the following picture prediction.

To run the realtime object detection use the following command

./darknet detector demo cfg/coco.data cfg/yolov3.cfg yolov3.weights

This will open your webcam and start detecting the objects in realtime.

Afterthought is to expand this to train the license plate recognition. I will post more once I have experimented with this.