Python interface

Installation of the Python package

The Python package is stored as a whl file in the folder <TwinCatInstallDir>\Functions\TF38xx-Machine-Learning\Utilities\ModelManagerAPI\PythonPackage.

To install the package, use pip install <TwinCatInstallDir>\Functions\TF38xx-Machine-Learning\Utilities\ModelManagerAPI\PythonPackage\<whl-file-name>. The folder may contain different versions of the package (only if you have installed a new setup on top of an old TwinCAT Machine Learning Setup).

Make sure you always use the current version.

Using the API

The package is loaded with

import  beckhoff.toolbox as  tb

Creating a JSON and PlcOpenXml from an ONNX file

tb.onnxprep("C:\\PathTo\\myONNX.onnx")

Display of model information

tb.info("C:\\PathTo\\myONNX.json")

Add Custom Attributes

new_ca = { 'nID' : -34234, 'bTested' : True, 'fNum' : 324.3E-12, 'AnotherTreeItem' : { 'fPi' : 3.13412, 'bFalseFlag' : False }}
tb.modify_ca("C:\\PathTo\\myONNX.json","C:\\PathTo\\myONNX_ca.json", new_ca)

Add Model Description (name, version, author, etc. of a model)

model_description = { 
    "new_version" : "2.3.1.0",
    "new_name" : "CurrentPreControlAxis42",
    "new_desc":"This is the most awesome model to control Axis42",
    "new_author":"Max",
    "new_tags":"awesome, ingenious, astounding",
}
tb.modify_md("C:\\PathTo\\myONNX.json", "C:\\PathTo\\myONNX_md.json",
             **model_description)