XML Exporter
Classification of the XML Exporters
The XML Exporters provided by Beckhoff can be freely used and changed. They are open source and under MIT license. This offers customers the option of adapting the XML Exporter according to their needs, for example by adding company-specific or project-specific CustomAttributes, cf.XML Tag CustomAttributes.
The XML exporters are provided after installation of the product in the folder
<TwinCATPath>\Functions\TF38xx-Machine-Learning\Utilities\exporter.
![]() | The XML Exporters are based on special versions of the libraries It is recommended to export created ML models via the ONNX format as well as to convert correspondingly to XML or BML. In the early phase of TwinCAT Machine Learning, the XML Exporters were intended as a transitional solution until all relevant libraries offered comprehensive ONNX support. This is the case today, so XML Exporters are no longer tested and updated with newer libraries. |
Direct XML export of an MLP
Only network architectures that have a sequential structure in the following sense are supported: each neuron of one layer is exclusively linked to each neuron of the following layer. It is possible to export layers without bias.
Export from Keras / Tensor Flow
- File: KerasMlp2Xml.py
- Sample call: sample code
- Requirements for the Python environment:
- Keras with TensorFlow backend (Tensor Flow Version 1.15.0)
- Numpy (Version 1.17.4)
- Matplotlib
- Supported activation functions: tanh, sigmoid, softmax, relu, linear/identity, exp, softplus, softsign
- Only sequential models can be exported with the XML Exporter, no functional models. The model is to be generated accordingly with:
from tensorflow.keras.models import Sequential
model = Sequential()
- Dropout layers are supported (only relevant for training, ignored when exporting)
- Dense layers are supported. The activation functions must be transferred to the layer as an argument and not as a discrete activation layer.
from keras.layers import Activation, Dense
# this will not work !!!
model.add(Dense(64))
model.add(Activation(‘tanh’))
# this will work
model.add(Dense(64,activation=’tanh’))
- The API is described in detail in the header of the file KerasMlp2Xml.py.
net2xml(net,output_scaling_bias=None,output_scaling_scal=None)
net
, obligatory, class of the trained modeloutput_scaling_bias
, optional, list (in case of several features), otherwise float or intoutput_scaling_scal
, optional, list (in case of several features), otherwise float or int- A string document is returned that can be saved as an XML.
Export from MATLAB®
- File: MatlabMlp2Xml.m
- Sample call: ExampleMatlabMLP
- Requirements for the MATLAB® environment:
- MATLAB®
- Deep Learning Toolbox
- Supported activation functions: tanh, sigmoid, softmax, relu, linear/identity
- Supported models of the Deep Learning Toolbox: fitnet, patternnet
- ProcessFcns are supported by the types mapminmax and mapstd
- The use of ProcessFcns is optional
- If a ProcessFcn is used in the output layer, its activation function must be purelin
- The API is described in detail in the header of the file MatlabMlp2Xml.m
MatlabMlp2Xml(net, fnstr, varargin)
- net, obligatory, class of the trained model
- fnstr, obligatory, string with path and file name
- output_scaling_bias, optional, vector
- output_scaling_scal, optional, vector
Direct XML export of an SVM
Export from Scikit-learn
- File: SciKitLearnSvm2Xml.py
- Sample call: ExampleScikitLearnSVM
- Requirements for the Python environment:
- Python Interpreter: 3.6 or higher
- Scikit-learn: Version 0.22.0 or higher
- Matplotlib
- Numpy
- Only numerical class labels can be exported.
- Supported classes or models: SVC, NuSVC, OneClassSVM, SVR, NuSVR
- LinearSVR and LinearSVC are not supported by the Exporter, but can alternatively be implemented via the classes SVR and SVC, each with a linear kernel.
- Supported kernel functions: linear, rbf, sigmoid, polynomial
- Neither individual kernel functions nor precomputed functions are supported
- Remarks about model parameters:
- Gamma = scale is not supported
- Gamma = auto_deprecated: it is exported gamma = 0.0
- Gamma = auto: it is exported gamma = 1/n_features.
- C = inf is not supported
- decision_function_shape = ovr is not supported. decision_function_shape = ovo must be used. Default in Scikit-learn is ovr!
- break_ties is ignored because decision_function_shape = ovr is not supported.
- The API is described in detail in the header of the file SciKitLearnSvm2Xml.py.
svm2xml(svm, input_scaling_bias=None, input_scaling_scal=None)
net
, obligatory, class of the trained modelinput_scaling_bias
, optional, list (in case of several features), otherwise float or intinput_scaling_scal
, optional, list (in case of several features), otherwise float or int- A string document is returned that can be saved as an XML.