How to adjust a Neural Networks metadata: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Required install: | |||
<pre>pip install onnx </pre> | |||
Add a metadata key (without duplication): | Add a metadata key (without duplication): | ||
Line 16: | Line 14: | ||
meta = onnx_model.metadata_props.add() | meta = onnx_model.metadata_props.add() | ||
meta.key = key | meta.key = key | ||
meta.value = value | meta.value = value | ||
</pre> | </pre> | ||
<pre> | |||
import onnx | |||
onnx_model = onnx.load("path/to/onnx/file") | |||
addMeta(onnxModel, "key", "value") | |||
</pre> | |||
Save the onnx model to file: | Save the onnx model to file: | ||
<pre> | <pre> | ||
with open(onnxFilePath, "wb") as f: | with open(onnxFilePath, "wb") as f: | ||
f.write(onnx_model.SerializeToString()) | f.write(onnx_model.SerializeToString()) | ||
</pre> | |||
Producer, version and description are set using these functions | |||
<pre> | |||
def setProducer(onnxModel, producer): | |||
onnxModel.producer_name = producer | |||
def setModelVersion(onnxModel, modelVersion): | |||
onnxModel.model_version = modelVersion | |||
def setDocString(onnxModel, description): | |||
onnxModel.doc_string = description | |||
</pre> | </pre> |
Revision as of 12:48, 19 December 2024
Required install:
pip install onnx
Add a metadata key (without duplication):
def addMeta(onnx_model, key, value): for entry in onnx_model.metadata_props: if entry.key == key: entry.value = value return meta = onnx_model.metadata_props.add() meta.key = key meta.value = value
import onnx onnx_model = onnx.load("path/to/onnx/file") addMeta(onnxModel, "key", "value")
Save the onnx model to file:
with open(onnxFilePath, "wb") as f: f.write(onnx_model.SerializeToString())
Producer, version and description are set using these functions
def setProducer(onnxModel, producer): onnxModel.producer_name = producer def setModelVersion(onnxModel, modelVersion): onnxModel.model_version = modelVersion def setDocString(onnxModel, description): onnxModel.doc_string = description