CLI

In addition to the GUI and the Python package, a command line tool is available for the programmatic processing of ML description files, e.g. conversion from ONNX to XML or BML: mllib_toolbox.exe

The executable is located in <TwinCatInstallDir>\Functions\TF38xx-Machine-Learning\Utilities\ModelManagerAPI.

Use of the executable

mllib_toolbox.exe can be used, for example, from the command prompt. The built-in help is displayed by running the exe without arguments.

CLI 1:

You can move/copy the mllib_toolbox.exe to any other place you like on your PC. The exe uses the path environment variable, which points to the mllib_um.dll (default <TwinCatInstallDir>\3.1\Components\Base\Addins\TcMLExtension).

Conversion of ONNX files

ONNX files are converted using the method onnximport

mllib_toolbox.exe onnximport ".\decision tree\decisiontree-classifier.onnx" ".\decision tree\decisiontree-classifier.bml"

Alternatively, an argument can also be used (--xml or –bml).

Mllib_toolbox onnximport myOnnxFile.onnx --xml
Mllib_toolbox onnximport myOnnxFile.onnx -bml

The conversion command automatically writes the “required version” (minimum version of the ML Runtime driver) in the generated XML or BML.

Merging and extracting engines

Use the merge command to create multi-engines. The following command merges the two named XML files to form a multi-engine with 2 engines. The last-named file is overwritten in the process.

mllib_toolbox.exe merge KerasMLPExample_cos.xml KerasMLPExample_sin.xml

A new target file can also be specified. This may be both an XML and a BML file.

mllib_toolbox.exe merge KerasMLPExample_cos.xml KerasMLPExample_sin.xml MultiEngine.bml

The number of files to be combined with a command is not limited.

Use the Extract method to extract engines from a description file with multiple engines. Using the Info command, first check how many engines exist in the file – and what they are called.

CLI 2:

In the figure above you can see two engines with the designations mlp_fp32_engine::merge0 or merge1. To extract the first engine into the target file Extracted.xml, call:

mllib_toolbox.exe extract MultiEngine.xml?eng='mlp_fp32_engine::merge0' Extract.xml

Displaying information from an ML model description file

The info command can be used to quickly check what model is described in a description file. This can analyze ONNX files as well as XML and BML files.

mllib_toolbox.exe info decisiontree-classifier.xml
mllib_toolbox.exe info decisiontree-classifier.bml
mllib_toolbox.exe info decisiontree-classifier.onnx
CLI 3:

Execution of an instruction list

You can perform operations graphically in the Machine Learning Model Manager. Each operation that you perform in a session is written as an XML command on the “Automation Tool” tab.

CLI 4:

In the figure above, for example, a conversion command and a command to enter Custom Attributes can be seen. Mark the commands that you wish to export and select Create XML file. Pay attention to the order in which you select the commands in the Machine Learning Model Manager. The order of selection determines the order of the commands in the exported file.

You can use the generated XML file to reproduce the command order via

mllib_toolbox.exe rawxml AutomationToolExport.xml

Custom Attributes, Scalings and Model description

These properties are not available in the CLI. Use the Python package or the TwinCAT Machine Learning Model Manager for that. The CLI is limited to basic functions.