SimCLR¶
Notation Conventions
- Parentheses
()
indicate literal parentheses. - Braces
{}
are used to bind combinations of options. - The bracket
[]
indicates an optional clause. - An ellipsis following a comma in brackets [,...] means that the preceding item can be repeated as a comma-separated list
- The vertical bar
|
represents the logicOR
. - VALUE represents a regular value.
- literal: a fixed or unchangeable value, also known as a Constant.
Each literal has a special data type such as column, in the table.
BUILD MODEL Syntax¶
Use the "BUILD MODEL" statement to develop an AI model. The "BUILD MODEL" statement allows you to train a model using datasets defined with the query_expr that comes after the "AS" clause.
query_statement:
query_expr
BUILD MODEL (model_name_expression)
USING SimCLR
OPTIONS (
expression [ , ...]
)
AS
(query_expr)
OPTIONS Clause
OPTIONS (
(image_col=VALUE),
[batch_size=VALUE],
[max_epochs=VALUE],
[pretrained={True|False}],
[overwrite={True|False}]
)
The "OPTIONS" clause allows you to change the value of a parameter. The definition of each parameter is as follows.
- "image_col": the name of the column containing the image path to be used for the training (str, default: 'image_path')
- "batch_size": the size of dataset bundle utilized in a single cycle of training (int, optional, default: 256)
- "max_epochs": number of times to train with the training dataset (int, optional, default: 5)
- "pretrained": Sets whether or not to use pre-trained ImageNet weights (bool, optional, True|False, default: False)
- "overwrite": determines whether to overwrite a model if it already exists. If set as True, the old model is replaced with the new model (bool, optional, True|False, default: False)
BUILD MODEL Example
An example "BUILD MODEL" query can be found in Search Image by Image.
%%thanosql
BUILD MODEL my_image_search_model
USING SimCLR
OPTIONS (
image_col='image_path',
max_epochs=1,
overwrite=True
)
AS
SELECT *
FROM mnist_train
CONVERT Syntax¶
Use the "CONVERT" statement to convert data into the vectors and add it to the table.
query_statement:
query_expr
CONVERT USING (model_name_expression)
OPTIONS (
expression [ , ...]
)
AS
(query_expr)
OPTIONS Clause
OPTIONS (
(image_col=column_name),
[result_col=column_name],
[batch_size=VALUE]
)
The "OPTIONS" clause allows you to change the value of a parameter. The definition of each parameter is as follows.
- "image_col": the name of the column containing the image path (str, default: 'image_path')
- "result_col": defines the column name that contains the vectorized results (str, optional, default: 'convert_result')
- "batch_size": the size of dataset bundle utilized in a single cycle of training (int, optional, default: 256)
CONVERT Example
An example "CONVERT" query can be found in Search Image by Image.
%%thanosql
CONVERT USING my_image_search_model
OPTIONS (
image_col='image_path',
result_col='convert_result'
)
AS
SELECT *
FROM mnist_test
SEARCH IMAGE Syntax¶
Use the "SEARCH IMAGE" statement to retrieve the desired image data.
query_statement:
query_expr
SEARCH IMAGE
USING (model_name_expression)
OPTIONS (
expression [ , ...]
)
AS
(query_expr)
OPTIONS Clause
OPTIONS (
(search_by={image|text|audio|video}),
(search_input=expression),
(emb_col=column_name),
[result_col=column_name],
[top_k=VALUE]
)
The "OPTIONS" clause allows you to change the value of a parameter. The definition of each parameter is as follows.
- "search_by": defines the image|text|audio|video type to be used for the search (str)
- "search_input": defines the input to be used for the search (str)
- "emb_col": the column that contains the vectorized results (str)
- "result_col": defines the name of the column that contains the search results (str, optional, default: 'search_result')
- "top_k": number of rows to return. If set as None, returns the entire data table (int, optional, default: 1000)
SEARCH IMAGE Example
An example "SEARCH IMAGE" query can be found in Search Image by Image.
%%thanosql
SEARCH IMAGE
USING my_image_search_model
OPTIONS (
search_by='image',
search_input='tutorial_data/mnist_data/test/923.jpg',
emb_col='convert_result',
result_col='search_result'
)
AS
SELECT *
FROM mnist_test