YOLO11 in FRC

Here’s a Jupyter notebook to train YOLO11 models and convert them to RKNN so they can be used by coprocessors with Rockchips, it is intended to be used with an Orange Pi 5.

This notebook is based on LaviRZ’s and LevyIshai’s YOLOv8 training notebook. I’m currently a high school sophomore in my second year with FRC Team 503, Frog Force, and as I’ve been working with vision, their work with implementing YOLO in FRC has really helped me learn a lot, especially since I started learning about computer vision last year.

In summary, this takes a Roboflow Universe dataset, trains a YOLO11 object detection model from scratch, and then converts it to RKNN so that it can be used on a Rockchip processor’s NPU. To use the notebook, just make a copy of it in Google Colab. Then you just have to find a YOLO11 dataset in Roboflow and paste the download code in the specified code cell. I would use a dataset with a fewer number of classes and larger amount of images. Then you can adjust certain arguments for training the model and exporting it. It’s only written to be used in Google Colab with a GPU. Colab has pretty short time limits for use with the GPU so make sure to finish training your model quickly.

One problem I noticed when initially using LaviRZ’s code was that he included code to fix directories in the data.yaml file of the Roboflow dataset that only worked with his dataset’s specific directory errors. I adjusted the code to work with any data.yaml file as long as it has train, val, and test image directories in it. This is something to watch out for if you have errors with training. Also, when downloading RKNN Toolkit to convert the model, the notebook didn’t account for losing local variables after the runtime has to be restarted, so I added code for that.

I also added a lot more yap in the notebook which explains a lot about how all of the code works, and includes a lot of background information for people who are new to computer vision and Python. When I was learning how all of this stuff worked, those resources would have been really helpful. This model also includes a link to a notebook that can run YOLO11 models on videos.

To actually deploy this model, I would recommend using LaviRZ’s and Levyishai’s RKNN fork of PhotonVision found here: High FPS object detection with PhotonVision fork - v1.0!. You need an Orange Pi 5, an SD card flashed with the PhotonVision fork’s image, an ethernet cord & power (or a robot). This model hasn’t been tested with this fork so I don’t really know if this will work or not. Try running this notebook and deploying this model, it would be really great to see teams use this model in the coming Reefscape season!

Also I apologize if I didn’t follow proper citations with the resources I used and linked:)

16 Likes

Hi there!
Most of the notebook and fork are actually my work, so I’m glad to see it’s helped someone out there :blush:
Regarding the directory stuff, it’s been a long time so I don’t remember every hack I put in there, but I remember a historic mismatch between the output of the Roboflow clone and what yolo expected. There should be an issue I wrote in their discourse forum somewhere about this. It might have been fixed by now, or it may have been a Kaggle specific issue.
Speaking of Kaggle, I highly recommend it for training as it offers much better hardware, and allows running in the background, so you don’t have to have it open and prompt you for whether you’re still there while it’s training overnight.

Regarding whether it should work - I’m not familiar with yolov11, but when using v5 and v8 the output format of the models is drastically different. You should compare the inference code of v5/8 and v11 in the airockchip repo (maybe in the toolkit?) and see if it matches one of them. If not, it’d require more native code to be written and won’t work out of the box with neither the fork or mainstream PV.

3 Likes

Oh, I’m really sorry for not mentioning you, I forgot that the notebook was actually made by you and that it was posted by Levy. Also was it okay that I used a copy of your notebook to write my code and put my team’s number on? I want to make sure the proper credit and stuff is given to the people who worked on all of this stuff.

For sure

Also I compared the predict.py files for yolo11 and yolov8 and I’m pretty sure they’re the same. In general, I think yolo11 has the same functionalities as yolov8 with some extra features, so yolov8 inference code could probably work with yolo11 models.

Here is a kaggle version of the notebook: Frog Force 503: YOLO11 Training & RKNN Conversion | Kaggle

The model was able to upload on PV RKNN, but the frame rate was pretty low, the camera was set to stream 640x480 at 90fps but it was at 20fps. In that image it’s not detecting anything, but it was able to detect the note with decent confidence (I messed up the photo guys). I think with a solid training dataset, this model is feasible to use on an actual robot.