The CREATE MODEL statement for importing TensorFlow Lite models
CREATE MODEL
statement for TensorFlow Lite
To import an existing TensorFlow Lite model into BigQuery from
Cloud Storage, use the
BigQuery ML CREATE MODEL
statement with the TensorFlow Lite model type.
For information about supported model types of each SQL statement and function, and all supported SQL statements and functions for each model type, read End-to-end user journey for each model.
CREATE MODEL
syntax
{CREATE MODEL | CREATE MODEL IF NOT EXISTS | CREATE OR REPLACE MODEL} model_name [OPTIONS(MODEL_TYPE = 'TENSORFLOW_LITE', MODEL_PATH = string_value)];
CREATE MODEL
Creates a new BigQuery model in the specified dataset. For TensorFlow Lite
models, BigQuery imports the existing TensorFlow Lite model and
converts it to a BigQuery model. If the model name exists,
CREATE MODEL
returns an error.
CREATE MODEL IF NOT EXISTS
Creates a new imported model only if the model does not currently exist in the specified dataset.
CREATE OR REPLACE MODEL
Creates a new imported model and replaces any existing model with the same name in the specified dataset.
model_name
model_name
is the name of the BigQuery model you're creating or
replacing. The model name must be unique per dataset: no other model or table
can have the same name. The model name must follow the same naming rules as a
BigQuery table. A model name can contain the following:
- Up to 1,024 characters
- Letters of either case, numbers, and underscores
model_name
is not case-sensitive.
If you do not have a default project configured, prepend the project ID to the model name in following format, including backticks:
`[PROJECT_ID].[DATASET].[MODEL]`
For example:
`myproject.mydataset.mymodel`
CREATE MODEL
supports the following options:
MODEL_TYPE
Syntax
MODEL_TYPE = 'TENSORFLOW_LITE'
Description
Specifies the model type. This option is required.
MODEL_PATH
Syntax
MODEL_PATH = string_value
Description
Specifies the Cloud Storage URI of the TensorFlow Lite model to import. This option is required for TensorFlow Lite models.
string_value
is the URI of a Cloud Storage bucket that contains
the model to import.
BigQuery imports the model from Cloud Storage using the credentials
of the user who sent the CREATE MODEL
statement.
Example
MODEL_PATH = 'gs://bucket/path/to/tflite_model/*'
Supported inputs
The CREATE MODEL
statement supports the following data types for input label
and data split columns.
Supported data types for TensorFlow Lite model inputs and outputs
BigQuery converts certain TensorFlow Lite model inputs and outputs to BigQuery types. Some TensorFlow Lite model input and output types are not supported. Supported data types for the inputs and outputs of the imported TensorFlow Lite model include:
TensorFlow Lite types | Supported | BigQuery type |
---|---|---|
UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64 |
Supported | INT64 |
FLOAT16, FLOAT32, FLOAT64 |
Supported | FLOAT64 |
COMPLEX64, COMPLEX128 |
Unsupported | N/a |
BOOL |
Supported | BOOL |
STRING |
Supported | STRING |
RESOURCE |
Unsupported | N/a |
VARIANT |
Unsupported | N/a |
Limitations
CREATE MODEL
statements for TensorFlow Lite models must comply with the following
rules:
- The TensorFlow Lite model must exist before it can be imported into BigQuery.
- Models must be stored in Cloud Storage.
- TensorFlow Lite models must be in
.tflite
format. - Only
ML.PREDICT
is supported for TensorFlow Lite models. - Models are limited to 450 MB in size.
- Only Tensorflow core operations and TensorFlow Text operations are supported in BigQuery.
- SentencePiece operators are not supported.
- Sparse tensors are not supported.
CREATE MODEL
examples
The following example creates models named mymodel
in mydataset
in your
default project.
Importing a TensorFlow Lite model
The following example imports a TensorFlow Lite model into BigQuery
as a BigQuery model. The example assumes that there is an existing
TensorFlow Lite model located at gs://bucket/path/to/tflite_model/*
.
CREATE MODEL project_id.mydataset.mymodel
OPTIONS(MODEL_TYPE='TENSORFLOW_LITE',
MODEL_PATH="gs://bucket/path/to/tflite_model/*")