Skip to main content

A package for ONNX intermediate data dumping

Project description

onnxdumper

这是一个用于 ONNX 推理会话的 Python 包,通过额外创建一个 ONNX 推理会话加载修改了输出接口的 ONNX 模型,以便在导出 ONNX 推理中间层的输出。

安装

pip install onnxdumper

使用

import onnxruntime
import onnxdumper

# 将 onnxruntime.InferenceSession 替换为 onnxdumper.InferenceSession 即可
# session = onnxdumper.InferenceSession("path/to/your/model.onnx")
session = onnxdumper.InferenceSession("path/to/your/model.onnx")

# 准备输入数据
input_feed = {
    "input_name": input_data
}

# 运行推理并导出中间层输出
output_names = ["output_name"]
results = session.run(output_names, input_feed, dump_path="path/to/save/outputs")

导出格式

导出格式为 npz,使用 numpy 进行加载,data 的 key 为输出节点的名称,value 为输出节点的数据。

import numpy as np
data = np.load("path/to/save/outputs.npz")
for key in data.keys():
    print(key, data[key], data[key].shape, data[key].dtype)

节点输出的key查看方式

1. 使用 onnx 加载模型查看

model = onnx.load(path_or_bytes)
for node in model.graph.node:
    print(node.output)

2. 使用 netron 查看

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onnxdumper-0.7.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onnxdumper-0.7-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file onnxdumper-0.7.tar.gz.

File metadata

  • Download URL: onnxdumper-0.7.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for onnxdumper-0.7.tar.gz
Algorithm Hash digest
SHA256 7bd8511ec374e713a295b5eaa36e92fc3705e20d43b5540836e5ed273b4dbc91
MD5 7176abb869d0a5aeec618df922f0902e
BLAKE2b-256 e2058493fb9a84cff6621c95dab3eaeb159a39c8fe7134df3a214d1d0e63508d

See more details on using hashes here.

File details

Details for the file onnxdumper-0.7-py3-none-any.whl.

File metadata

  • Download URL: onnxdumper-0.7-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for onnxdumper-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 953ed271ebda09426703a09773bfbf5079209b34e4c92c8fa5d57ef39eafdc36
MD5 12f4cee4e5d765fdbfa993b5a731783c
BLAKE2b-256 d0af1ba868b60cdaccc19d85e61956dea9c1e54d0954304d9e04fac1c4ee7ffb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page