当前位置: 首页 > news >正文

将onnx模型中的类别信息导出到文本

例如需要将yolov8x.onnx中检测目标的类别信息导出到category_names.txt,可用如下代码实现。

import retext = "{0: 'person', 1: 'bicycle', 2: 'car', 3: 'motorcycle', 4: 'airplane', 5: 'bus', 6: 'train', 7: 'truck', 8: 'boat', 9: 'traffic light', 10: 'fire hydrant', 11: 'stop sign', 12: 'parking meter', 13: 'bench', 14: 'bird', 15: 'cat', 16: 'dog', 17: 'horse', 18: 'sheep', 19: 'cow', 20: 'elephant', 21: 'bear', 22: 'zebra', 23: 'giraffe', 24: 'backpack', 25: 'umbrella', 26: 'handbag', 27: 'tie', 28: 'suitcase', 29: 'frisbee', 30: 'skis', 31: 'snowboard', 32: 'sports ball', 33: 'kite', 34: 'baseball bat', 35: 'baseball glove', 36: 'skateboard', 37: 'surfboard', 38: 'tennis racket', 39: 'bottle', 40: 'wine glass', 41: 'cup', 42: 'fork', 43: 'knife', 44: 'spoon', 45: 'bowl', 46: 'banana', 47: 'apple', 48: 'sandwich', 49: 'orange', 50: 'broccoli', 51: 'carrot', 52: 'hot dog', 53: 'pizza', 54: 'donut', 55: 'cake', 56: 'chair', 57: 'couch', 58: 'potted plant', 59: 'bed', 60: 'dining table', 61: 'toilet', 62: 'tv', 63: 'laptop', 64: 'mouse', 65: 'remote', 66: 'keyboard', 67: 'cell phone', 68: 'microwave', 69: 'oven', 70: 'toaster', 71: 'sink', 72: 'refrigerator', 73: 'book', 74: 'clock', 75: 'vase', 76: 'scissors', 77: 'teddy bear', 78: 'hair drier', 79: 'toothbrush'}"
cleaned_text = re.sub(r"[0-9':{}]+", "", text)
print(cleaned_text)# 分割文本并去除多余空格
words = [word.strip() for word in cleaned_text.split(',')]# 写入文件
with open('category_names.txt', 'w') as f:for word in words:f.write(f"{word}\n")

得到文件category_names.txt

person
bicycle
car
motorcycle
airplane
bus
train
truck
boat
traffic light
fire hydrant
stop sign
parking meter
bench
bird
cat
dog
horse
sheep
cow
elephant
bear
zebra
giraffe
backpack
umbrella
handbag
tie
suitcase
frisbee
skis
snowboard
sports ball
kite
baseball bat
baseball glove
skateboard
surfboard
tennis racket
bottle
wine glass
cup
fork
knife
spoon
bowl
banana
apple
sandwich
orange
broccoli
carrot
hot dog
pizza
donut
cake
chair
couch
potted plant
bed
dining table
toilet
tv
laptop
mouse
remote
keyboard
cell phone
microwave
oven
toaster
sink
refrigerator
book
clock
vase
scissors
teddy bear
hair drier
toothbrush

http://www.mrgr.cn/news/40578.html

相关文章:

  • JAVA认识异常
  • 数值计算的程序设计问题举例
  • 51单片机的智能家居【proteus仿真+程序+报告+原理图+演示视频】
  • 排水系统C++
  • 第5篇:勒索病毒自救指南----应急响应篇
  • 构建现代化社区医疗服务:SpringBoot平台
  • 【JavaEE】http/https 超级详解
  • 使用Materialize制作unity的贴图,Materialize的简单教程,Materialize学习日志
  • Raspberry Pi3B+之Rpanion(gst)和ffmpeg验证
  • 从零开始,5个步骤轻松掌握越来越火的JAX深度学习框架
  • Element-UI Plus 暗黑主题切换
  • 虚幻引擎-设置UI自适应屏幕大小
  • php生成透明图片和文字
  • Windows 环境下 MySQL5.5 安装与配置详解
  • 图神经网络DGL库之消息传递
  • Linux数据备份
  • idea 同一个项目不同模块如何设置不同的jdk版本
  • MySQL安装与环境配置(Windows系统 MySQL8.0.39)
  • 教程:在Linux上启动、运行、杀掉和管理项目程序
  • 从构建个性化学习系统维度提高认知转化率