If you don't have a reservation, running a query using ML.PREDICT produces this error: BigQuery ML inference using imported models and object tables requires a reservation, but no reservations were assigned for job type `QUERY`...`.
You use the following query that contains the ML.PREDICT function to make predictions from image data in the input object table goldfish_image_table. This query outputs the predicted class label of the input image based on the ImageNet labels dictionary.
In the query, the ML.DECODE_IMAGE function is required to decode the image data so that it can be interpreted by ML.PREDICT. The ML.RESIZE_IMAGE function is called to resize the image to fit the size of the model's input (224*224).
bq query --use_legacy_sql=false \ 'SELECT class_label FROM ML.PREDICT(MODEL `bqml_tutorial.imported_onnx_model`, ( SELECT ML.RESIZE_IMAGE(ML.DECODE_IMAGE(DATA), 224, 224, FALSE) AS input FROM bqml_tutorial.goldfish_image_table))'
Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.
Delete the project
Console
In the Google Cloud console, go to the Manage resources page.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-04-17 UTC."],[[["ONNX enables the use of models trained in various frameworks within BigQuery ML, by providing a common machine learning model format."],["The process involves training a model in a preferred framework, converting it to ONNX format, and then importing it into BigQuery for predictions."],["You can import pretrained models, such as a PyTorch model, convert them to ONNX using torch.onnx, and subsequently import them into BigQuery via the `CREATE MODEL` statement."],["BigQuery ML's `ML.PREDICT` function allows making predictions with the imported ONNX model, while working with image data in object tables requires the use of `ML.DECODE_IMAGE` and `ML.RESIZE_IMAGE` functions."],["Using imported models and object tables in BigQuery requires a reservation and a Cloud resource connection with the necessary permissions, while clean-up involves deleting the model, dataset, connection, and Cloud Storage bucket to avoid continued billing."]]],[]]