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)
相关推荐
慧慧吖@21 小时前
前端关于埋点
前端
universe_0121 小时前
前端学习css
前端·css·学习
稚辉君.MCA_P8_Java21 小时前
深入理解 TCP;场景复现,掌握鲜为人知的细节
java·linux·网络·tcp/ip·kubernetes
熊猫比分站21 小时前
[特殊字符] Java/Vue 实现体育比分直播系统,支持多端实时更新
java·开发语言·vue.js
lang201509281 天前
深入掌握 Maven Settings:从配置到实战
java·maven
scx_link1 天前
修改JetBrains产品(IntelliJ IDEA 、PyCharm等软件)的默认插件和日志的存储位置
java·pycharm·intellij-idea
BUG?不,是彩蛋!1 天前
Maven-Java 项目到底解决了什么痛点?
java·servlet·maven
小池先生1 天前
idea配置代码注释模板
java·ide·intellij-idea
inferno1 天前
Maven基础(一)
java·开发语言·maven
摇滚侠1 天前
Spring Boot3零基础教程,Reactive-Stream 规范核心接口,笔记103
java·spring boot·笔记