Not every ML model / onnx file is compatible with the mlfmu tool and i can be a bit hard/confusing to make an incompatible model compatible.
To make this process easier for our users we can make example classes in tensorflow and pytorch that they can use and extend to make a compatibility wrapper for their trained model.
The class could have implemented some functions and give the user an idea of what they should do to make the wrapper.
class TensorflowWrapper(tensorflow.keras.Model):
def __init__(self, trained_model):
self.trained_model = trained_model
def format_inputs(self, inputs, states, time):
return
def format_outputs(self, inputs, states, time, model_outputs):
return
def call(self, x):
inputs, states, time = x
formatted_inputs = self.format_inputs(inputs, state, time)
model_outputs = self.trained_model(formatted_inputs)
return self.format_outputs(inputs, states, time, model_outputs)
class PytorchWrapper(torch.nn.Modulel):
def __init__(self, trained_model):
self.trained_model = trained_model
def format_inputs(self, inputs, states, time):
return
def format_outputs(self, inputs, states, time, model_outputs):
return
def forward(self, x):
inputs, states, time = x
formatted_inputs = self.format_inputs(inputs, state, time)
model_outputs = self.trained_model(formatted_inputs)
return self.format_outputs(inputs, states, time, model_outputs)
In easy cases just implementing the format_inputs and format_outputs classes could be sufficient to make the compatibility wrapper for their model. For more complex cases one would maybe also need to modify more, but this could be a good starting point for our users.
If we include this we should also include tools for loading onnx files into pytorch/tensorflow and converting pytorch/tensorflow to onnx files. That way a user could go the entire way from an incompatible onnx file to an compatible onnx to a compiled fmu. All within the this tool.
Not every ML model / onnx file is compatible with the mlfmu tool and i can be a bit hard/confusing to make an incompatible model compatible.
To make this process easier for our users we can make example classes in tensorflow and pytorch that they can use and extend to make a compatibility wrapper for their trained model.
The class could have implemented some functions and give the user an idea of what they should do to make the wrapper.
In easy cases just implementing the format_inputs and format_outputs classes could be sufficient to make the compatibility wrapper for their model. For more complex cases one would maybe also need to modify more, but this could be a good starting point for our users.
If we include this we should also include tools for loading onnx files into pytorch/tensorflow and converting pytorch/tensorflow to onnx files. That way a user could go the entire way from an incompatible onnx file to an compatible onnx to a compiled fmu. All within the this tool.