top of page
Writer's pictureSameer Natu

YOLOX on RISC-V QEMU

Updated: Nov 12

Goal of this project:


This project aims to determine RISC-V's readiness for running YOLOX for the latest edge requirements.


Target Application:


Running YOLOX on RISC-V QEMU involves setting up a RISC-V virtual machine and then configuring the necessary environment to compile and run YOLOX. Please note that this is a complex process, and it's essential to have prior experience with virtualization and RISC-V development.

From the RISCV website, this is a blog (https://riscv.org/blog/2023/07/yolox-for-object-detection/) which describes the steps to build and run YOLOX for a development board. These steps did not work as is when running on QEMU. This blog assumes the readers of this blog are comfortable with a Linux-based host system (this guide is based on Ubuntu 22.04).


Step 1: Install QEMU and Set Up a RISC-V Virtual Machine


Setting up RISC-V VM

First, you need to install QEMU and the RISC-V toolchain. You can do this by running:


​sudo apt-get install qemu-system-riscv

In this step, you'll create a RISC-V virtual machine using QEMU. You'll need a RISC-V disk image for this. You can find pre-built RISC-V images for various Linux distributions online. You can also build your own RISC-V image if you prefer.


wget https://cdimage.ubuntu.com/releases/22.04/release/ubuntu-22.04.3-preinstalled-server-riscv64+unmatched.img.xz
tar xf ubuntu-22.04.3-preinstalled-server-riscv64+unmatched.img.xz
#Rename the qemu_image
mv ubuntu-22.04.3-preinstalled-server-riscv64+unmatched.img riscv-ubuntu2204.img 
qemu-img resize ubuntu-22.04.3-preinstalled-server-riscv64+unmatched.img +16G

Launch the Qemu VM as follows:


Booting the VM

qemu-system-riscv64 -nographic -machine virt -m 16G -append "root=/dev/vda rw" -drive file=riscv-ubuntu2204.img,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 -device virtio-net-device,netdev=net0 -netdev user,id=net0


This will boot the RISC-V VM with 16GB of RAM.


Step 2: Configure the Python Environment


Configuring Python

Once the VM is up and running, log in, and set up your RISC-V development environment. You may need to install the necessary dependencies, which may vary depending on the distribution and the version.

Most of the software packages that Python program software depends on can be installed by pip. You can run the following command to install pip.


apt install python3-pip

Before installing other Python packages, install the venv package that can be used to create a Python virtual environment.


apt install python3.11-venv

Create a Python virtual environment and activate it.


cd /root
python3 -m venv yolox
source /root/yolox/bin/activate

Step 3: Install necessary whl packages


The Python ecology of the RISC-V architecture is still lacking. We have created build packages to be able to install directly on python3.11. 


Step 4: Build and Run YOLOX


Building YOLOX

Next, clone the YOLOX repository into your RISC-V qemu


Navigate to the YOLOX directory and build the YOLOX code. This step may involve installing additional dependencies and configuring the build for RISC-V architecture.


cd YOLOX
make

With YOLOX successfully built, you can now run it on your RISC-V system. You'll need to adapt the YOLOX commands to work with your specific use case and input data.

In this example, yolox_s is downloaded.


Running YOLOX

wget wttps://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.pth -P /home/ubuntu/
python3 tools/demo.py image -n yolox-s -c /home/ubuntu/yolox_s.pth --path assets/demo.png --conf 0.25 --nms 0.45 --tsize 640 --save_result --device cpu


#Output Logs
2023-09-15 17:05:49.803 | INFO     | __main__:main:269 - Model Summary: Params: 8.97M, Gflops: 26.93
2023-09-15 17:05:49.860 | INFO     | __main__:main:282 - loading checkpoint
2023-09-15 17:05:53.884 | INFO     | __main__:main:286 - loaded checkpoint done.
2023-09-15 17:06:24.598 | INFO     | __main__:inference:165 - Infer time: 30.0775s
2023-09-15 17:06:24.708 | INFO     | __main__:image_demo:202 - Saving detection result in ./YOLOX_outputs/yolox_s/vis_res/2023_09_15_17_05_53/demo.png

Inference

YOLOX and RISC-V

We would like to hear from you if this blog was useful to you. Please contact us at info@whileone.in.


Running YOLOX on RISC-V

We would be happy to understand and discuss your requirements and showcase our expertise in a variety of cloud and edge technologies.



35 views0 comments

Comments


bottom of page