Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make wrapper classes for making ML models compatible with tool #30

Open
KristofferSkare opened this issue Mar 15, 2024 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@KristofferSkare
Copy link
Collaborator

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.

@KristofferSkare KristofferSkare added the enhancement New feature or request label Mar 15, 2024
@ClaasRostock
Copy link
Collaborator

ClaasRostock commented Mar 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants