IMPORT_MODELS
Imports models into Vertica, either Vertica models that were exported with EXPORT_MODELS, or models in Predictive Model Markup Language (PMML) or TensorFlow format. You can use this function to move models between Vertica clusters, or to import PMML and TensorFlow models trained elsewhere.
Other Vertica model management operations such as GET_MODEL_SUMMARY and GET_MODEL_ATTRIBUTE support imported models.
Caution
Changing the exported model files causes the import functionality to fail on attempted re-import.This is a meta-function. You must call meta-functions in a top-level SELECT statement.
Behavior type
VolatileSyntax
IMPORT_MODELS ( 'source'
[ USING PARAMETERS [ new_schema = 'schema-name' ] [, category = 'model-category' ] ] )
Arguments
source
- The absolute path of the location from which to import models, one of the following:
-
The directory of a single model:
path/model-directory
-
The parent directory of multiple model directories:
parent-dir-path/*
-
Parameters
new_schema
- An existing schema where the machine learning models are imported. If omitted, models are imported to the default schema.
IMPORT_MODELS extracts the name of the imported model from its
metadata.json
file, if it exists. Otherwise, the function uses the name of the model directory. category
- Specifies the category of the model to import, one of the following:
-
VERTICA_MODELS
-
PMML
-
TENSORFLOW
This parameter is required if the model directory has no
metadata.json
file. IMPORT_MODELS returns with an error if one of the following cases is true:-
No category is specified and the model directory has no
metadata.json
. -
The specified category does not match the model type.
Note
If the category is TENSORFLOW, IMPORT_MODELS only imports the following files from the model directory:
-
model-name
.pb
-
model-name
.json
-
model-name
.pbtxt
(optional)
-
Privileges
Superuser
Requirements and restrictions
The following requirements and restrictions apply:
-
If you export a model, then import it again, the export and import model directory names must match. If naming conflicts occur, import the model to a different schema by using the
new_schema
parameter, and then rename the model. -
The machine learning configuration parameter MaxModelSizeKB sets the maximum size of a model that can be imported into Vertica.
-
Some PMML features and attributes are not currently supported. See PMML features and attributes for details.
-
If you import a PMML model with both
metadata.json
andcrc.json
files, the CRC file must contain the metadata file's CRC value. Otherwise, the import operation returns with an error.
Examples
Import models into the specified schema:
In both examples no model category is specified, so IMPORT_MODEL uses the model's metadata.json
file to determine its category:
-
Import a single model
mykmeansmodel
into thenewschema
schema:=> SELECT IMPORT_MODELS ('/home/dbadmin/myschema/mykmeansmodel' USING PARAMETERS new_schema='newschema') IMPORT_MODELS ---------------- Success (1 row)
-
Import all models in the
myschema
directory into thenewschema
schema:=> SELECT IMPORT_MODELS ('/home/dbadmin/myschema/*' USING PARAMETERS new_schema='newschema') IMPORT_MODELS ---------------- Success (1 row)
Specify the category of models to import:
In the first two examples, IMPORT_MODELS returns with success only if the specified model and category match; otherwise, it returns an error:
-
Import
kmeans_pmml
as a PMML model:SELECT IMPORT_MODELS ('/root/user/kmeans_pmml' USING PARAMETERS category='PMML') import_models --------------- Success (1 row)
-
Import
tf_mnist_estimator
as a TensorFlow model:=> SELECT IMPORT_MODELS ( '/path/tf_models/tf_mnist_estimator' USING PARAMETERS category='TENSORFLOW'); import_models --------------- Success (1 row)
-
Import all TensorFlow models from the specified directory:
=> SELECT IMPORT_MODELS ( '/path/tf_models/*' USING PARAMETERS category='TENSORFLOW'); import_models --------------- Success (1 row)