This feature is only available for the Python based frameworks.
Since SOL v0.4.2 you can cross execute SOL models. For this just use sol.optimize(..., framework='?')
. I.e. you can load an ONNX Model and run it within PyTorch using:
import sol
# Run Model with Numpy (def func(...))
import numpy as np
np_model = sol.optimize('mymodel.onnx', framework='numpy')
np_input = np.random.rand(1, 3, 224, 224).astype(np.float32)
np_output = np_model(np_input)
# Run Model with PyTorch (torch.nn.Module)
import torch
py_model = sol.optimize('mymodel.onnx', framework='pytorch')
py_model.eval()
py_input = torch.from_numpy(np_input)
with torch.no_grad():
py_output = py_model(py_input)
# Run Model with TensorFlow (tf.Module)
import tensorflow as tf
tf_model = sol.optimize('mymodel.onnx', framework='tensorflow')
tf_output = tf_model(np_input)
# Run Model with Keras (tf.keras.model.Model)
import tensorflow as tf
keras_model = sol.optimize('mymodel.onnx', framework='keras')
keras_output = keras_model.predict(np_input)
If you are using a PyTorch as source model, you need to pass example inputs as PyTorch model’s don’t know their input shapes or dtypes.
pytorch_model = ...
keras_model = sol.optimize(pytorch_model, [torch.tensor(np_input)], framework='keras')
keras_output = keras_model.predict(np_input)