When is this applicable?
This article explains how to store and load your model as a Model Asset.
The Virtualitics AI Platform has internal support for saving trained models. Depending on your application, you may want to use a trained model in others steps within the Flow used to train the model, or other Flows developed in the future.
You are able to store and load your model by using the
StoreInterface functions within the Virtualitics AI Platform.
Here is an example of how to store and load a Model Asset:
Store model as a Model Asset
from predict_backend.ml.model import Model from predict_backend.store.store_interface import StoreInterface class SaveModel(Step): def run(self, flow_metadata): # Retrieve StoreInterface object store_interface = StoreInterface(**flow_metadata) # Store model as an asset by calling the model function. # The concepts of 'label' and 'alias' are described below per parameter. model_asset = Model(model=model, label="model_x", # label - analogous to a bucket/folder alias="trained_10202022" # alias - the version of the saved model ) # Use the "store_interface" object to save your model asset. store_interface.save_asset(model_asset)
Load Model Asset and Use the Trained Model
from predict_backend.store.store_interface import 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 label and alias names to retrieve the correct model. # Alternatively, if "alias" parameter is not used, the most recent version of the model will be retrieved. model = store_interface.get_model(label="model_x",alias="trained_10202022") # Model assets are a wrapper for their underlying object, so you can call functions, # set/get attributes directly on the Model object! results = model.predict(data)
What to Expect (Validation)
When you have saved your model as a Model Asset, your model is accessible from any Flow within the Virtualitics AI Platform.
When you load your Model Asset as a model, you may use your model per the functions associated with your model.