Install using pip¶
The model store library is available via Pypi:
pip install modelstore
Create a model store instance and point it to your storage¶
The model store library supports storing models to blob storage across different cloud providers:
To start, import
from modelstore import ModelStore
And then create a model store instance by using one of the following factory methods.
File System Storage
model_store = ModelStore.from_file_system(root_directory="/path/to/directory")
Google Cloud Storage Bucket
model_store = ModelStore.from_gcloud( project_name="my-project", bucket_name="my-bucket", )
AWS s3 Bucket
model_store = ModelStore.from_aws_s3( bucket_name="my-bucket", )
Azure Blob Storage
model_store = ModelStore.from_azure(container_name="my-container-name")
Upload a model to the model store¶
Model store has an
upload() function that will create an archive containing your model and upload it to your storage.
Whenever you upload a model, you need to specify which domain it belongs to. A “domain” is a string that model store uses to group several models that are for the same end-usage together.
For example, let’s say you’ve trained a scikit-learn model (which is stored in a variable called
clf) that is going to be used in a spam classifier domain.
To store the model, use:
meta_data = model_store.upload("spam-detection", model=clf)
upload() function returns a dictionary containing meta data about your model - including the id that has been assigned to it, which is in
Load a model from the model store¶
Once a model has been stored, you can load it straight from storage back into memory using model store’s
clf = model_store.load("spam-detection", model_id="abcd-abcd-abdc")
Download a model from the model store¶
If you would rather download the model, and not load it into memory, you can use model store’s
file_path = model_store.download( local_path=".", # Where to download the model to domain="example-model", # The model's domain model_id="model-id" # Optional; the ID of the specific model )