yolov8修改通道顺序

python 复制代码
'''
description:
version:
Author: zef
Date: 2023-07-06 14:54:01
LastEditors: zwy
LastEditTime: 2023-07-11 18:05:32
'''
import onnx
import onnx.helper as helper
import sys
import os

def main(file):



    prefix, suffix = os.path.splitext(file)
    dst = prefix + ".transd" + suffix

    model = onnx.load(file)
    node  = model.graph.node[-1]

    old_output = node.output[0]
    node.output[0] = "pre_transpose"

    for specout in model.graph.output:
        if specout.name == old_output:
            shape0 = specout.type.tensor_type.shape.dim[0]
            shape1 = specout.type.tensor_type.shape.dim[1]
            shape2 = specout.type.tensor_type.shape.dim[2]
            new_out = helper.make_tensor_value_info(
                specout.name,
                specout.type.tensor_type.elem_type,
                [0, 0, 0]
            )
            new_out.type.tensor_type.shape.dim[0].CopyFrom(shape0)
            new_out.type.tensor_type.shape.dim[2].CopyFrom(shape1)
            new_out.type.tensor_type.shape.dim[1].CopyFrom(shape2)
            specout.CopyFrom(new_out)

    model.graph.node.append(
        helper.make_node("Transpose", ["pre_transpose"], [old_output], perm=[0, 2, 1])
    )

    print(f"Model save to {dst}")
    onnx.save(model, dst)
    return 0

if __name__ == "__main__":
    file=r"F:\ultralytics\epoch55.onnx"
    main(file)
相关推荐
qqxhb2 分钟前
零基础学Java——第十一章:实战项目 - 桌面应用开发(JavaFX入门)
java·开发语言·javafx
hy.z_7777 分钟前
【数据结构】链表 LinkedList
java·数据结构·链表
松树戈11 分钟前
plus-ui&RuoYi-Vue-Plus 基于pgSql本地运行实践
前端·vue.js·spring boot·ui
new66699917 分钟前
css画图形
前端·css
Akiiiira28 分钟前
【数据结构】队列
java·开发语言·数据结构
程序媛学姐34 分钟前
Java级联操作:CascadeType的选择与最佳实践
java·开发语言
不知几秋1 小时前
Maven
java·数据库·maven
MUTA️1 小时前
ultalytics代码中模型接收多层输入的处理
深度学习·算法·yolo·机器学习·计算机视觉
Yvonne爱编码1 小时前
CSS- 1.1 css选择器
前端·css·状态模式·html5·hbuilder
山河故人1631 小时前
uniapp使用npm下载
前端·npm·uni-app