Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting class labels form .onnx model

I made an object detection model with YOLOv8 that I converted to an onnx model to make it faster on cpu. I want to extract the original label names used for annotation. I can see the labels in order in the onnx file when i open it as .txt file, but im not sure how to read this list with code. The goal is the list labels. Does anyone have a solution to get this data from the model?

I looked online but could not find a solution. Another option would be a way to open the file as a txt doc so i can filter the list out by hand

like image 634
FishingBehindTheNet Avatar asked Jan 23 '26 13:01

FishingBehindTheNet


1 Answers

I was looking at this as well and found that in some of the YOLO ONNX models the label names and the stride is stored as ONNX metadata_props.

import onnx,ast
m = onnx.load('yolov7-tiny_256x320.onnx')
props = { p.key : p.value for p in m.metadata_props }
if 'names' in props:
    names = ast.literal_eval(props['names'])
    ...
like image 179
D Dowling Avatar answered Jan 26 '26 01:01

D Dowling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!