The Virtualitics AI Platform (VAIP) provides built-in support for saving trained models. Depending on your use case, you may want to leverage a saved model in subsequent Steps of the App that trained it or integrate it into other Apps that are developed in the future.
You are able to store and load your model by using the Model and StoreInterface classes within the Virtualitics SDK.
Storing a Model Asset
The code below is an example of how to store a Model Asset:
from virtualitics_sdk import Model, StoreInterface, ...
class SaveModel(Step):
def run(self, flow_metadata):
# Retrieve StoreInterface object
store_interface = StoreInterface(**flow_metadata)
# Create a new model asset
model_asset = Model(model=model,
label="xyz", # analogous to a bucket/folder,
name="my_model"
)
# Save your model asset to the platform persistence system (aka store)
store_interface.save_asset(model_asset)
Loading a Model Asset and Using the Trained Model
The code below is an example of how to load a Model Asset and use the trained Model:
from virtualitics_sdk import Model, StoreInterface, ...
class ModelPredict(Step):
def run(self, flow_metadata):
store_interface = StoreInterface(**flow_metadata)
# Use StoreInterface "get_model" attribute to retrieve model.
# Must use identical name to retrieve the correct model.
# Models can have the same label but must have unique names.
model = store_interface.get_model(label="xyz", name="my_model")
# Model assets are a wrapper for their underlying object, so you can call functions and set/get attributes directly on the Model object!
results = model.predict(data)
What to Expect
When you have saved your model as a Model Asset, your model is accessible from any App within the VAIP. When you load your Model Asset as a model, you may use your model per the functions associated with your model.