How to adjust a Neural Networks metadata: Difference between revisions

From Tygron Preview Support Wiki
Jump to navigation Jump to search
(Created page with " <pre> import onnx </pre> Save the onnx model to file: <pre> with open(onnxFilePath, "wb") as f: f.write(onnx_model.SerializeToString()) </pre>")
 
No edit summary
Line 2: Line 2:
<pre>
<pre>
import onnx
import onnx
onnx_model = onnx.load(onnxModelName)
</pre>


Add a metadata key (without duplication):
<pre>
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 
</pre>
</pre>



Revision as of 12:39, 19 December 2024

import onnx
onnx_model = onnx.load(onnxModelName)

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  

Save the onnx model to file:

with open(onnxFilePath, "wb") as f:
    f.write(onnx_model.SerializeToString())